组件工具MCP服务器
一个模型上下文协议(MCP)服务器,为WebAssembly组件开发提供工具,使用 cargo component.
特性
此MCP服务器公开了使用WebAssembly组件的两个主要工具:
可用工具
- 组件绑定 -为WebAssembly组件生成绑定
- 跑 cargo component bindings 在指定目录中 - 支持其他参数
- 组件构建 -构建WebAssembly组件
- 跑 cargo component build 在指定目录中 - 支持其他参数,如 --release, --target等等。
先决条件
在使用此服务器之前,您需要 cargo-component 安装:
cargo install cargo-component安装
- 克隆此存储库并导航到组件工具mcp目录
- 构建服务器:
cargo build --release用法
运行服务器
# Run with default settings (allows access to all directories)
cargo run
# Run with restricted directory access
cargo run -- --allowed-dir /path/to/your/components --allowed-dir /another/path
# Run with custom logging
cargo run -- --log-level debug --log-file component-tools.log命令行选项
--allowed-dir:指定允许组件操作的目录(可以多次使用)--log-level:设置日志级别(跟踪、调试、信息、警告、错误)-默认为“信息”--log-file:记录到文件而不是stderr
与MCP客户端一起使用
服务器运行后,MCP客户端可以使用以下工具:
组件绑定
为组件项目生成绑定:
{
"name": "component-bindings",
"arguments": {
"directory": "/path/to/your/component/project",
"args": ["--out-dir", "generated"]
}
}组件构建
构建组件项目:
{
"name": "component-build",
"arguments": {
"directory": "/path/to/your/component/project",
"args": ["--release"]
}
}安全功能
- 目录限制:何时
--allowed-dir如果指定了,服务器将仅在这些目录中运行 - 路径验证:所有路径在执行前都经过验证
- 命令隔离:只有
cargo component命令被执行
错误处理
服务器提供详细的错误信息,包括:
- 命令执行状态
- stdout和stderr输出
- 退出代码
- 路径验证错误
发展
建筑
cargo build测试
cargo test在发展中奔跑
cargo run -- --log-level debug示例用法
基本用法
- 启动服务器:
cargo run- 从目录限制开始:
cargo run -- --allowed-dir /home/user/components --allowed-dir /home/user/other-components- 从调试日志开始:
cargo run -- --log-level debug --log-file component-tools.log与MCP客户端一起使用
服务器公开了MCP客户端可以调用的两个工具:
组件绑定
{
"name": "component-bindings",
"arguments": {
"directory": "/path/to/your/component/project",
"args": ["--out-dir", "generated"]
}
}组件构建
{
"name": "component-build",
"arguments": {
"directory": "/path/to/your/component/project",
"args": ["--release"]
}
}MCP客户端配置示例
对于Claude Desktop或其他MCP客户端,请将以下内容添加到您的配置中:
{
"mcpServers": {
"component-tools": {
"command": "cargo",
"args": ["run", "--release"],
"cwd": "/path/to/component-tools-mcp",
"env": {
"RUST_LOG": "info"
}
}
}
}与其他工具集成
此MCP服务器设计用于:
- Claude桌面应用程序
- 其他MCP兼容客户端
- 涉及WebAssembly组件的开发工作流程
故障排除
“未找到货物组件”错误
确保您安装了货物组件:
cargo install cargo-component权限错误
如果您遇到权限错误:
- 检查目标目录是否存在并且可写
- 确保该目录在您的允许目录列表中(如果使用
--allowed-dir)
构建失败
组件构建失败将以完整的stdout/stderr输出报告,以帮助调试。
