关于 MCP-Go SDK
MCP-Go SDK 是用于构建 MCP 工具和服务的 Go 开发套件,面向 Go 开发者。它定义工具接口与响应格式,并提供包含 stdio 支持的传输层。
主要功能
- 01构建 MCP 工具和服务
- 02定义工具结构与执行方式
- 03采用 MCP 工具响应格式
- 04使用传输接口
- 05内置 stdio 传输
适用场景
- 01用 Go 实现 MCP 工具
- 02创建精简示例服务
- 03通过 JSON Schema 描述工具参数
- 04通过 stdio 连接命令行工具
MCP 相关
该 SDK 提供实现符合 MCP 规范的工具和服务所需的构件。其传输层包含供命令行工具使用的 stdio 支持。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
暂未收录安装方式
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
MCP-Go SDK
用于构建 Model Communication Protocol(MCP)工具和服务的 Go SDK。此 SDK 提供了实现符合 MCP 规范的工具所需的构建模块,这些工具可与 Cursor IDE 等 AI 应用配合使用。
快速开始
查看 servers/example 中的示例服务,了解一个最小化 MCP 工具实现,该工具会回显收到的消息:
package main
import (
"encoding/json"
"mcp-go/server"
"mcp-go/transport"
)
// EchoTool implements a simple echo tool
type EchoTool struct{}
func (t *EchoTool) Name() string {
return "echo"
}
func (t *EchoTool) Description() string {
return "A simple echo tool that returns the input message"
}
func (t *EchoTool) Schema() json.RawMessage {
return json.RawMessage(`{
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "The message to echo back"
}
},
"required": ["message"]
}`)
}
func (t *EchoTool) Execute(params json.RawMessage) (interface{}, error) {
var input struct {
Message string `json:"message"`
}
if err := json.Unmarshal(params, &input); err != nil {
return nil, err
}
return map[string]interface{}{
"content": []map[string]interface{}{
{
"type": "text",
"text": input.Message,
},
},
"metadata": map[string]interface{}{
"length": len(input.Message),
},
}, nil
}
func main() {
// Create a new server with stdin/stdout transport
srv := server.NewServer(transport.NewStdioTransport())
// Register your tool
if err := srv.RegisterTool(&EchoTool{}); err != nil {
panic(err)
}
// Start the server
if err := srv.Start(); err != nil {
panic(err)
}
}
## Core Concepts
### 1. Tools
A Tool in MCP is a service that can be called by AI applications. Each tool must implement the `mcp.Tool` interface:
```go
type Tool interface {
// Name returns the unique identifier for this tool
Name() string
// Description returns a human-readable description
Description() string
// Schema returns the JSON schema for the tool's parameters
Schema() json.RawMessage
// Execute runs the tool with the given parameters
Execute(params json.RawMessage) (interface{}, error)
}
2. 响应格式
工具应以 MCP 格式返回响应:
{
"content": [
{
"type": "text",
"text": "Your response text"
}
],
"metadata": {
// Optional metadata about the response
}
}
3. 传输层
SDK 通过 Transport 接口提供灵活的传输层:
type Transport interface {
Send(data interface{}) error
Receive() ([]byte, error)
Close() error
}
默认情况下,SDK 包含用于命令行工具的 stdio 传输(transport.NewStdioTransport())。
4. 配置
要在 Cursor IDE 中使用 MCP 工具,请在项目根目录中创建 .cursor/mcp.json:
{
"mcpServers": {
"mytool": {
"command": "mytool",
"args": [],
"env": {}
}
}
}
贡献
- Fork 此仓库
- 创建功能分支
- 为新功能添加测试
- 提交 pull request
请确保代码:
- 遵循 Go 最佳实践
- 包含适当的文档
- 具有测试覆盖
- 能够妥善处理错误
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。