G: G2 MCP description document POST /mcp and x-mcp-tools from the tool router
This commit is contained in:
1 parent
3d8e840427
commit
7078ed15b1
3 files changed
+142
-2
No files matched your search
+66
-2
@@ -14,6 +14,7 @@ use axum::http::{Request, StatusCode};
|
||||
use axum::Router;
|
||||
use serde_json::Value;
|
||||
use skyg_linux_tracker::config::Config;
|
||||
use skyg_linux_tracker::mcp::TrackerService;
|
||||
use skyg_linux_tracker::openapi::{self, document};
|
||||
use skyg_linux_tracker::peers::testing::{fake_state_with_peers, static_registry};
|
||||
use skyg_linux_tracker::peers::types::{ApiStatus, AuthState, PeerName, PeerStatus, ServerStatus};
|
||||
@@ -85,10 +86,16 @@ fn api_route_literals() -> Vec<String> {
|
||||
out
|
||||
}
|
||||
|
||||
/// Route literals declared outside the API router (`server.rs`: `/healthz`).
|
||||
/// Route literals declared outside the API router: `/healthz` and the `/mcp`
|
||||
/// mount in `server.rs`.
|
||||
fn server_route_literals() -> Vec<String> {
|
||||
let source = fs::read_to_string(Path::new(MANIFEST).join("src/server.rs")).unwrap();
|
||||
route_literals(&source)
|
||||
let mut out = route_literals(&source);
|
||||
let mount = ".nest_service(\"/mcp\"";
|
||||
assert!(source.contains(mount), "server.rs no longer mounts /mcp");
|
||||
out.push("/mcp".to_owned());
|
||||
out.sort();
|
||||
out
|
||||
}
|
||||
|
||||
/// The path argument of every `.route("...")` call. Splitting on the marker
|
||||
@@ -136,6 +143,63 @@ async fn every_documented_path_is_routed() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The tools in `x-mcp-tools` are the ones `tools/list` serves in that mode.
|
||||
#[test]
|
||||
fn mcp_tools_match_the_tool_router() {
|
||||
for peers in [false, true] {
|
||||
let spec = serde_json::to_value(document(peers)).unwrap();
|
||||
let documented = spec["x-mcp-tools"]["tools"].as_array().unwrap();
|
||||
let advertised = TrackerService::advertised_tools(peers);
|
||||
assert_eq!(
|
||||
documented.len(),
|
||||
advertised.len(),
|
||||
"x-mcp-tools has a different number of tools (peers = {peers})"
|
||||
);
|
||||
for (entry, tool) in documented.iter().zip(&advertised) {
|
||||
assert_eq!(
|
||||
entry["name"],
|
||||
tool.name.as_ref(),
|
||||
"tool order or names differ"
|
||||
);
|
||||
assert_eq!(
|
||||
entry["description"],
|
||||
tool.description.as_deref().unwrap_or_default(),
|
||||
"{} has a different description",
|
||||
tool.name
|
||||
);
|
||||
assert_eq!(
|
||||
entry["inputSchema"],
|
||||
Value::Object((*tool.input_schema).clone()),
|
||||
"{} has a different input schema",
|
||||
tool.name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The tool count is part of the contract: 8 without peers, 10 with them.
|
||||
#[test]
|
||||
fn mcp_tool_count_follows_the_peers_flag() {
|
||||
let names = |peers: bool| -> Vec<String> {
|
||||
let spec = serde_json::to_value(document(peers)).unwrap();
|
||||
spec["x-mcp-tools"]["tools"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|tool| tool["name"].as_str().unwrap().to_owned())
|
||||
.collect()
|
||||
};
|
||||
let off = names(false);
|
||||
assert_eq!(off.len(), 8);
|
||||
assert!(!off
|
||||
.iter()
|
||||
.any(|name| name == "list_peers" || name == "get_peer"));
|
||||
let on = names(true);
|
||||
assert_eq!(on.len(), 10);
|
||||
assert!(on.iter().any(|name| name == "list_peers"));
|
||||
assert!(on.iter().any(|name| name == "get_peer"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_spec_is_valid_json_with_the_expected_shape() {
|
||||
let doc = document(true);
|
||||
|
||||
Reference in new issue
Block a user