rustup update)brew install uv 在macOS上)git clone https://github.com/your-org/syncable-cli-mcp-server.git
cd syncable-cli-mcp-server
# 调试构建
cargo build
# 发布构建
cargo build --release
二进制文件将在以下位置可用:
./target/debug/mcp-stdio 和 ./target/debug/mcp-sse./target/release/mcp-stdio 和 ./target/release/mcp-sse# 运行单元测试
cargo test
# 带日志运行
RUST_LOG=debug cargo test
首先,在终端中启动MCP服务器:
# 对于stdio模式
cargo run --bin mcp-stdio
# 对于SSE模式(在另一个终端中)
cargo run --bin mcp-sse
然后在另一个终端中设置Python环境:
# 设置Python环境
cd mcp-python-server-client
# 使用uv创建并激活虚拟环境
uv venv
source .venv/bin/activate
# 安装依赖项
uv pip install -r requirements.txt
# 或者使用sync如果你有requirements.lock
uv sync
# 测试stdio模式
uv run python -m src.mcp_py_client_rust_server_stdio
# 测试SSE模式
uv run python src.mcp_py_client_rust_server_sse
服务器启动时应显示可用工具。你应该看到:
# 例如使用stdio模式
cargo run --bin mcp-stdio
在另一个终端中:
import asyncio
from mcp.client.session import ClientSession
from mcp.client.stdio import StdioServerParameters, stdio_client
async def test_tools():
async with stdio_client(
StdioServerParameters(command="../target/debug/mcp-stdio")
) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# 测试about_info
result = await session.call_tool("about_info", {})
print("关于信息:", result)
# 测试analysis_scan
result = await session.call_tool("analysis_scan",
{"path": ".", "display": "矩阵"})
print("分析扫描:", result)
# 测试security_scan
result = await session.call_tool("security_scan", {"path": "."})
print("安全扫描:", result)
# 测试dependency_scan
result = await session.call_tool("dependency_scan", {"path": "."})
print("依赖扫描:", result)
asyncio.run(test_tools())
# 安装LangGraph依赖项
uv add langgraph openai python-dotenv langchain_mcp_adapters
# 测试stdio集成
uv run python -m src.langgraph_stdio_demo
# 测试SSE集成
uv run python -m src.langgraph_sse_demo
lsof -i :8000 # 检查端口8000是否被占用
kill -9 <PID> # 如需,请终止进程
cargo build是否成功chmod +x)# 对于Rust服务器
RUST_LOG=debug cargo run --bin mcp-stdio
# 对于Python客户端
uv python -c "import logging; logging.basicConfig(level=logging.DEBUG)"
我们使用release-plz来自动化版本管理和发布。工作流配置在.github/workflows/release-plz.yml。
# 安装release-plz
cargo install release-plz
# 配置GitHub令牌
export GITHUB_TOKEN=your_github_token
export CARGO_REGISTRY_TOKEN=your_crates_io_token
# 预览将要发布的项目
release-plz check
main分支# 创建变更日志并提升版本
release-plz release
# 只更新变更日志
release-plz update-changelog
在发布到crates.io之前:
cargo testcargo fmt --all -- --checkcargo clippy -- -D warningscargo doc --no-deps仅在本地测试成功后:
# 登录到crates.io
cargo login
# 干运行
cargo publish --dry-run
# 实际发布
cargo publish