本地开发和测试
先决条件
- 锈蚀1.70+(
rustup update) - Python 3.8+(用于客户端测试)
- 紫外线 (
brew install uvmacOS)
从源头构建
- 克隆存储库:
git clone https://github.com/your-org/syncable-cli-mcp-server.git
cd syncable-cli-mcp-server- 构建项目:
# Debug build
cargo build
# Release build
cargo build --release二进制文件将在以下位置提供:
- 调试:
./target/debug/mcp-stdio和./target/debug/mcp-sse - 发布:
./target/release/mcp-stdio和./target/release/mcp-sse
测试MCP服务器
- 测试生锈部件:
# Run unit tests
cargo test
# Run with logging
RUST_LOG=debug cargo test- 使用Python客户端进行手动测试:
首先,在终端中启动MCP服务器:
# For stdio mode
cargo run --bin mcp-stdio
# For SSE mode (in another terminal)
cargo run --bin mcp-sse然后在另一个终端中,设置Python环境:
# Setup Python environment
cd mcp-python-server-client
# Create and activate virtual environment using uv
uv venv
source .venv/bin/activate
# Install dependencies
uv pip install -r requirements.txt
# Or use sync if you have a requirements.lock
uv sync
# Test stdio mode
uv run python -m src.mcp_py_client_rust_server_stdio
# Test SSE mode
uv run python src.mcp_py_client_rust_server_sse- 验证可用工具:
服务器应在启动时显示可用工具。您应该看到:
- about_info
- 分析扫描
- 安全扫描
- 依赖性扫描
- 测试每个工具:
# Using stdio mode for example
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()
# Test about_info
result = await session.call_tool("about_info", {})
print("About Info:", result)
# Test analysis_scan
result = await session.call_tool("analysis_scan",
{"path": ".", "display": "matrix"})
print("Analysis Scan:", result)
# Test security_scan
result = await session.call_tool("security_scan", {"path": "."})
print("Security Scan:", result)
# Test dependency_scan
result = await session.call_tool("dependency_scan", {"path": "."})
print("Dependency Scan:", result)
asyncio.run(test_tools())- 使用LangGraph进行集成测试:
# Install LangGraph dependencies
uv add langgraph openai python-dotenv langchain_mcp_adapters
# Test stdio integration
uv run python -m src.langgraph_stdio_demo
# Test SSE integration
uv run python -m src.langgraph_sse_demo常见问题与调试
- 端口已在使用中 (SSE模式):
lsof -i :8000 # Check if port 8000 is in use
kill -9
# Kill the process if needed- 未找到二进制文件 (stdio模式):
- 确保Python客户端中的二进制路径与您的构建位置匹配
- 检查
cargo build成功 - 验证二进制权限(
chmod +x如果需要)
- 启用调试日志记录:
# For Rust server
RUST_LOG=debug cargo run --bin mcp-stdio
# For Python client
uv python -c "import logging; logging.basicConfig(level=logging.DEBUG)"使用发布plz的自动发布流程
我们使用 释放plz 实现版本控制和发布的自动化。工作流已在中配置 .github/workflows/release-plz.yml.
- 设置:
# Install release-plz
cargo install release-plz
# Configure GitHub token
export GITHUB_TOKEN=your_github_token
export CARGO_REGISTRY_TOKEN=your_crates_io_token- 检查发布状态:
# Preview what would be released
release-plz check- 发布过程:
- 将您的更改推送到
main分支 - GitHub Action将自动执行以下操作:
- 更新Cargo.toml中的版本 - 生成变更日志条目 - 创建发布PR或直接发布 - 准备就绪后推到crates.io
- 手动释放 (如果需要):
# Create changelog and bump version
release-plz release
# Update changelog only
release-plz update-changelog手动预发布检查表
在发布到crates.io之前:
- 所有测试均通过:
cargo test - 代码格式:
cargo fmt --all -- --check - 无剪贴警告:
cargo clippy -- -D warnings - 最新文档:
cargo doc --no-deps - 版本冲突:
- Cargo.toml - 更改日志.md
- Python客户端示例工作
- 测试了两种传输模式(stdio/SSE)
出版流程
只有在本地测试成功后:
# Login to crates.io
cargo login
# Dry run
cargo publish --dry-run
# Actual publish
cargo publish