Token导航 LogoToken导航

MCP Server · AI代理

MCP Gin

MCP-Gin是一个Go库,将Gin Web应用程序转换为Model Context Protocol (MCP)服务器,使AI工具能够无缝与API交互。

未说明官方级别未说明来源级核验工具 0
API转换GoClineGo语言

快速开始

公开资料没有提供安装命令,按仓库或官方文档接入。
作者 / 组织
landmaster135
提供方
landmaster135

工具数量

0

来源目录标注

资源数量

0

来源目录标注

提示词数量

0

来源目录标注

GitHub Star

0

仓库热度

收录来源

1 个

MCP World

选型结论

MCP Gin 属于AI代理类 MCP Server,公开资料标注 0 个工具,通过传输方式未标注接入,适配 Cline,没有现成的安装命令;接入前要先准备 访问 Token。

分类

AI代理

传输方式

未说明

认证方式

访问 Token

部署方式

公开资料未说明

安装与配置

公开目录没有给出安装命令,需要按仓库 README安装;下面按同类条目的通用流程说明。

公开命令不是通用的启动方式,拼不出可靠配置示例;请在客户端 MCP 配置里按官方文档填写 command 和 args。

上手步骤

  1. 1

    先确认运行方式

    公开资料没有标注传输方式,先看仓库 README,确认是本地进程还是远程地址。

  2. 2

    获取服务

    公开目录没有给出安装命令,按仓库 README里的步骤安装或获取服务。

  3. 3

    写入客户端配置

    在客户端的 MCP 配置里填启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4

    验证是否可用

    连接成功后客户端会列出 0 个工具,随便调一个只读工具确认能返回结果。

接入前确认

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

公开资料仍需确认:安装命令

详细介绍

MCP杜松子酒

MCP杜松子酒 是一个Go库,可以转换您的 金酒 web应用程序进入 模型上下文协议(MCP) 服务器,使AI工具能够与您的API无缝交互。

特性

  • 🚀 自动路线转换:将现有的Gin HTTP路由自动转换为MCP工具
  • 🔧 MCP专用工具:创建不需要HTTP端点直接执行的工具
  • 📋 模式自动生成:使用反射从Go结构生成JSON模式
  • 🎯 灵活的配置:筛选工具、设置基本URL和自定义行为
  • 🔒 环境变量支持:通过环境变量进行安全令牌处理
  • 📖 丰富的示例:包括完整的实施示例

安装

go get github.com/landmaster135/mcp-gin

快速开始

基本HTTP路由转换

package main

import (
    "net/http"
    "github.com/gin-gonic/gin"
    server "github.com/landmaster135/mcp-gin"
)

type Product struct {
    ID    int     `json:"id" jsonschema:"readOnly"`
    Name  string  `json:"name" jsonschema:"required,description=Product name"`
    Price float64 `json:"price" jsonschema:"required,minimum=0,description=Price in USD"`
}

func main() {
    r := gin.Default()
    
    // Regular Gin routes
    r.GET("/products", listProducts)
    r.POST("/products", createProduct)
    
    // Initialize MCP server
    mcp := server.New(r, &server.Config{
        Name:        "Product API",
        Description: "API for managing products",
        BaseURL:     "http://localhost:8080",
    })
    
    // Register schemas for automatic conversion
    mcp.RegisterSchema("GET", "/products", nil, nil)
    mcp.RegisterSchema("POST", "/products", nil, Product{})
    
    // Mount MCP endpoint
    mcp.Mount("/mcp")
    
    r.Run(":8080")
}

func listProducts(c *gin.Context) {
    // Your existing handler logic
    c.JSON(http.StatusOK, []Product{})
}

func createProduct(c *gin.Context) {
    // Your existing handler logic
    c.JSON(http.StatusCreated, Product{})
}

MCP专用工具(高级)

创建无需HTTP端点即可直接执行的工具:

type CalculateRequest struct {
    A int `json:"a" jsonschema:"required,description=First number"`
    B int `json:"b" jsonschema:"required,description=Second number"`
}

func main() {
    r := gin.Default()
    mcp := server.New(r, &server.Config{
        Name: "Calculator API",
    })
    
    // Register MCP-only tool
    mcp.RegisterMCPTool(
        "calculate",
        "Perform arithmetic calculations",
        CalculateRequest{},
        func(params map[string]any) (any, error) {
            a := int(params["a"].(float64))
            b := int(params["b"].(float64))
            return map[string]int{"result": a + b}, nil
        },
    )
    
    mcp.Mount("/mcp")
    r.Run(":8080")
}

环境变量集成

对于安全的令牌处理:

type SecureRequest struct {
    Data string `json:"data" jsonschema:"required,description=Data to process"`
}

func secureHandler(params map[string]any) (any, error) {
    // Get token from environment variable
    token := os.Getenv("API_TOKEN")
    if token == "" {
        return nil, fmt.Errorf("API_TOKEN environment variable not set")
    }
    
    // Process with token
    data := params["data"].(string)
    return map[string]string{"processed": data}, nil
}

func main() {
    r := gin.Default()
    mcp := server.New(r, &server.Config{Name: "Secure API"})
    
    mcp.RegisterMCPTool("secure-process", "Process data securely", 
        SecureRequest{}, secureHandler)
    
    mcp.Mount("/mcp")
    r.Run(":8080")
}

配置

服务器配置

config := &server.Config{
    Name:              "My API",
    Description:       "Description of my API",
    BaseURL:           "http://localhost:8080",
    IncludeOperations: []string{"GET_products", "POST_products"}, // Only include these
    ExcludeOperations: []string{"DELETE_products"},              // Exclude these
}

架构注册

使用 jsonschema 用于生成富模式的标签:

type User struct {
    ID       int    `json:"id" jsonschema:"readOnly"`
    Name     string `json:"name" jsonschema:"required,description=User's full name"`
    Email    string `json:"email" jsonschema:"required,format=email,description=Email address"`
    Age      int    `json:"age" jsonschema:"minimum=0,maximum=150,description=Age in years"`
    IsActive bool   `json:"is_active" jsonschema:"required,description=Account status"`
}

// Register for automatic schema generation
mcp.RegisterSchema("POST", "/users", nil, User{})

MCP客户端连接

与Cline(VS代码扩展)一起使用

添加到MCP设置中:

{
  "mcpServers": {
    "my-gin-api": {
      "command": "go",
      "args": ["run", "main.go"],
      "cwd": "/path/to/your/project",
      "env": {
        "API_TOKEN": "your-secret-token"
      }
    }
  }
}

远程连接

如果您的服务器已在运行:

{
  "mcpServers": {
    "my-gin-api": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:8080/mcp"]
    }
  }
}

api参考

核心类型

GinMCP

管理MCP功能的主服务器实例。

type GinMCP struct {
    // Internal fields
}

// Create new instance
func New(engine *gin.Engine, config *Config) *GinMCP

// Register HTTP route schema
func (m *GinMCP) RegisterSchema(method, path string, queryType, bodyType any)

// Register MCP-only tool
func (m *GinMCP) RegisterMCPTool(name, description string, schema any, 
    handler func(map[string]any) (any, error))

// Mount MCP endpoint
func (m *GinMCP) Mount(mountPath string)
Config

MCP服务器的配置选项。

type Config struct {
    Name              string   // Server name
    Description       string   // Server description
    BaseURL           string   // Base URL for HTTP requests
    IncludeOperations []string // Only include these operations
    ExcludeOperations []string // Exclude these operations
}
MCPTool

表示仅MCP工具。

type MCPTool struct {
    Name        string
    Description string
    Schema      any
    Handler     func(map[string]any) (any, error)
}

架构标签

使用这些 jsonschema 用于生成富模式的标签:

  • required -根据需要标记字段
  • description=text -添加字段描述
  • minimum=n -设置数字的最小值
  • maximum=n -设置数字的最大值
  • format=email -设置字符串格式
  • readOnly -将字段标记为只读
  • enum=val1,enum=val2 -定义允许的值

例子

完整的REST API示例

看 examples/simple/main.go 完整的实施方式包括:

  • 产品CRUD操作
  • 搜索和过滤
  • 分页和排序
  • 全面的模式定义
  • MCP集成

运行示例

cd examples/simple
go run main.go

服务器将于启动 http://localhost:8080 MCP端点位于 /mcp.

高级用法

自定义工具筛选

config := &server.Config{
    Name: "Filtered API",
    IncludeOperations: []string{
        "GET_products",
        "POST_products",
    },
}

复杂模式类型

type SearchParams struct {
    Query    string   `json:"query" jsonschema:"description=Search query"`
    Tags     []string `json:"tags" jsonschema:"description=Filter by tags"`
    MinPrice float64  `json:"min_price" jsonschema:"minimum=0,description=Minimum price"`
    MaxPrice float64  `json:"max_price" jsonschema:"minimum=0,description=Maximum price"`
    Page     int      `json:"page" jsonschema:"minimum=1,default=1,description=Page number"`
    Limit    int      `json:"limit" jsonschema:"minimum=1,maximum=100,default=10,description=Items per page"`
}

MCP工具中的错误处理

func myToolHandler(params map[string]any) (any, error) {
    value, ok := params["required_field"].(string)
    if !ok {
        return nil, fmt.Errorf("required_field must be a string")
    }
    
    if value == "" {
        return nil, fmt.Errorf("required_field cannot be empty")
    }
    
    // Process and return result
    return map[string]string{"result": value}, nil
}

故障排除

常见问题

  1. 工具未出现:确保 RegisterSchema 被调用之前 Mount
  2. 架构生成失败:检查您的结构是否使用导出的字段
  3. MCP连接失败:验证服务器是否正在运行以及端点是否可访问
  4. 环境变量不起作用:确保在MCP客户端配置中设置变量

调试模式

启用Gin调试模式以进行详细日志记录:

gin.SetMode(gin.DebugMode)

日志记录

图书馆使用 成就 用于日志记录。当Gin处于调试模式时,会自动记录调试信息。

贡献

  1. 分叉存储库
  2. 创建功能分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add some amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

运行测试

go test ./...

测试覆盖率

go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

致谢

相关项目

工具与能力

工具数量

0

资源数量

0

提示词数量

0

能力标签

API转换Go本地部署MCP协议Gin框架AI集成Go语言

支持客户端

Cline

数量来自来源目录的标注,具体工具清单以官方文档为准。

典型使用场景

多步任务编排

把拆解、检索、执行串成一条链,模型按步骤调用工具。

长期上下文

把会话、笔记和知识放到外部存储,换个会话还能接着做。

接自有流程

把内部系统和模型连起来,让助手调用已有的工作流。

选择建议

值得选的地方

  • 只提供 0 个工具,职责集中,接入后不容易误操作。
  • 公开说明写得比较完整,接入前能看清能力边界。

先想清楚的地方

  • 公开资料没有可直接复制的安装命令,第一次接入要自己找入口。
  • 需要自备访问 Token,没有凭据没法直接试。
  • 第三方目录整理,版本更新和行为细节以官方仓库为准。

更适合

  • 需要在AI代理场景里让模型直接调用外部能力的人。
  • 已经在用 Cline 的用户,接入路径最短。
  • 愿意照着官方文档一步步配环境的人。

不太适合

  • 暂时拿不到访问 Token的人。
  • 希望一条命令就装好、不想看文档的人。
  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

5 个同类
MCP Server工具数传输方式安装命令收录来源最后核验
MCP Gin

MCP World · 本页

0未说明未标注1 个2026-05-17
Everything Claude Code

MCP World

0stdio有1 个2026-05-17
Filesystem 560c4363

MCP World

13未说明未标注2 个2026-05-17
Time 7365cb6d

MCP.so

2SSE有2 个2026-05-17
Server Everything (everything)

MCP World

11stdio有1 个2026-05-17

按同分类和工具数量挑出最接近的几条,字段以各自详情页为准。

常见问题

5 条

MCP Gin 怎么安装?

公开目录没有给出可以直接复制的安装命令,需要按仓库 README里的步骤安装;装好后写进客户端的 MCP 配置再重启。

MCP Gin 怎么在 Claude Desktop、Cursor 里配置?

它是传输方式未标注,客户端配置里要写启动命令和参数,运行环境是 未标注;保存后完全退出客户端再打开,配置才会生效。

MCP Gin 收费吗?

本站只整理公开资料,不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

MCP Gin 需要 API Key 吗?

公开资料标注的认证方式是访问 Token,也就是要先拿到凭据才能连上;凭据只填在自己本地的配置里,不要写进公开仓库。

MCP Gin 支持哪些客户端?

公开资料标注支持 Cline;其他客户端只要能配置 MCP Server,也能用同样的命令或地址接入。

来源信息

继续浏览同类 MCP