Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource capabilties to MCP servers that use it #576

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/goose-mcp/README.md
Original file line number Diff line number Diff line change
@@ -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.
36 changes: 36 additions & 0 deletions crates/goose-mcp/examples/mcp.rs
Original file line number Diff line number Diff line change
@@ -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?)
}
5 changes: 4 additions & 1 deletion crates/goose-mcp/src/developer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tool> {
Expand Down
5 changes: 4 additions & 1 deletion crates/goose-mcp/src/developer2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tool> {
Expand Down
5 changes: 4 additions & 1 deletion crates/goose-mcp/src/nondeveloper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tool> {
Expand Down
5 changes: 4 additions & 1 deletion crates/mcp-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tool> {
Expand Down
Loading