Skip to content

Commit 85ce67d

Browse files
committed
fix: use JSON Schema Draft-07 for MCP tool schemas to support VSCode/Copilot
1 parent 4b90ce4 commit 85ce67d

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

crates/apollo-mcp-server/src/introspection/tools/validate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rmcp::schemars::JsonSchema;
1111
use rmcp::serde_json::Value;
1212
use rmcp::{schemars, serde_json};
1313
use serde::Deserialize;
14-
use std::default::Default;
1514
use std::sync::Arc;
1615
use tokio::sync::Mutex;
1716

crates/apollo-mcp-server/src/json_schema.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,47 @@
22
#[macro_export]
33
macro_rules! schema_from_type {
44
($type:ty) => {{
5-
match serde_json::to_value(schemars::schema_for!($type)) {
5+
// Use Draft-07 for compatibility with MCP clients like VSCode/Copilot that don't support newer drafts.
6+
// See: https://github.com/microsoft/vscode/issues/251315
7+
let settings = schemars::generate::SchemaSettings::draft07();
8+
let generator = settings.into_generator();
9+
let schema = generator.into_root_schema_for::<$type>();
10+
match serde_json::to_value(schema) {
611
Ok(Value::Object(schema)) => schema,
712
_ => panic!("Failed to generate schema for {}", stringify!($type)),
813
}
914
}};
1015
}
16+
17+
#[cfg(test)]
18+
mod tests {
19+
use schemars::JsonSchema;
20+
use serde::Deserialize;
21+
use serde_json::Value;
22+
23+
#[derive(JsonSchema, Deserialize)]
24+
struct TestInput {
25+
#[allow(dead_code)]
26+
field: String,
27+
}
28+
29+
#[test]
30+
fn test_schema_from_type() {
31+
let schema = schema_from_type!(TestInput);
32+
33+
assert_eq!(
34+
serde_json::to_value(&schema).unwrap(),
35+
serde_json::json!({
36+
"$schema": "http://json-schema.org/draft-07/schema#",
37+
"title": "TestInput",
38+
"type": "object",
39+
"properties": {
40+
"field": {
41+
"type": "string"
42+
}
43+
},
44+
"required": ["field"]
45+
})
46+
);
47+
}
48+
}

0 commit comments

Comments
 (0)