File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
crates/apollo-mcp-server/src Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ use rmcp::schemars::JsonSchema;
1111use rmcp:: serde_json:: Value ;
1212use rmcp:: { schemars, serde_json} ;
1313use serde:: Deserialize ;
14- use std:: default:: Default ;
1514use std:: sync:: Arc ;
1615use tokio:: sync:: Mutex ;
1716
Original file line number Diff line number Diff line change 22#[ macro_export]
33macro_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+ }
You can’t perform that action at this time.
0 commit comments