MCP 助手
- 作者仓库星标 0
- 作者更新于 实时读取
- 作者仓库 skills-registry
- 领域
- AI 智能
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 需手动接入
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- Windows · Docker
- 底层运行要求
- Docker
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 读取环境变量
- 网络行为
- 允许外网请求
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: mcp-server-go
description: Authoritative reference for building MCP (Model Context Protocol) servers in Go using the offici…
category: AI 智能
runtime: Docker
---
# mcp-server-go 输出预览
## PART A: 任务判断
- 适用问题:提示词、Agent 工作流、模型评估或自动化推理。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“When to load / The four facts that change everything / 1. Use the official Go SDK”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于提示词、Agent 工作流、模型评估或自动化推理,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“When to load / The four facts that change everything / 1. Use the official Go SDK”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、读取环境变量、会按任务需要访问外部网络、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令、读取环境变量;会按任务需要访问外部网络;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文没有稳定的斜杠命令要求。安装验证后通常全局生效,直接在对话里点名这个 Skill 并描述任务即可。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令、读取环境变量。
先用一个小任务确认它会围绕“When to load / The four facts that change everything / 1. Use the official Go SDK”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: mcp-server-go
description: Authoritative reference for building MCP (Model Context Protocol) servers in Go using the offici…
category: AI 智能
source: tomevault-io/skills-registry
---
# mcp-server-go
## 什么时候使用
- 把 AI / Agent方向的常用动作沉淀成 Agent 可调用的技能 适合处理AI Agent、提示词、模型评估与自动化推理,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查…
- 面向提示词、Agent 工作流、模型评估或自动化推理,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「When to load / The four facts that change everything / 1. Use the official Go SDK」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令、读取环境变量;会按任务需要访问外部网络;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "mcp-server-go" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> When to load / The four facts that change everything / 1. Use the official Go SDK
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Docker | 读取文件、写入/修改文件、执行终端命令、读取环境变量 | 会按任务需要访问外部网络
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} mcp-server-go — building MCP servers in Go
This skill answers the questions that block productive MCP server work in Go. Verified against the 2025-11-25 spec and the official modelcontextprotocol/go-sdk v1.6.0 (released 2026-05-08).
When to load
- Editing or building Go code in
projects/pg-ai-stewards/cmd/stewards-mcp/ - Adding a new MCP tool to an existing server
- Wiring up a new MCP server to Claude Code or another MCP client
- Hitting "tool not found" / "JSON-RPC error" / silent connection failures
- Reading another project's MCP server code to understand its shape
The four facts that change everything
1. Use the official Go SDK
github.com/modelcontextprotocol/go-sdk — maintained jointly by Anthropic and Google. v1.6.0 as of 2026-05-08. Schema reflection from struct tags, transport handling, capability negotiation, error wrapping all built in. Going from scratch in Go is ~250 lines for a tools-only stdio server; using the SDK is ~30. Use the SDK.
import "github.com/modelcontextprotocol/go-sdk/mcp"
2. stdio transport is newline-delimited JSON
NOT LSP-style with Content-Length headers. One JSON-RPC message per line, embedded newlines forbidden inside messages. The SDK handles this for you via mcp.StdioTransport{}. If you ever roll your own:
- Read stdin line by line
- Write each response as one line to stdout
- Never write to stdout from anywhere else — that corrupts the protocol stream
- stderr is for logs
3. The initialize handshake is mandatory and ordered
Three steps, in order, before any tool call:
- Client → server:
initializerequest (protocol version, capabilities) - Server → client:
initializeresponse (protocol version, server capabilities, serverInfo) - Client → server:
notifications/initialized(one-way, no response)
Only after step 3 may the client send tools/list or tools/call. The SDK enforces this. If you hand-roll, do not let tools/list succeed before initialized arrives — strict clients reject early-tool servers.
4. Two error kinds, don't conflate them
- JSON-RPC errors (code
-32602etc.): protocol-level. "Unknown tool", "malformed params". Returned via the JSON-RPCerrorobject. - Tool execution errors (
isError: trueinsideresult): runtime. "DB connection failed", "Tool returned no results". The model SEES these and can self-correct.
Mixing them up means the model treats DB outages as unrecoverable system errors. Use mcp.NewToolResultError(...) for the latter.
Minimum viable server (uses official SDK)
package main
import (
"context"
"log"
"os"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
// Tool input. SDK reflects struct tags into JSON Schema 2020-12.
type SearchInput struct {
Query string `json:"query" jsonschema:"description=topic to search"`
Limit int `json:"limit,omitempty" jsonschema:"description=max results,minimum=1,maximum=100"`
}
// Tool output. SDK reflects struct tags into outputSchema if you declare it.
type SearchOutput struct {
Results []map[string]any `json:"results"`
}
// Tool handler. Three returns: optional pre-built result, structured output,
// optional error. SDK builds the standard {content, structuredContent, isError}
// shape automatically.
func studySearch(
ctx context.Context,
req *mcp.CallToolRequest,
in SearchInput,
) (*mcp.CallToolResult, SearchOutput, error) {
// ... query DB, build results ...
return nil, SearchOutput{Results: []map[string]any{}}, nil
}
func main() {
// CRITICAL: pin logger to stderr. Anything to stdout corrupts the protocol.
logger := log.New(os.Stderr, "stewards-mcp: ", log.LstdFlags)
s := mcp.NewServer(&mcp.Implementation{
Name: "pg-ai-stewards",
Version: "0.1.0",
}, nil)
mcp.AddTool(s, &mcp.Tool{
Name: "study_search",
Description: "Find studies in the substrate by topic.",
}, studySearch)
if err := s.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
logger.Fatalf("server.Run: %v", err)
}
}
That's a fully spec-compliant tools-only MCP server. Build, register in .mcp.json, restart Claude Code session.
Tool registration patterns
Tool name regex: [A-Za-z0-9_.-]{1,128}. Slashes and spaces are silently rejected by some clients. Pick a convention (study_search, study.search, or study-search) and stick to it.
Input schema is auto-generated from the struct. Use json:"..." tags and jsonschema:"..." for descriptions, ranges, enums.
Output schema is optional. If you declare it, you MUST return structuredContent matching it. Strict clients reject mismatches. Either:
- Declare and validate (best for typed APIs)
- Omit and rely on the auto-generated text block (best for free-form results)
Tool list changes can be announced at runtime via notifications/tools/list_changed if your server has dynamic tool sets. For static tool sets, declare capabilities.tools.listChanged: false (the SDK default — don't override unless needed).
Claude Code integration
Three scopes for registering an MCP server:
| Scope | File | Use for |
|---|---|---|
| Project | .mcp.json (repo root) |
Servers that ship with the project, work for all teammates |
| Local user | ~/.claude.json |
Personal experiments, tools |
| Global user | ~/.claude/settings.json (rarely used) |
System-wide tools |
For project sidecars (the case here), use .mcp.json at repo root:
{
"mcpServers": {
"pg-ai-stewards": {
"type": "stdio",
"command": "${WORKSPACE_FOLDER}/projects/pg-ai-stewards/bin/stewards-mcp.exe",
"args": ["--dsn", "${STEWARDS_DSN:-postgres://stewards:stewards@localhost:55433/stewards?sslmode=disable}"],
"env": {}
}
}
}
Env-var expansion: ${VAR} and ${VAR:-default}. Project-scoped servers prompt for approval on first run; clear with claude mcp reset-project-choices if testing a config change.
Restart the Claude Code session after editing .mcp.json. The MCP client only re-reads the config at session start. The skill listing in subsequent turns will then show the new tools.
Gotchas (recurring failures)
stderr discipline. Any
fmt.Printlnor default-logger call writes to stdout and corrupts the protocol. Pin all logging toos.Stderr. Audit dependencies — pgx's default logger writes to stdout in some configurations.Don't respond to notifications.
notifications/initializedandnotifications/cancelledarrive withoutid. Sending a response is a protocol violation. The SDK handles this; rolled-your-own constantly breaks it.Tool name characters. Stick to
[A-Za-z0-9_.-]. Underscores are safest.isError: truevs JSON-RPC error. Tool-execution failures useisError: trueso the model can react. JSON-RPC errors are for protocol violations.mcp.NewToolResultError(...)is the SDK helper.Buffered stdout. Go's stdout is fully buffered when not connected to a TTY (Claude Code spawns you as a pipe). The SDK flushes after each message. If you write a custom transport, wrap stdout in a
bufio.Writerand flush every line.Initialize before tools. Do not let
tools/listsucceed beforenotifications/initializedarrives. Strict clients enforce ordering.outputSchemais a contract. If declared, validate matches before sending. Either be rigorous or omit the schema.First-run approval dialog. Project-scoped MCP servers prompt the user for approval on first invocation. Document this for teammates so they don't think the server is broken.
pgx connection lifecycle. Use
pgxpool.New(ctx, dsn)for connection pooling. Close the pool ons.Run()exit. Don't share*pgx.Connacross goroutines — use the pool.Context cancellation. The SDK passes
context.Contextthrough to handlers. Honor it. If a tool call is mid-flight and the client cancels, abort cleanly viactx.Done().
Real-world references
When in doubt, look at how production Go MCP servers are structured:
- subnetmarco/pgmcp — Postgres MCP using the official Go SDK. Closest analog to what we're building. Has CI, Docker, schema fixtures.
- mark3labs/mcp-go examples/ — even if you use the official SDK, the example servers are clean reference implementations of the protocol flow.
- modelcontextprotocol/go-sdk examples/ — the official SDK's bundled examples.
Project-specific (pg-ai-stewards)
Binary location: projects/pg-ai-stewards/cmd/stewards-mcp/main.go. Compiled to projects/pg-ai-stewards/bin/stewards-mcp.exe on Windows.
Connection string: STEWARDS_DSN env var, defaulting to postgres://stewards:stewards@localhost:55433/stewards?sslmode=disable (the docker-compose port mapping).
First tools to register (Phase 3e.1):
study_search— wrapsstewards.study_search_text(query, kinds, limit), returns matched study slugs + titles + scoresstudy_get— wrapsstewards.study_get(slug), returns body + frontmatter + citations
Future tools (Phase 3e.2-3e.5): gospel_passthrough, stewards_brain, stewards_work_item, gospel_search, gospel_get (the latter two via outbound MCP-client to gospel-engine-v2).
Findings doc: projects/pg-ai-stewards/docs/3e-mcp-findings.md (created when 3e.1 ships).
Source: cpuchip/scripture-study — distributed by TomeVault.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核