This project implements a simple Model Context Protocol (MCP) server in Rust that exposes a set of counter tools via the MCP protocol. The server allows clients to increment, decrement, and retrieve the value of a shared counter using defined tools.
- Increment Tool: Increases the counter by 1.
- Decrement Tool: Decreases the counter by 1.
- Get Counter Tool: Returns the current value of the counter.
- MCP Protocol: Implements the MCP server protocol for tool-based interaction.
- The main logic is in
src/main.rs
. - The
HelloWorld
struct manages the counter state using an async mutex for safe concurrent access. - Tools are defined using the
#[tool]
macro and exposed via the MCP protocol. - The server is started using Tokio and listens for requests over stdio.
Make sure you have Rust and Cargo installed. Then run:
cargo build --release
Start the MCP server:
cargo run --release
The server will listen for MCP requests over stdio.
- Increment Counter:
- Tool name:
increment
- Description: Increments the counter by 1 and returns the new value.
- Tool name:
- Decrement Counter:
- Tool name:
decrement
- Description: Decrements the counter by 1 and returns the new value.
- Tool name:
- Get Counter Value:
- Tool name:
get_counter
- Description: Returns the current value of the counter.
- Tool name:
src/main.rs
: Main server implementationCargo.toml
: Rust dependencies and metadata
- The server is designed for demonstration and testing of MCP tool capabilities.
- You can extend the toolset by adding more methods to the
HelloWorld
struct and annotating them with the#[tool]
macro.
MIT