Skip to content

Commit

Permalink
fix mcp args
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Mar 4, 2025
1 parent d85f68f commit 149d749
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions crates/torii/server/src/handlers/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,47 +539,39 @@ impl McpHandler {
}

async fn handle_query_tool(&self, request: JsonRpcRequest) -> JsonRpcResponse {
if let Some(params) = request.params {
if let Some(query) = params.get("query").and_then(Value::as_str) {
match sqlx::query(query).fetch_all(&*self.pool).await {
Ok(rows) => {
// Convert rows to JSON using shared mapping function
let result = rows.iter().map(map_row_to_json).collect::<Vec<_>>();

JsonRpcResponse {
jsonrpc: JSONRPC_VERSION.to_string(),
id: request.id,
result: Some(json!({
"content": [{
"type": "text",
"text": serde_json::to_string(&result).unwrap()
}]
})),
error: None,
}
}
Err(e) => JsonRpcResponse {
let Some(params) = request.params else {
return JsonRpcResponse::invalid_params(request.id, "Missing params");

Check warning on line 543 in crates/torii/server/src/handlers/mcp.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/mcp.rs#L542-L543

Added lines #L542 - L543 were not covered by tests
};

let args = params.get("arguments").and_then(Value::as_object);
if let Some(query) = args.and_then(|args| args.get("query").and_then(Value::as_str)) {
match sqlx::query(query).fetch_all(&*self.pool).await {
Ok(rows) => {
// Convert rows to JSON using shared mapping function
let result = rows.iter().map(map_row_to_json).collect::<Vec<_>>();

JsonRpcResponse {

Check warning on line 553 in crates/torii/server/src/handlers/mcp.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/mcp.rs#L546-L553

Added lines #L546 - L553 were not covered by tests
jsonrpc: JSONRPC_VERSION.to_string(),
id: request.id,
result: None,
error: Some(JsonRpcError {
code: -32603,
message: "Database error".to_string(),
data: Some(json!({ "details": e.to_string() })),
}),
},
result: Some(json!({
"content": [{
"type": "text",
"text": serde_json::to_string(&result).unwrap()
}]
})),
error: None,
}

Check warning on line 563 in crates/torii/server/src/handlers/mcp.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/mcp.rs#L556-L563

Added lines #L556 - L563 were not covered by tests
}
} else {
JsonRpcResponse {
Err(e) => JsonRpcResponse {

Check warning on line 565 in crates/torii/server/src/handlers/mcp.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/mcp.rs#L565

Added line #L565 was not covered by tests
jsonrpc: JSONRPC_VERSION.to_string(),
id: request.id,
result: None,
error: Some(JsonRpcError {
code: -32602,
message: "Invalid params".to_string(),
data: Some(json!({ "details": "Missing query parameter" })),
code: -32603,
message: "Database error".to_string(),
data: Some(json!({ "details": e.to_string() })),

Check warning on line 572 in crates/torii/server/src/handlers/mcp.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/mcp.rs#L570-L572

Added lines #L570 - L572 were not covered by tests
}),
}
},

Check warning on line 574 in crates/torii/server/src/handlers/mcp.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/mcp.rs#L574

Added line #L574 was not covered by tests
}
} else {
JsonRpcResponse {
Expand All @@ -589,7 +581,7 @@ impl McpHandler {
error: Some(JsonRpcError {
code: -32602,
message: "Invalid params".to_string(),
data: None,
data: Some(json!({ "details": "Missing query parameter" })),

Check warning on line 584 in crates/torii/server/src/handlers/mcp.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/server/src/handlers/mcp.rs#L584

Added line #L584 was not covered by tests
}),
}
}
Expand Down

0 comments on commit 149d749

Please sign in to comment.