From e17a3f24468e9f98df8ea19d2c94cb35f98b3d88 Mon Sep 17 00:00:00 2001 From: Salman Mohammed Date: Fri, 20 Dec 2024 14:45:30 -0500 Subject: [PATCH] add instructions to InitializeRequest & Router trait --- crates/mcp-core/src/protocol.rs | 2 ++ crates/mcp-server/src/main.rs | 4 ++++ crates/mcp-server/src/router.rs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/crates/mcp-core/src/protocol.rs b/crates/mcp-core/src/protocol.rs index a98d8d79..91d76888 100644 --- a/crates/mcp-core/src/protocol.rs +++ b/crates/mcp-core/src/protocol.rs @@ -147,6 +147,8 @@ pub struct InitializeResult { pub protocol_version: String, pub capabilities: ServerCapabilities, pub server_info: Implementation, + #[serde(skip_serializing_if = "Option::is_none")] + pub instructions: Option, } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] diff --git a/crates/mcp-server/src/main.rs b/crates/mcp-server/src/main.rs index b8911b36..5ea232bb 100644 --- a/crates/mcp-server/src/main.rs +++ b/crates/mcp-server/src/main.rs @@ -44,6 +44,10 @@ impl CounterRouter { } impl Router for CounterRouter { + fn instructions(&self) -> String { + "This server provides a counter tool that can increment and decrement values. The counter starts at 0 and can be modified using the 'increment' and 'decrement' tools. Use 'get_value' to check the current count.".to_string() + } + fn capabilities(&self) -> ServerCapabilities { CapabilitiesBuilder::new().with_tools(true).build() } diff --git a/crates/mcp-server/src/router.rs b/crates/mcp-server/src/router.rs index d2d8a9dd..07deca32 100644 --- a/crates/mcp-server/src/router.rs +++ b/crates/mcp-server/src/router.rs @@ -78,6 +78,8 @@ impl CapabilitiesBuilder { } pub trait Router: Send + Sync + 'static { + // in the protocol, instructions are optional but we make it required + fn instructions(&self) -> String; fn capabilities(&self) -> ServerCapabilities; fn list_tools(&self) -> Vec; fn call_tool( @@ -113,6 +115,7 @@ pub trait Router: Send + Sync + 'static { name: "mcp-server".to_string(), version: env!("CARGO_PKG_VERSION").to_string(), }, + instructions: Some(self.instructions()), }; let mut response = self.create_response(req.id);