使用说明
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)
|
基础设施
|
快速开始
先决条件
- 转到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 作为指导方针。
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'feat: add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
致谢
Built for the MCP community