Skip to content

Commit b92debe

Browse files
committed
fix: adapt the new openApi structure
1 parent 0c1fa8f commit b92debe

File tree

6 files changed

+937
-821
lines changed

6 files changed

+937
-821
lines changed

crates/rmcp/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ paste = { version = "1", optional = true }
2828
oauth2 = { version = "5.0", optional = true }
2929

3030
# for auto generate schema
31-
schemars = { version = "0.9", optional = true }
31+
schemars = { version = "1.0", optional = true }
3232

3333
# for image encoding
3434
base64 = { version = "0.22", optional = true }
@@ -133,7 +133,7 @@ schemars = ["dep:schemars"]
133133

134134
[dev-dependencies]
135135
tokio = { version = "1", features = ["full"] }
136-
schemars = { version = "0.9", features = ["chrono04"] }
136+
schemars = { version = "1.0", features = ["chrono04"] }
137137

138138
anyhow = "1.0"
139139
tracing-subscriber = { version = "0.3", features = [

crates/rmcp/src/handler/server/tool.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ use crate::{
1313
model::{CallToolRequestParam, CallToolResult, IntoContents, JsonObject},
1414
service::RequestContext,
1515
};
16-
16+
use crate::schemars::generate::SchemaSettings;
1717
/// A shortcut for generating a JSON schema for a type.
1818
pub fn schema_for_type<T: JsonSchema>() -> JsonObject {
1919
// explicitly to align json schema version to official specifications.
2020
// https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-03-26/schema.json
21-
let mut settings = schemars::r#gen::SchemaSettings::draft07();
22-
settings.option_nullable = true;
23-
settings.option_add_null_type = false;
24-
settings.visitors = Vec::default();
21+
// TODO: update to 2020-12 waiting for the mcp spec update
22+
let settings = SchemaSettings::draft07();
2523
let generator = settings.into_generator();
2624
let schema = generator.into_root_schema_for::<T>();
2725
let object = serde_json::to_value(schema).expect("failed to serialize schema");

crates/rmcp/tests/test_complex_schema.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ fn test_complex_schema() {
4747
let attr = Demo::chat_tool_attr();
4848
let input_schema = attr.input_schema;
4949
let enum_number = input_schema
50-
.get("definitions")
50+
.get("components")
51+
.unwrap()
52+
.as_object()
53+
.unwrap()
54+
.get("schemas")
5155
.unwrap()
5256
.as_object()
5357
.unwrap()

crates/rmcp/tests/test_message_schema.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod tests {
22
use rmcp::model::{ClientJsonRpcMessage, ServerJsonRpcMessage};
3-
use schemars::schema_for;
3+
use schemars::{generate::SchemaSettings, schema_for};
44

55
fn compare_schemas(name: &str, actual: &str, expected_file: &str) {
66
let expected = match std::fs::read_to_string(expected_file) {
@@ -48,7 +48,8 @@ mod tests {
4848

4949
#[test]
5050
fn test_client_json_rpc_message_schema() {
51-
let schema = schema_for!(ClientJsonRpcMessage);
51+
let settings = SchemaSettings::draft07();
52+
let schema = settings.into_generator().into_root_schema_for::<ClientJsonRpcMessage>();
5253
let schema_str = serde_json::to_string_pretty(&schema).expect("Failed to serialize schema");
5354

5455
compare_schemas(
@@ -60,7 +61,8 @@ mod tests {
6061

6162
#[test]
6263
fn test_server_json_rpc_message_schema() {
63-
let schema = schema_for!(ServerJsonRpcMessage);
64+
let settings = SchemaSettings::draft07();
65+
let schema = settings.into_generator().into_root_schema_for::<ServerJsonRpcMessage>();
6466
let schema_str = serde_json::to_string_pretty(&schema).expect("Failed to serialize schema");
6567

6668
compare_schemas(

0 commit comments

Comments
 (0)