From bcd991c32262e6061d8aaa0989f28958c5c0c764 Mon Sep 17 00:00:00 2001 From: Salman Mohammed Date: Sun, 12 Jan 2025 19:42:52 -0500 Subject: [PATCH] Add resource capabilties to MCP servers that use it (#576) --- crates/goose-mcp/README.md | 5 ++-- crates/goose-mcp/examples/mcp.rs | 36 ++++++++++++++++++++++++ crates/goose-mcp/src/developer/mod.rs | 5 +++- crates/goose-mcp/src/developer2/mod.rs | 5 +++- crates/goose-mcp/src/nondeveloper/mod.rs | 5 +++- crates/mcp-server/src/main.rs | 5 +++- 6 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 crates/goose-mcp/examples/mcp.rs diff --git a/crates/goose-mcp/README.md b/crates/goose-mcp/README.md index d605054d..822c1742 100644 --- a/crates/goose-mcp/README.md +++ b/crates/goose-mcp/README.md @@ -1,8 +1,9 @@ ### Test with MCP Inspector +Update examples/mcp.rs to use the appropriate the MCP server (eg. DeveloperRouter) + ```bash -npx @modelcontextprotocol/inspector cargo run -p developer -npx @modelcontextprotocol/inspector cargo run -p jetbrains +npx @modelcontextprotocol/inspector cargo run -p goose-mcp --example mcp ``` Then visit the Inspector in the browser window and test the different endpoints. diff --git a/crates/goose-mcp/examples/mcp.rs b/crates/goose-mcp/examples/mcp.rs new file mode 100644 index 00000000..15e401a0 --- /dev/null +++ b/crates/goose-mcp/examples/mcp.rs @@ -0,0 +1,36 @@ +// An example script to run an MCP server +use anyhow::Result; +use goose_mcp::DeveloperRouter; +use mcp_server::router::RouterService; +use mcp_server::{ByteTransport, Server}; +use tokio::io::{stdin, stdout}; +use tracing_appender::rolling::{RollingFileAppender, Rotation}; +use tracing_subscriber::{self, EnvFilter}; + +#[tokio::main] +async fn main() -> Result<()> { + // Set up file appender for logging + let file_appender = RollingFileAppender::new(Rotation::DAILY, "logs", "mcp-server.log"); + + // Initialize the tracing subscriber with file and stdout logging + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into())) + .with_writer(file_appender) + .with_target(false) + .with_thread_ids(true) + .with_file(true) + .with_line_number(true) + .init(); + + tracing::info!("Starting MCP server"); + + // Create an instance of our counter router + let router = RouterService(DeveloperRouter::new()); + + // Create and run the server + let server = Server::new(router); + let transport = ByteTransport::new(stdin(), stdout()); + + tracing::info!("Server initialized and ready to handle requests"); + Ok(server.run(transport).await?) +} diff --git a/crates/goose-mcp/src/developer/mod.rs b/crates/goose-mcp/src/developer/mod.rs index c50fc32d..774686f1 100644 --- a/crates/goose-mcp/src/developer/mod.rs +++ b/crates/goose-mcp/src/developer/mod.rs @@ -777,7 +777,10 @@ impl Router for DeveloperRouter { } fn capabilities(&self) -> ServerCapabilities { - CapabilitiesBuilder::new().with_tools(true).build() + CapabilitiesBuilder::new() + .with_tools(false) + .with_resources(false, false) + .build() } fn list_tools(&self) -> Vec { diff --git a/crates/goose-mcp/src/developer2/mod.rs b/crates/goose-mcp/src/developer2/mod.rs index 730b3e54..2586460d 100644 --- a/crates/goose-mcp/src/developer2/mod.rs +++ b/crates/goose-mcp/src/developer2/mod.rs @@ -484,7 +484,10 @@ impl Router for Developer2Router { } fn capabilities(&self) -> ServerCapabilities { - CapabilitiesBuilder::new().with_tools(true).build() + CapabilitiesBuilder::new() + .with_tools(false) + .with_resources(false, false) + .build() } fn list_tools(&self) -> Vec { diff --git a/crates/goose-mcp/src/nondeveloper/mod.rs b/crates/goose-mcp/src/nondeveloper/mod.rs index 98e5ba4b..5233531b 100644 --- a/crates/goose-mcp/src/nondeveloper/mod.rs +++ b/crates/goose-mcp/src/nondeveloper/mod.rs @@ -577,7 +577,10 @@ impl Router for NonDeveloperRouter { } fn capabilities(&self) -> ServerCapabilities { - CapabilitiesBuilder::new().with_tools(true).build() + CapabilitiesBuilder::new() + .with_tools(false) + .with_resources(false, false) + .build() } fn list_tools(&self) -> Vec { diff --git a/crates/mcp-server/src/main.rs b/crates/mcp-server/src/main.rs index aa9a9f93..eee25002 100644 --- a/crates/mcp-server/src/main.rs +++ b/crates/mcp-server/src/main.rs @@ -58,7 +58,10 @@ impl Router for CounterRouter { } fn capabilities(&self) -> ServerCapabilities { - CapabilitiesBuilder::new().with_tools(true).build() + CapabilitiesBuilder::new() + .with_tools(false) + .with_resources(false, false) + .build() } fn list_tools(&self) -> Vec {