MCP server by shuclaw
MCP Tools Server
🔧 模块化 MCP 工具服务器 - Go 语言实现
特性
- 🚀 高性能 - Go 语言,编译即运行
- 📦 模块化 - 插件式工具注册
- 🔄 热加载 - 支持插件热重载
- 💾 Redis 缓存 - 内置 Redis 缓存支持
- 🔒 安全 - 操作审计日志
- 🌐 开源 - MIT 协议
快速开始
安装
git clone https://github.com/shuclaw/mcp-tools.git
cd mcp-tools
go build -o mcp-tools ./cmd/server
运行
# 基本运行
./mcp-tools
# 指定配置
PORT=3002 REDIS_ADDR=localhost:6379 ./mcp-tools
Docker
docker pull shuclaw/mcp-tools
docker run -d -p 3002:3002 shuclaw/mcp-tools
API 接口
健康检查
GET /health
工具列表
GET /mcp/tools
JSON-RPC 调用
POST /mcp
Content-Type: application/json
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "http_get",
"arguments": {
"url": "https://api.example.com/data"
}
},
"id": 1
}
批量调用
[
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "tool1"}, "id": 1},
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "tool2"}, "id": 2}
]
内置工具
系统工具
| 工具 | 描述 |
|------|------|
| system_info | 获取系统信息 |
| system_time | 获取当前时间 |
| system_exec | 执行系统命令 |
网络工具
| 工具 | 描述 |
|------|------|
| http_get | HTTP GET 请求 |
| http_post | HTTP POST 请求 |
| url_parse | URL 解析 |
| dns_lookup | DNS 查询 |
数据库工具
| 工具 | 描述 |
|------|------|
| redis_get | Redis GET |
| redis_set | Redis SET |
| redis_del | Redis DEL |
| redis_keys | Redis KEYS |
文本工具
| 工具 | 描述 |
|------|------|
| text_uppercase | 转大写 |
| text_lowercase | 转小写 |
| json_format | 格式化 JSON |
| json_parse | 解析 JSON |
工具类
| 工具 | 描述 |
|------|------|
| uuid_generate | 生成 UUID |
| hash_md5 | 计算 MD5 |
开发
添加新工具
// 1. 在 tools/ 目录创建文件
package tools
import "github.com/shuclaw/mcp-tools/server"
// 2. 创建工具处理函数
func myTool(args map[string]interface{}) (interface{}, error) {
name, ok := args["name"].(string)
if !ok {
return nil, fmt.Errorf("missing name")
}
return fiber.Map{"result": "Hello " + name}, nil
}
// 3. 注册工具
func MyTools(s *server.Server) {
s.RegisterTool(&server.Tool{
Name: "my_tool",
Description: "我的工具",
Category: "custom",
}, myTool)
}
// 4. 在 main.go 中调用
MyTools(s)
插件开发
// plugins/my_plugin/plugin.go
package my_plugin
import "github.com/shuclaw/mcp-tools/server"
type MyPlugin struct{}
func (p *MyPlugin) Name() string { return "my_plugin" }
func (p *MyPlugin) Version() string { return "1.0.0" }
func (p *MyPlugin) Load(s *server.Server) {
s.RegisterTool(&server.Tool{
Name: "plugin_tool",
Description: "插件工具",
Category: "plugin",
}, pluginToolHandler)
}
配置
| 环境变量 | 默认值 | 描述 |
|---------|--------|------|
| PORT | 3002 | HTTP 端口 |
| REDIS_ADDR | localhost:6379 | Redis 地址 |
| REDIS_PASSWORD | `` | Redis 密码 |
| PLUGIN_DIR | ./plugins | 插件目录 |
架构
┌─────────────────────────────────────────┐
│ HTTP Server (Fiber) │
├─────────────────────────────────────────┤
│ /health │ /mcp/tools │ /mcp │ /stats │
├─────────────────────────────────────────┤
│ JSON-RPC Handler │
├─────────────────────────────────────────┤
│ Tool Registry & Router │
├─────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────┐ ┌──────┐ │
│ │ System │ │ Network │ │ DB │ │
│ └──────────┘ └──────────┘ └──────┘ │
│ ┌──────────┐ ┌──────────┐ ┌──────┐ │
│ │ Text │ │ JSON │ │ Util │ │
│ └──────────┘ └──────────┘ └──────┘ │
├─────────────────────────────────────────┤
│ Redis Cache │
└─────────────────────────────────────────┘
License
MIT