用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/vinilana/dotcontext --skill mcp-tool-design命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| type | skill |
| name | MCP Tool Design |
| description | Design MCP tools and gateway interfaces for the dotcontext server |
| skillSlug | api-design |
| phases | ["P","R"] |
| generated | "2026-03-18T00:00:00.000Z" |
| status | filled |
| scaffoldVersion | 2.0.0 |
Guidance for designing and extending MCP (Model Context Protocol) tools exposed by AIContextMCPServer in src/services/mcp/mcpServer.ts.
context://, file://, workflow://)src/services/mcp/gateway/The MCP server follows a consolidated gateway pattern to minimize cognitive load for AI agents:
AIContextMCPServer (mcpServer.ts)
registerGatewayTools()
-> explore (read, list, analyze, search, getStructure)
-> context (check, init, fill, fillSingle, listToFill, getMap, buildSemantic, scaffoldPlan)
-> sync (exportRules, exportDocs, exportAgents, exportContext, exportSkills, reverseSync, importDocs, importAgents, importSkills)
-> plan (link, getLinked, getDetails, getForPhase, updatePhase, recordDecision, updateStep, getStatus, syncMarkdown, commitPhase)
-> agent (discover, getInfo, orchestrate, getSequence, getDocs, getPhaseDocs, listTypes)
-> skill (list, getContent, getForPhase, scaffold, export, fill)
-> workflow-init / workflow-status / workflow-advance / workflow-manage
Each gateway dispatches to a handler in src/services/mcp/gateway/<name>.ts. The handler receives typed params and an options object with repoPath.
z.enum([...]) and extend the handler switch.workflow-* was split out for clarity).All MCP tool inputs use Zod v4 schemas (imported from zod). Follow the existing pattern:
inputSchema: {
action: z.enum(['existingAction', 'newAction'])
.describe('Action to perform'),
newParam: z.string().optional()
.describe('(newAction) What this param does'),
}
Key conventions:
.describe() with the action prefix in parentheses: (actionName)z.enum() for constrained values, z.array(z.string()) for lists.optional() since different actions use different params../../workflow (e.g., PREVC_ROLES, AGENT_TYPES)Add a new file in src/services/mcp/gateway/ or extend an existing one:
// src/services/mcp/gateway/myGateway.ts
import { createJsonResponse, createErrorResponse, type MCPToolResponse } from './response';
export type MyAction = 'doThing' | 'doOther';
export interface MyParams {
action: MyAction;
repoPath?: string;
// action-specific params
}
export interface MyOptions {
repoPath: string;
}
export async function handleMy(params: MyParams, options: MyOptions): Promise<MCPToolResponse> {
switch (params.action) {
case 'doThing':
return createJsonResponse({ success: true, message: 'Done' });
default:
return createErrorResponse(`Unknown action: ${params.action}`);
}
}
Use the three helpers from src/services/mcp/gateway/response.ts:
createJsonResponse(data) -- structured JSON for programmatic consumptioncreateErrorResponse(message) -- sets isError: truecreateTextResponse(text) -- plain text for human-readable outputAll responses conform to MCPToolResponse with content: [{ type: 'text', text }].
Register the tool in registerGatewayTools() using the wrap() helper for automatic action logging:
this.server.registerTool('my-tool', {
description: `Description with action list...`,
inputSchema: { /* Zod schemas */ }
}, wrap('my-tool', async (params): Promise<MCPToolResponse> => {
return handleMy(params as MyParams, { repoPath: this.getRepoPath() });
}));
Add your handler, types, and params to the re-export barrel in src/services/mcp/gatewayTools.ts and src/services/mcp/gateway/index.ts.
Write tests in src/services/mcp/ following the pattern in mcpServer.test.ts. Since MCP tools require stdio transport, test the handler functions directly:
import { handleMy } from './gateway/myGateway';
it('should handle doThing action', async () => {
const result = await handleMy(
{ action: 'doThing' },
{ repoPath: tempDir }
);
const payload = JSON.parse(result.content[0].text);
expect(payload.success).toBe(true);
});
getStatus, buildSemantic, exportRules).describe() annotations with action prefixMCPToolResponse via response helpersrepoPath resolution uses this.getRepoPath(params.repoPath) for cachingwrap() helperprocess.cwd() directly in handlers; always use the repoPath from options.optional() and validate inside the handlercreateErrorResponse() for consistent error shapeprocess.stderr.write() to avoid corrupting the MCP protocolImplement or review bounded MCP inputs and responses. Use for gateway response helpers, MCP Zod schemas, list actions, cursor pagination, maxEvents, JSON serialization, audit logging, response metadata, artifact exports, or payload-size and client-compatibility changes.
Implement or review child-process execution with bounded stdout and stderr memory. Use for Node spawn wrappers, sensors, test runners, acceptance commands, timeout handling, output tails, truncation, or any change that captures subprocess output in the dotcontext harness.
Design, implement, or review bounded cache and persistent-index lifecycle. Use for ContextCache, SemanticContextBuilder, tree-sitter analysis cache, MCP session cache, hook host-session bindings, checkpoints, TTL, LRU, byte budgets, invalidation, cleanup timers, disposal, migration, or runtime retention configuration.
基于 SOC 职业分类