一个实现了模型上下文协议(MCP)的服务器,提供带有全面系统工具的AI助手功能。
此MCP服务器通过模型上下文协议实现与AI模型的无缝集成,提供了一种标准化的方式与AI助手进行交互并有效管理上下文。使用Go构建以实现高性能和可靠性。
git clone (https://github.com/can-acar/jarvis)
cd jarvis
go mod download
go build -o jarvis main.go
./jarvis
服务器将启动并通过stdio使用MCP协议进行通信。
服务器使用config.yaml文件进行配置:
# 安全设置
blockedCommands:
- rm
- shutdown
# 命令执行的默认shell
defaultShell: bash
# 文件操作允许的目录
allowedDirectories:
- /tmp
- /var/log
# 文件操作限制
fileReadLineLimit: 1000
fileWriteLineLimit: 50
# 遥测
telemetryEnabled: false
服务器提供了以下MCP工具:
get-config - 获取当前服务器配置set-config - 更新服务器配置值execute-command - 执行带安全控制的shell命令get-command-history - 获取命令执行历史read-file - 支持分页的文件内容读取write-file - 写入文件内容list-directory - 列出目录内容create-directory - 创建新目录delete-file - 删除文件和目录move-file - 移动/重命名文件和目录file-info - 获取文件元数据和信息edit-file - 执行复杂的文本编辑操作search-replace - 在文件中搜索和替换文本batch-edit - 对文件应用多个编辑fetch-url - 从web URL抓取内容download-file - 从远程源下载文件jarvis/
├── main.go # 主服务器入口点
├── config.yaml # 服务器配置
├── go.mod # Go模块定义
├── go.sum # Go模块校验和
├── handlers/ # MCP工具处理器
│ ├── config_handler.go # 配置管理
│ ├── terminal_handler.go # 终端操作
│ ├── filesystem_handler.go # 文件系统操作
│ ├── textediting_handler.go # 文本编辑工具
│ └── fetch_handler.go # HTTP抓取操作
└── internal/ # 内部包
├── common/ # 共享实用工具
├── config/ # 配置管理
├── terminal/ # 终端实用工具
├── filesystem/ # 文件系统实用工具
├── textedit/ # 文本编辑实用工具
├── fetch/ # 抓取实用工具
└── types/ # 类型定义
# 构建项目
go build -o jarvis main.go
# 运行测试
go test ./...
# 使用详细日志运行
go run main.go
# 为不同平台构建
GOOS=windows GOARCH=amd64 go build -o jarvis.exe main.go
GOOS=linux GOARCH=amd64 go build -o jarvis-linux main.go
要添加新的MCP工具:
func HandleNewTool(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// 实现代码
return mcp.NewToolResultText("结果"), nil
}
func RegisterNewTools(s *server.MCPServer) {
s.AddTool("new-tool", "描述", map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"param": map[string]interface{}{
"type": "string",
"description": "参数描述",
},
},
"required": []string{"param"},
}, handlers.HandleNewTool)
}
main.go中调用注册函数。git checkout -b feature-namego fmt ./...go test ./...git commit -m '添加功能'git push origin feature-name服务器实现了以下MCP功能:
该项目根据MIT许可证发布 - 查看LICENSE文件获取详情。
对于支持和问题: