Skip to content

ktxhkpnwbd/rust-mcp-sample

Repository files navigation

Rust MCP Server (Modular Template)

This repository is a complete, layered MCP server scaffold in Rust using stdio transport.

Architecture

  • src/domain: core types and contracts
  • src/application: request handling and MCP method routing
  • src/tools: tool implementations and registry
  • src/infrastructure: transport implementation (stdio)
  • src/main.rs: process bootstrap and runtime loop

Configuration Layer

Configuration is loaded in this order:

  1. Defaults from ServerConfig
  2. Optional JSON file: mcp-server.json (or path from MCP_SERVER_CONFIG_PATH)
  3. Environment variable overrides

Supported environment variables:

  • MCP_SERVER_NAME
  • MCP_SERVER_VERSION
  • MCP_SERVER_PROTOCOL_VERSION
  • MCP_SERVER_TOOLS_LIST_CHANGED

An example config file is available at mcp-server.example.json.

Included Tools

  • echo: returns the input message
  • now: returns the current UTC timestamp in RFC3339 format

Run

Server only:

cargo run

Windows shortcut:

.\bin\run-server.bat

Client (spawns server internally):

cargo run --bin client

See CLIENT.md for more details on the client module.

VS Code task:

  • Run task Run MCP Server from the Command Palette.

Test Tools (Windows)

Run unit tests:

cargo test

Run integration tests only:

cargo test --test integration_tests

Run smoke test (interactive server validation):

.\bin\test-tools.bat

See TESTS.md for full test documentation.

The server communicates over stdio using JSON-RPC framing (Content-Length headers), compatible with MCP clients.

Extend

  1. Add a new tool under src/tools implementing the Tool trait.
  2. Register it in ToolRegistry::new() in src/tools/mod.rs.
  3. Keep protocol handling in src/application/mcp_service.rs focused on MCP method dispatch.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors