simple-rust-mcp-server
A simple Model Context Protocol (MCP) server implementation in Rust with streamable-http transport
GitHubスター
0
ユーザー評価
未評価
お気に入り
0
閲覧数
7
フォーク
0
イシュー
0
README
MCP Server
A simple Model Context Protocol (MCP) server implementation in Rust with streamable-http transport. This server provides example tools and can be easily deployed using Docker.
Features
- 🚀 Lightweight MCP server with streamable-http transport
- 🛠️ Four example tools included:
get_time
- Get the current timeincrement_counter
- Increment a counterget_counter
- Get the current counter valuesystem_info
- Get system information
- 🐳 Docker support with multi-platform builds (amd64/arm64)
- 🔄 Automatic GitHub Actions for Docker image publishing
- 📦 Minimal dependencies and small image size
Quick Start
Using Docker (Recommended)
Pull and run the latest image:
docker run -p 8080:8080 ghcr.io/digibugcat/simple-rust-mcp-server:latest
Using Docker Compose
docker-compose up
Building from Source
Requirements:
- Rust 1.75 or later
# Clone the repository
git clone https://github.com/DigiBugCat/simple-rust-mcp-server.git
cd simple-rust-mcp-server
# Build and run
cargo run --release
Endpoints
- Streamable HTTP Endpoint:
http://localhost:8080/message
- JSON-RPC endpoint for MCP protocol
Environment Variables
HOST
- Server host (default:0.0.0.0
)PORT
- Server port (default:8080
)RUST_LOG
- Log level (default:mcp_server=info
)
Docker Image
The Docker image is automatically built and published to GitHub Container Registry on every push to the main branch.
Available Tags
latest
- Latest build from main branchvX.Y.Z
- Specific version releasesmain
- Latest main branch build
Testing with MCP Inspector
You can test the server using MCP Inspector:
- Start the server:
docker run -p 8080:8080 ghcr.io/digibugcat/simple-rust-mcp-server:latest
- Open MCP Inspector
- Select transport:
streamable-http
- Enter URL:
http://localhost:8080/message
- Connect and test the tools
Example Usage with MCP Client
// Example using the MCP SDK with streamable-http transport
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHttpClientTransport } from '@modelcontextprotocol/sdk/client/streamable-http.js';
const transport = new StreamableHttpClientTransport(
new URL('http://localhost:8080/message')
);
const client = new Client({
name: 'example-client',
version: '1.0.0',
}, {
capabilities: {}
});
await client.connect(transport);
// Call a tool
const result = await client.callTool({
name: 'get_time',
arguments: {}
});
console.log(result);
Development
Project Structure
.
├── src/
│ ├── main.rs # Main server entry point
│ └── mcp/
│ ├── mod.rs # MCP module
│ └── tools.rs # Tool implementations
├── Cargo.toml # Rust dependencies
├── Dockerfile # Multi-stage Docker build
├── docker-compose.yml # Local development setup
└── .github/
└── workflows/
└── docker-publish.yml # CI/CD pipeline
Adding New Tools
To add new tools, edit src/mcp/tools.rs
and add your tool implementation using the #[tool]
macro:
#[tool(description = "Your tool description")]
async fn your_tool_name(&self, param: String) -> Result<CallToolResult, McpError> {
// Tool implementation
Ok(CallToolResult::success(vec![
Content::text("Tool result")
]))
}
License
MIT