MCP服务器模板

一个基于Go语言实现的完整、生产就绪的MCP服务器模板,支持多种传输协议和开发工具集成。

  • by NP-compete
  • Go
  • 本地部署
  • 5 星标
  • 更新于
在 GitHub 查看 NP-compete/gomcp

使用说明

gomcp

Production-ready Model Context Protocol (MCP) server template in Go

Features | Quick Start | Use as Template | Documentation | Contributing


概述

gomcp 是一个完整的、可用于生产的MCP服务器模板,使用Go和 官方MCP Go SDK。它实现了完整 MCP 2025-06-18规范 并且被设计为构建自己的MCP服务器的起点。

为什么是gomcp?

  • 完成实施 -所有12个MCP功能均已完全实现
  • 生产就绪 -Docker支持、CI/CD、安全最佳实践
  • 证据充分的 -全面的文档、示例和定制指南
  • 易于定制 -简洁的架构、模块化设计、广泛的评论
  • 多个传输 -用于Cursor IDE的HTTP/SSE,用于Claude Desktop的stdio

特性

MCP功能(12/12)

功能 状态 描述
工具 是 4个具有结构化输出的示例工具
提示 是 3个可重复使用的提示模板
资源 是 6个静态/动态资源
根 是 文件系统根定义
完成 是 带JSON模式的结构化输出
日志记录 是 服务器到客户端通知(8级)
分页 是 基于光标的分页
采样 是 服务器到客户端的LLM请求
引用 是 服务器到用户的数据请求
进度 是 实时进度通知
取消 是 请求取消支持
Ping 是 健康检查

基础设施

特性 描述
多运输 HTTP/SSE+stdio支持
光标兼容 一流的Cursor IDE支持
克劳德桌面版 本地使用的stdio传输
Docker就绪 包含多级Dockerfile
CI/CD GitHub操作工作流
热重载 空气开发模式
OAuth支持 身份验证就绪
指标 内置监控端点
安全 非根容器,SSL/TLS

快速开始

先决条件

  • 转到1.24+
  • (可选)Docker/Podman

安装

# Clone the repository
git clone https://github.com/NP-compete/gomcp.git
cd gomcp

# Download dependencies
go mod download

# Build and run
make run

运行服务器

For Cursor IDE (HTTP/SSE)
make cursor
# Server runs on http://localhost:8081/mcp/sse

配置 ~/.cursor/mcp.json:

{
  "mcpServers": {
    "gomcp": {
      "url": "http://localhost:8081/mcp/sse"
    }
  }
}

重新启动Cursor IDE以进行连接。

For Claude Desktop (stdio)
# Build the binary
make build-prod

# Configure Claude Desktop
# ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
# %APPDATA%\Claude\claude_desktop_config.json (Windows)
{
  "mcpServers": {
    "gomcp": {
      "command": "/absolute/path/to/gomcp/bin/gomcp",
      "args": [],
      "env": {
        "MCP_TRANSPORT_PROTOCOL": "stdio"
      }
    }
  }
}

重新启动Claude Desktop以进行连接。

With Docker
# Build and run with Docker
make docker-build
make docker-run

# Or with Docker Compose
docker-compose up -d

用作模板

此存储库旨在用作您自己的MCP服务器的模板。

选项1:GitHub模板(推荐)

点击 “使用此模板” GitHub上的按钮创建新的存储库。

选项2:手动克隆

# Clone and remove git history
git clone https://github.com/NP-compete/gomcp.git my-mcp-server
cd my-mcp-server
rm -rf .git
git init

# Update module name
# Edit go.mod: module github.com/YOUR_USERNAME/my-mcp-server
# Then update all imports

定制指南

看 docs/CUSTOMIZATION.md 有关以下内容的详细说明:

  • 添加自己的工具、提示和资源
  • 配置身份验证
  • 自定义Docker设置
  • 为您的存储库设置CI/CD

项目结构

gomcp/
├── cmd/server/          # Application entry point
├── internal/
│   ├── api/            # HTTP handlers & routing
│   ├── completion/     # Structured outputs
│   ├── config/         # Configuration management
│   ├── logging/        # Server-to-client logs
│   ├── mcp/            # MCP server logic
│   ├── pagination/     # Cursor-based pagination
│   ├── prompts/        # Prompt implementations
│   ├── resources/      # Resource implementations
│   ├── roots/          # Filesystem roots
│   └── tools/          # Tool implementations
├── pkg/mcpprotocol/    # MCP protocol types
├── test/               # Integration tests
├── docs/               # Documentation
├── scripts/            # Utility scripts
├── .github/            # GitHub Actions & templates
├── Dockerfile          # Container build
├── docker-compose.yml  # Local development
└── Makefile           # Build commands

配置

变量 默认值 描述
MCP_TRANSPORT_PROTOCOL http 运输: stdio, http, sse
MCP_PORT 8081 服务器端口
CURSOR_COMPATIBLE_SSE true 启用光标兼容性
ENABLE_AUTH true 启用OAuth身份验证
LOG_LEVEL INFO 日志级别

看 .env.示例 对于所有选项。

测试

# Run all tests
make test

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

# Run linter
make lint

# Run security scan
make security-scan

文档

文档 描述
建筑 系统设计和组件概述
定制 自定义模板指南
贡献 如何做出贡献
安全 安全策略

外部资源

贡献

我们欢迎捐款!请参阅 贡献.md 作为指导方针。

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

许可证

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

致谢


Built for the MCP community

Star us on GitHub | Report Bug | Discussions