AGENT SKILL
mcp-api-tool
Use this skill when adding or changing a ctl-api MCP tool (RegisterMCPTools, mcp_*.go handlers).
适用职业开发工程师
- License 许可
- AGPL-3.0
- 所属仓库
- nuonco/nuon
- 最近更新
- 2026-11-14
- Stars
- ★ 125
- Forks
- 14
01 前言 Front Matter
- name
- mcp-api-tool
- color
- blue
- model
- sonnet
- description
- Use this skill when adding or changing a ctl-api MCP tool (RegisterMCPTools, mcp_*.go handlers).
03 SKILL.md 正文
This skill enforces the ctl-api MCP tool registration pattern for the stateless Streamable HTTP server.
Steps
- Pick the domain service under
services/ctl-api/internal/app/<domain>/service/that already implementsapi.Serviceand is in FXgroup:"services". - Add
mcp_<name>.gowith an input struct (json+jsonschematags) and a handler matchingfunc(ctx, *mcp.CallToolRequest, in T) (*mcp.CallToolResult, any, error). - Read org/account/token role from
keys.*FromContext(ctx)— never Gin context. - Return payloads via
api.MCPJSONResult(...)(compact JSON text content). - Register the tool in that domain’s
mcp_register.gowithmcp.AddTool(server, api.MCPReadTool(...)|api.MCPWriteTool(...), handler)soTitleandAnnotationsare always set. - For mutating tools: prefix
DescriptionwithWRITE OPERATION:, useapi.MCPWriteTool(..., destructive, idempotent), and callrequire.Write(ctx)at the start of the handler. - For read tools scoped to an org: use
api.MCPReadTool(...)and callrequire.Read(ctx)at the start of the handler. - Prefer trimmed response shapes over full GORM models when the payload would be large for LLM context. Format times with
api.MCPTime(UTC RFC3339…Z) — do not serializetime.Time, add relative age strings, or localize on the server. - List tools must use
api.MCPListPage(default 20, max 100),Limit(limit+1), andapi.MCPClipList. Returnhas_more/next_offset. Appendapi.MCPListToolHintto the description. Do not loop until the full set is loaded. - No new MCP-specific FX wiring —
RegisterMCPToolsis discovered via type assert onapi.MCPService. - Update the tool tables in
docs/guides/agents/tools.mdxandbins/cli/cmd/agents_context.md. Add a prompt todocs/guides/agents/sample-queries.mdxif the tool is part of a user-facing flow.
Reference examples: apps/service/mcp_list_apps.go, apps/service/mcp_register.go, installs/service/mcp_approve_step.go.
Anti-Patterns
- Do not implement tools only in the CLI proxy — tools live in ctl-api; the CLI forwards them.
- Do not skip
require.Writeon write tools — description prefix / annotations alone are not enough. - Do not skip
require.Readon org-scoped read tools. - Do not register tools with bare
&mcp.Tool{Name, Description}— always useMCPReadTool/MCPWriteTool. - Do not key request state on
Mcp-Session-Id— the server isStateless: true; use bearer token + per-requestX-Nuon-Org-ID. Do not store an org on the token. - Do not print to stdout from tool handlers — MCP protocol owns the stream.
- Do not serialize
time.Time, add*_relativeage fields, or render local timestamps — useMCPTime; agents convert UTC to local. - Do not
Finda collection withoutapi.MCPListPage/Limit(limit+1)/MCPClipList. Returnhas_moreandnext_offset; do not loop until the full set is loaded.