Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Mar 4, 2025
1 parent aedb9ca commit c85f931
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions crates/torii/server/src/handlers/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ impl McpHandler {
},
Tool {
name: "schema",
description: "Retrieve the database schema including tables, columns, and their types",
description: "Retrieve the database schema including tables, columns, and their \
types",
input_schema: json!({
"type": "object",
"properties": {
Expand Down Expand Up @@ -189,18 +190,19 @@ impl McpHandler {
}

fn handle_tools_list(&self, id: Value) -> JsonRpcResponse {
let tools_json: Vec<Value> = self.tools.iter().map(|tool| {
json!({
"name": tool.name,
"description": tool.description,
"inputSchema": tool.input_schema
let tools_json: Vec<Value> = self
.tools
.iter()
.map(|tool| {
json!({
"name": tool.name,
"description": tool.description,
"inputSchema": tool.input_schema
})
})
}).collect();
.collect();

JsonRpcResponse::ok(
id,
json!({ "tools": tools_json }),
)
JsonRpcResponse::ok(id, json!({ "tools": tools_json }))
}

async fn handle_tools_call(&self, request: JsonRpcRequest) -> JsonRpcResponse {
Expand Down Expand Up @@ -334,7 +336,7 @@ impl McpHandler {
))
.unwrap(),
))
.unwrap()
.unwrap();
}
}
};
Expand Down Expand Up @@ -392,7 +394,8 @@ impl McpHandler {
}
Err(_) => {
// If not a valid JsonRpcMessage, try to interpret as a raw request
// This is more permissive and handles cases where the client sends simplified JSON
// This is more permissive and handles cases where the client sends
// simplified JSON
if let Some(method) = json_value.get("method").and_then(|m| m.as_str()) {
let id = json_value.get("id").cloned().unwrap_or(Value::Null);
let params = json_value.get("params").cloned();
Expand Down Expand Up @@ -594,14 +597,10 @@ impl McpHandler {

// New method to handle resources/list
fn handle_resources_list(&self, id: Value) -> JsonRpcResponse {
let resources_json: Vec<Value> = self.resources.iter().map(|resource| {
json!({ "name": resource.name })
}).collect();
let resources_json: Vec<Value> =
self.resources.iter().map(|resource| json!({ "name": resource.name })).collect();

JsonRpcResponse::ok(
id,
json!({ "resources": resources_json }),
)
JsonRpcResponse::ok(id, json!({ "resources": resources_json }))
}

// New method to handle resources/read
Expand Down

0 comments on commit c85f931

Please sign in to comment.