From 09474d47694225dc7cf828776d934fbd02414cba Mon Sep 17 00:00:00 2001 From: 4t145 Date: Wed, 7 May 2025 15:22:24 +0800 Subject: [PATCH] fix(test): skip serialize tool's annotation if empty (#160) * fix(test): skip serialize tool's annotation if empty 1. skip serialize tool's annotation if empty 2. close js server and client when close * fix(test): fix test with js, don't close too early --- crates/rmcp/src/model/tool.rs | 1 + crates/rmcp/tests/test_with_js/client.js | 3 ++- crates/rmcp/tests/test_with_js/server.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/rmcp/src/model/tool.rs b/crates/rmcp/src/model/tool.rs index 3d973eb..ca5100d 100644 --- a/crates/rmcp/src/model/tool.rs +++ b/crates/rmcp/src/model/tool.rs @@ -18,6 +18,7 @@ pub struct Tool { pub description: Option>, /// A JSON Schema object defining the expected parameters for the tool pub input_schema: Arc, + #[serde(skip_serializing_if = "Option::is_none")] /// Optional additional tool information. pub annotations: Option, } diff --git a/crates/rmcp/tests/test_with_js/client.js b/crates/rmcp/tests/test_with_js/client.js index 54b7cad..17b189a 100644 --- a/crates/rmcp/tests/test_with_js/client.js +++ b/crates/rmcp/tests/test_with_js/client.js @@ -1,7 +1,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"; -const transport = new SSEClientTransport( new URL(`http://127.0.0.1:8000/sse`)); +const transport = new SSEClientTransport(new URL(`http://127.0.0.1:8000/sse`)); const client = new Client( { @@ -26,3 +26,4 @@ console.log(templates); const prompts = await client.listPrompts(); console.log(prompts); await client.close(); +await transport.close(); \ No newline at end of file diff --git a/crates/rmcp/tests/test_with_js/server.js b/crates/rmcp/tests/test_with_js/server.js index c128340..d959224 100644 --- a/crates/rmcp/tests/test_with_js/server.js +++ b/crates/rmcp/tests/test_with_js/server.js @@ -32,4 +32,4 @@ server.tool( ); const transport = new StdioServerTransport(); -await server.connect(transport); +await server.connect(transport); \ No newline at end of file