Jarvis MCP服务器
一种模型上下文协议(MCP)服务器实现,通过全面的系统工具提供人工智能辅助功能。
概述
此MCP服务器通过模型上下文协议实现了与AI模型的无缝集成,提供了一种与AI助手交互和有效管理上下文的标准化方法。采用Go构建,具有高性能和可靠性。
特性
- MCP协议支持:使用mark3labs/mcp-go完全实现模型上下文协议
- 安全第一设计:可配置的命令阻止和目录访问控制
- 系统集成:终端命令执行与安全控制
- 文件系统操作:安全的文件读取、写入和操作
- 文本编辑工具:具有基于行的操作的高级文本编辑功能
- HTTP获取工具:内置web内容获取功能
- 配置管理:通过MCP工具更新运行时配置
- Go实现:用Go编写的高性能服务器,具有强大的错误处理功能
安装
先决条件
- 转到1.24.4或更高版本
- Git
设置
- 克隆存储库:```bash
git clone (https://github.com/can-acar/jarvis)
cd jarvis
2. 安装依赖项:```bash
go mod download
- 构建项目:```bash
go build -o jarvis main.go
## 用法
### 启动服务器```bash
./jarvis
服务器将使用MCP协议通过stdio启动和通信。
配置
服务器使用 config.yaml 配置文件:```yaml
Security settings
blockedCommands:
- rm
- shutdown
Default shell for command execution
defaultShell: bash
Allowed directories for file operations
allowedDirectories:
- /tmp
- /var/log
File operation limits
fileReadLineLimit: 1000
fileWriteLineLimit: 50
Telemetry
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 # Main server entry point
├── config.yaml # Server configuration
├── go.mod # Go module definition
├── go.sum # Go module checksums
├── handlers/ # MCP tool handlers
│ ├── config_handler.go # Configuration management
│ ├── terminal_handler.go # Terminal operations
│ ├── filesystem_handler.go # File system operations
│ ├── textediting_handler.go # Text editing tools
│ └── fetch_handler.go # HTTP fetch operations
└── internal/ # Internal packages
├── common/ # Shared utilities
├── config/ # Configuration management
├── terminal/ # Terminal utilities
├── filesystem/ # File system utilities
├── textedit/ # Text editing utilities
├── fetch/ # Fetch utilities
└── types/ # Type definitions
建造和测试```bash
Build the project
go build -o jarvis main.go
Run tests
go test ./...
Run with verbose logging
go run main.go
Build for different platforms
GOOS=windows GOARCH=amd64 go build -o jarvis.exe main.go
GOOS=linux GOARCH=amd64 go build -o jarvis-linux main.go
### 添加自定义工具
要添加新的MCP工具:
1. 在相应的处理程序文件中创建一个处理程序函数:```go
func HandleNewTool(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// Implementation here
return mcp.NewToolResultText("Result"), nil
}
-
在相应的内部包中注册该工具:
go func RegisterNewTools(s *server.MCPServer) { s.AddTool("new-tool", "Description", map[string]interface{}{ "type": "object", "properties": map[string]interface{}{ "param": map[string]interface{}{ "type": "string", "description": "Parameter description", }, }, "required": []string{"param"}, }, handlers.HandleNewTool) } -
在中调用注册功能
main.go.
贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature-name - 进行更改并添加测试
- 确保代码遵循Go约定:
go fmt ./... - 运行测试:
go test ./... - 提交您的更改:
git commit -m 'Add feature' - 推到分支:
git push origin feature-name - 提交拉取请求
安全考虑
- 对命令进行清理,并根据被阻止的模式进行检查
- 文件系统访问仅限于允许的目录
- 命令执行包括超时控制
- 所有操作都记录在案,以供审计之用
- 配置可以限制危险操作
依赖项
- mark3labs/mcp go:Go的MCP协议实现
- google/uid:UUID生成
- spf13/cast:类型铸造实用程序
API文档
MCP协议实现
服务器实现了以下MCP功能:
- 工具:执行系统操作(文件I/O、终端命令等)
- 资源:通过适当的访问控制访问文件系统资源
- 鼓励:基于模板的提示管理
工具类别
- 系统工具:终端命令执行、进程管理
- 文件工具:具有安全边界的文件操作
- 文本工具:高级文本操作和编辑
- 网络工具:HTTP请求和内容获取
- 配置工具:运行时配置管理
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
支持
有关支持和问题:
- 在GitHub上创建问题
- 检查文档和代码注释
- 审查现有问题和讨论
业绩说明
- 使用Go构建,实现高并发性和高性能
- 具有可配置限制的高效文件操作
- 大文件处理的内存意识设计
- 针对标准输入输出上的MCP协议通信进行了优化
