- Tiny MCP Server (Rust)
Tiny MCP Server (Rust)
A rust implementation for the Machine Communication Protocol (MCP)
Content
Tiny MCP Server (Rust)
这是一个用Rust实现的MCP(Machine Conversation Protocol)服务器。
功能
- 支持MCP协议的生命周期管理
- 支持多种传输方式(stdio、SSE)
- 提供工具注册和调用机制
运行测试
运行所有测试:
cargo test
运行SSE测试
SSE测试需要启动实际的服务器进程,可能会导致端口冲突和进程残留问题。这些测试默认被标记为#[ignore],需要手动运行。
要运行SSE测试,请按照以下步骤操作:
- 首先清理可能残留的进程:
./scripts/cleanup_sse.sh
- 然后手动运行SSE示例:
cargo run --example sse
- 在另一个终端窗口中,使用curl测试SSE服务器:
curl http://localhost:3000/schema
- 如果需要关闭SSE服务器,可以使用以下命令:
lsof -i :3000 -t | xargs kill -9
清理残留进程
如果测试过程中出现问题,可能会有SSE服务器进程残留。使用以下脚本清理:
./scripts/cleanup_sse.sh
示例
运行stdio服务器
cargo run --example stdio
运行SSE服务器
cargo run --example sse
默认监听127.0.0.1:3000。可以指定不同的地址:
cargo run --example sse -- 127.0.0.1:8080
Features
- Multiple Transport Layers: Supports both stdio and Server-Sent Events (SSE) transports
- Extensible Tool System: Easily register custom tools with the server
- Type-Safe API: Leverages Rust's type system for safe and reliable communication
- Asynchronous Design: Built on tokio for high-performance async I/O
- Simple Integration: Just add a single dependency to your project
- Convenient Imports: Use the prelude module to import all necessary types and traits
Installation
Add this to your Cargo.toml:
[dependencies]
tiny_mcp_server = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
serde_json = "1.0"
Quick Start
For convenience, you can use the prelude module to import all necessary types and traits:
use serde_json::{Value, json};
use std::error::Error;
use tiny_mcp_server::prelude::*;
#[mcp_tool(
description = "A simple greeting tool",
version = "1.0.0",
category = "examples"
)]
pub async fn say_hello(name: String) -> MCPResult<Value> {
Ok(json!({
"greeting": format!("Hello {name}")
}))
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Start with stdio transport
server::start_stdio().await
}
Documentation
For more detailed documentation, see the API documentation.
Examples
Check out the examples directory for more usage examples:
stdio.rs: Example using stdio transportsse.rs: Example using SSE transport
License
This project is licensed under either of:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
WindsurfThe new purpose-built IDE to harness magic
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Serper MCP ServerA Serper MCP Server
Tavily Mcp
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
ChatWiseThe second fastest AI chatbot™
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
CursorThe AI Code Editor
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright McpPlaywright MCP server
DeepChatYour AI Partner on Desktop
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Amap Maps高德地图官方 MCP Server