brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
scaffold-mcp-serverScaffold a new MCP server from tool specifications using the official SDK (TypeScript or Python), including transport configuration, tool handlers, and test harness. Use when you have a tool specification and need a working server, when starting a new MCP server project and want correct structure from the start, when migrating an existing tool integration t…
Independent GitHub snapshot · Automated classification · Original documentation governs
從工譜生完備可行 MCP 服項,用官 MCP SDK(TypeScript 或 Python)。
typescript 或 python)stdio 或 sse)none、bearer-token、api-key)true/false,默 false)1.1. 按項境擇行語:
1.2. 擇傳:
1.3. 定認需:
得:明語、傳、認擇文錄。
敗:需含糊→默 TypeScript + stdio + 無認以最快達工服。
2.1. 建項目啟:
TypeScript:
mkdir -p $PROJECT_NAME && cd $PROJECT_NAME
npm init -y
npm install @modelcontextprotocol/sdk zod
npm install -D typescript @types/node tsx
npx tsc --init --target ES2022 --module nodenext --moduleResolution nodenext --outDir dist
Python:
mkdir -p $PROJECT_NAME && cd $PROJECT_NAME
python -m venv .venv
source .venv/bin/activate
pip install mcp pydantic
2.2. 建標目結構:
$PROJECT_NAME/
├── src/
│ ├── index.ts|main.py
│ ├── tools/
│ │ ├── index.ts|__init__.py
│ │ └── [category].ts|.py
│ └── utils/
│ └── validation.ts|.py
├── test/
│ ├── harness.ts|.py
│ └── tools/
│ └── [category].test.ts|.py
├── package.json|pyproject.toml
├── tsconfig.json
├── Dockerfile
└── README.md
2.3. 加 npm bin(TypeScript)或 Python 入點:
TypeScript package.json:
{
"name": "$PACKAGE_NAME",
"version": "1.0.0",
"type": "module",
"bin": { "$PACKAGE_NAME": "./dist/index.js" },
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "tsx src/index.ts",
"test": "tsx test/harness.ts"
}
}
得:可建之項骨含諸依裝。
敗:npm/pip 裝敗→查網與譜達。TypeScript 需 Node.js ≥ 18。Python 需 ≥ 3.10。
3.1. 析譜為各工生處:
TypeScript 處板:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
export function registerTools(server: McpServer): void {
server.tool(
"tool_name",
"Tool description from spec",
{
param1: z.string().describe("Parameter description"),
param2: z.number().optional().default(10).describe("Optional param"),
},
async ({ param1, param2 }) => {
try {
// TODO: Implement tool logic
const result = await performAction(param1, param2);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
};
} catch (error) {
return {
content: [{ type: "text", text: `Error: ${(error as Error).message}` }],
isError: true,
};
}
}
);
}
Python 處板:
from mcp.server import Server
from mcp.types import Tool, TextContent
from pydantic import BaseModel
class ToolNameParams(BaseModel):
param1: str
param2: int = 10
async def handle_tool_name(params: ToolNameParams) -> list[TextContent]:
try:
result = await perform_action(params.param1, params.param2)
return [TextContent(type="text", text=json.dumps(result, indent=2))]
except Exception as e:
return [TextContent(type="text", text=f"Error: {e}")]
3.2. 為譜各類生一處檔。
3.3. 加入驗超於型查:
3.4. 為諸期敗模加結構誤應。
得:各類有處檔含型參與誤理。
敗:譜含模糊型→默 string 加 TODO 註以人精。
4.1. 建服入點含所擇傳:
stdio(TypeScript):
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { registerTools } from "./tools/index.js";
const server = new McpServer({
name: "$PACKAGE_NAME",
version: "1.0.0",
});
registerTools(server);
const transport = new StdioServerTransport();
await server.connect(transport);
SSE(TypeScript):
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
import { registerTools } from "./tools/index.js";
const server = new McpServer({
name: "$PACKAGE_NAME",
version: "1.0.0",
});
registerTools(server);
const transport = new SSEServerTransport("/messages", response);
await server.connect(transport);
4.2. 認需→加中介:
Authorization 頭X-API-Key 頭4.3. stdio 服加首行以可執:
#!/usr/bin/env node
得:可行入點啟 MCP 服於配傳。
敗:SDK 本不合入路→查 @modelcontextprotocol/sdk 本、調入。SDK 本間重組路。
5.1. 築測台驗諸工:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
async function runTests(): Promise<void> {
const server = createServer();
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await server.connect(serverTransport);
const client = new Client({ name: "test-client", version: "1.0.0" });
await client.connect(clientTransport);
// Test: tools/list returns all expected tools
const tools = await client.listTools();
console.assert(tools.tools.length === EXPECTED_TOOL_COUNT);
// Test: each tool with valid input
for (const tool of tools.tools) {
const result = await client.callTool({
name: tool.name,
arguments: getTestInput(tool.name),
});
console.assert(!result.isError, `${tool.name} failed`);
}
// Test: each tool with invalid input returns isError
for (const tool of tools.tools) {
const result = await client.callTool({
name: tool.name,
arguments: getInvalidInput(tool.name),
});
console.assert(result.isError, `${tool.name} should reject invalid input`);
}
console.log("All tests passed");
}
5.2. 為各工建測夾:有效入、無效入、邊例。
5.3. 加 test 本至 package.json 或 pyproject.toml。
得:測台行諸工於有效與無效入。
敗:InMemoryTransport SDK 本無→退至子進程啟服經 stdio 管通。
6.1. 生 README.md 含:
6.2. 生 Claude Code 註命:
# stdio transport
claude mcp add $PACKAGE_NAME stdio "node" "dist/index.js"
# SSE transport
claude mcp add $PACKAGE_NAME -e API_KEY=your_key -- mcp-remote http://localhost:3000/mcp
6.3. 生 Claude Desktop 配片:
{
"mcpServers": {
"$PACKAGE_NAME": {
"command": "node",
"args": ["path/to/dist/index.js"]
}
}
}
6.4. Docker 求→生 Dockerfile:
FROM node:20-slim AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-slim
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json .
ENTRYPOINT ["node", "dist/index.js"]
得:完文與配檔可即用。
敗:生 README 含占位→項內搜實值代。Docker 建敗→驗基像合 Node.js/Python 本。
npm run build 等)tools/list JSON-RPCclaude mcp add 可連@modelcontextprotocol/sdk 本間重組出。必查裝本實出路#!/usr/bin/env nodeasync。同步操阻服諸工type: "module":MCP SDK 用 ESM 入。缺則 Node.js 視為 CommonJS、入敗console.log 壞流。用 console.error 或檔記analyze-codebase-for-mcpbuild-custom-mcp-serverconfigure-mcp-servertroubleshoot-mcp-connectioncontainerize-mcp-server