Skip to content

Commit

Permalink
add instructions to InitializeRequest & Router trait
Browse files Browse the repository at this point in the history
  • Loading branch information
salman1993 committed Dec 20, 2024
1 parent 64969ba commit e17a3f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/mcp-core/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
Expand Down
4 changes: 4 additions & 0 deletions crates/mcp-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
3 changes: 3 additions & 0 deletions crates/mcp-server/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<mcp_core::tool::Tool>;
fn call_tool(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e17a3f2

Please sign in to comment.