Token导航 LogoToken导航TokenDH.com
MCP Go SDK logo
开发工具未说明官方级别未说明来源级核验

MCP Go SDK

MCP Server

MCP Server SDK in Go and some servers I'm using myself

工具数

1

提示词数

0

GitHub Stars

3

资源数

0
协议实现GoCursorGo语言Cursor

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

dentaku7

提供方

dentaku7

最后核验

2026/5/18 04:56

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

MCP Go SDK

用于构建模型通信协议(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:

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.配置

要将MCP工具与Cursor IDE一起使用,请创建 `.cursor/mcp.json` 在项目根目录中:

{ "mcpServers": { "mytool": { "command": "mytool", "args": [], "env": {} } } }


## 贡献

1. 分叉存储库
1. 创建要素分支
1. 添加新功能的测试
1. 提交拉取请求

请确保您的代码:

- 遵循Go最佳实践
- 包括适当的文件
- 具有测试覆盖率
- 适当处理错误

目录标签

目录标签

协议实现GoCursorGo语言developer-toolsAI工具开发本地部署SDK

支持客户端

Cursor

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP