Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions crates/graphicle/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,16 +2001,26 @@ fn mcp_in(
}
})
}
_ => Err(Error::bad("Unsupported MCP method")),
_ => Err(Error::bad(UNSUPPORTED_METHOD)),
}
})();
Some(match result {
Ok(value) => json!({"jsonrpc":"2.0","id":request["id"],"result":value}),
Err(error) => {
json!({"jsonrpc":"2.0","id":request["id"],"error":{"code":-32602,"message":error.message}})
// JSON-RPC's "Method not found" for a method this connection
// does not serve, so that a client can tell it from a refused
// call.
let code = if error.message == UNSUPPORTED_METHOD {
-32601
} else {
-32602
};
json!({"jsonrpc":"2.0","id":request["id"],"error":{"code":code,"message":error.message}})
}
})
}
/// The error message of a method a connection does not serve.
const UNSUPPORTED_METHOD: &str = "Unsupported MCP method";
async fn mcp_http(
State(app): State<App>,
Path((workspace, repository)): Path<(String, String)>,
Expand Down
5 changes: 5 additions & 0 deletions crates/graphicle/tests/it/workspace_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,11 @@ fn a_workspace_connection_serves_the_graph_tools_of_the_project_repo_names() {
"Unsupported MCP method",
"{refused}"
);
// JSON-RPC's "Method not found", not "Invalid params".
assert_eq!(refused["error"]["code"], -32601, "{refused}");
// A refused call of a served method keeps "Invalid params".
let unknown_tool = rpc(&app, "tools/call", json!({"name":"no_such_tool"}));
assert_eq!(unknown_tool["error"]["code"], -32602, "{unknown_tool}");
// A navigation tool names its project, by id or key.
let unnamed = call(&app, "get_node", json!({"label":"quantize_cents"}));
assert!(
Expand Down