scaffold-mcp-server
정보
이 스킬은 공식 TypeScript 또는 Python SDK를 사용하여 도구 명세로부터 완전히 실행 가능한 MCP 서버 프로젝트를 생성합니다. 전송 구성, 도구 핸들러, 테스트 하네스를 포함한 적절한 프로젝트 구조를 만들어 즉시 사용할 수 있도록 합니다. 새로운 MCP 서버를 시작할 때, 기존 도구를 MCP로 마이그레이션할 때, 또는 Claude Code로 테스트하기 위한 도구 인터페이스 프로토타이핑 시에 활용하세요.
빠른 설치
Claude Code
추천npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/scaffold-mcp-serverClaude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요
문서
MCP-Server aufsetzen
Generieren a complete, runnable MCP server project from a tool specification document, using the official MCP SDK for TypeScript or Python.
Wann verwenden
- You have a tool specification (from
analyze-codebase-for-mcpor written manuell) and need a working server - Starting a new MCP server project and want correct structure from the start
- Migrating an existing tool integration to the MCP protocol
- Prototyping a tool surface to test with Claude Code vor full implementation
- Need both der Server scaffold and a test harness for CI
Eingaben
- Erforderlich: Tool specification document (YAML or JSON with tool names, parameters, return types)
- Erforderlich: Target language (
typescriptorpython) - Erforderlich: Transport type (
stdioorsse) - Optional: Output directory (default: current directory)
- Optional: Package name and version
- Optional: Authentication method (
none,bearer-token,api-key) - Optional: Docker packaging (
trueorfalse, default:false)
Vorgehensweise
Schritt 1: Auswaehlen SDK Language and Transport
1.1. Waehlen the implementation language basierend auf project context:
- TypeScript: Best for Node.js ecosystems, web-adjacent tools, JSON-heavy workloads
- Python: Best for data science, ML, and scientific computing tool surfaces
1.2. Waehlen the transport mechanism:
- stdio: Default for local tool execution. Claude Code launches der Server as a subprocess.
- SSE (Server-Sent Events): For remote/shared servers. Requires HTTP hosting.
1.3. Bestimmen Authentifizierung requirements:
- none: Local stdio servers (process-level trust)
- bearer-token: Remote SSE servers with static tokens
- api-key: Remote servers with per-client keys
Erwartet: Clear language, transport, and auth choices documented.
Bei Fehler: If requirements are ambiguous, default to TypeScript + stdio + no auth for fastest time-to-working-server.
Schritt 2: Initialize Project Structure
2.1. Erstellen das Projekt directory and initialize:
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. Erstellen the standard Verzeichnisstruktur:
$PROJECT_NAME/
├── src/
│ ├── index.ts|main.py # Server entry point
│ ├── tools/ # One file per tool category
│ │ ├── index.ts|__init__.py
│ │ └── [category].ts|.py
│ └── utils/ # Shared utilities
│ └── validation.ts|.py
├── test/
│ ├── harness.ts|.py # MCP test harness
│ └── tools/
│ └── [category].test.ts|.py
├── package.json|pyproject.toml
├── tsconfig.json # TypeScript only
├── Dockerfile # If Docker requested
└── README.md
2.3. Hinzufuegen a bin entry for npm (TypeScript) or entry point for 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"
}
}
Erwartet: A buildable project skeleton with all Abhaengigkeiten installed.
Bei Fehler: If npm/pip install fails, check network connectivity and registry access. For TypeScript, ensure Node.js >= 18. For Python, ensure Python >= 3.10.
Schritt 3: Implementieren Tool Handlers from Spec
3.1. Parsen the tool specification document and fuer jede tool, generate a handler:
TypeScript handler template:
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 handler template:
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. Generieren one handler file per tool category from the specification.
3.3. Hinzufuegen input validation beyond type checking:
- String length limits
- Numeric range bounds
- Enum value constraints
- Required field enforcement
3.4. Hinzufuegen structured error responses for all anticipated failure modes.
Erwartet: A handler file per category with typed parameters and Fehlerbehandlung.
Bei Fehler: If the spec contains ambiguous types, default to string and add a TODO comment for manual refinement.
Schritt 4: Konfigurieren Transport
4.1. Erstellen der Server entry point with the chosen transport:
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. If Authentifizierung ist erforderlich, add middleware:
- Bearer token: validate
Authorizationheader - API key: validate
X-API-Keyheader
4.3. Hinzufuegen a shebang line for stdio servers to enable direct execution:
#!/usr/bin/env node
Erwartet: A working entry point that starts the MCP server on the configured transport.
Bei Fehler: If the SDK version nicht match the import paths, check the @modelcontextprotocol/sdk version and adjust imports. The SDK restructured paths zwischen versions.
Schritt 5: Erstellen Testen Harness
5.1. Erstellen a test harness that validates every tool:
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. Erstellen test fixtures fuer jede tool: valid inputs, invalid inputs, and Grenzfaelle.
5.3. Hinzufuegen a test script to package.json or pyproject.toml.
Erwartet: A test harness that exercises every tool with both valid and invalid inputs.
Bei Fehler: If InMemoryTransport ist nicht available in the SDK version, fall back to spawning der Server as a subprocess and communicating via stdio pipes.
Schritt 6: Generieren Documentation and Configuration
6.1. Generieren a README.md with:
- Project description
- Installation instructions
- Claude Code configuration command
- Claude Desktop JSON configuration snippet
- Tool listing with descriptions and parameter schemas
- Development and testing instructions
6.2. Generieren Claude Code registration command:
# 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. Generieren Claude Desktop configuration snippet:
{
"mcpServers": {
"$PACKAGE_NAME": {
"command": "node",
"args": ["path/to/dist/index.js"]
}
}
}
6.4. If Docker was requested, generate a 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"]
Erwartet: Abschliessen documentation and configuration files for immediate use.
Bei Fehler: If the generated README has placeholder values, search das Projekt for actual values to substitute. If Docker build fails, verify the base image matches the Node.js/Python version used.
Validierung
- Project builds ohne errors (
npm run buildor equivalent) - Server starts and responds to
tools/listJSON-RPC request - Every tool from the specification is registered and discoverable
- Testen harness passes for all tools with valid inputs
- Testen harness confirms error responses for invalid inputs
- Claude Code can connect via
claude mcp addcommand - README includes working installation and configuration instructions
- All generated code passes linting (if configured)
Haeufige Stolperfallen
- SDK import path changes: The
@modelcontextprotocol/sdkpackage restructured its exports zwischen versions. Always check the installed version's actual export paths. - Forgetting the shebang: stdio servers invoked directly need
#!/usr/bin/env nodeas the first line to be executable. - Blocking the event loop: Tool handlers in TypeScript muss
async. Synchronous operations block all other tool calls on der Server. - Missing
type: "module"in package.json: The MCP SDK uses ESM imports. Without"type": "module", Node.js treats files as CommonJS and imports fail. - Zod schema drift: If the tool spec evolves but Zod schemas sind nicht updated, validation mismatches cause silent failures. Generieren schemas from a single source of truth.
- stdout pollution: stdio transport uses stdout for JSON-RPC. Any
console.login tool handlers corrupts the protocol stream. Useconsole.erroror a file logger stattdessen.
Verwandte Skills
analyze-codebase-for-mcp- generate the tool specification this skill consumesbuild-custom-mcp-server- manual server implementation for complex casesconfigure-mcp-server- connect the scaffolded server to Claude Code/Desktoptroubleshoot-mcp-connection- debug connectivity issues nach deploymentcontainerize-mcp-server- package der Server in Docker for distribution
GitHub 저장소
연관 스킬
evaluating-llms-harness
테스팅이 Claude Skill은 MMLU, GSM8K를 포함한 60개 이상의 표준화된 학술 과제에서 LLM 성능을 벤치마크하기 위해 lm-evaluation-harness를 실행합니다. 개발자들이 모델 품질을 비교하고, 학습 진행 상황을 추적하거나 학술 결과를 보고할 수 있도록 설계되었습니다. 이 도구는 HuggingFace와 vLLM 모델을 포함한 다양한 백엔드를 지원합니다.
cloudflare-cron-triggers
테스팅이 스킬은 cron 표현식을 사용하여 Worker를 스케줄링하기 위한 Cloudflare Cron Triggers 구현에 관한 포괄적인 지식을 제공합니다. 주기적 작업, 유지보수 작업, 자동화된 워크플로우 설정 방법을 다루며, 잘못된 cron 표현식이나 시간대 문제 같은 일반적인 이슈들을 해결하는 방법을 포함합니다. 개발자들은 이를 통해 스케줄된 핸들러 구성, cron 트리거 테스트, Workflows 및 Green Compute와의 연동 작업을 수행할 수 있습니다.
webapp-testing
테스팅이 Claude Skill은 Python 스크립트를 통해 로컬 웹 애플리케이션을 테스트하기 위한 Playwright 기반 툴킷을 제공합니다. 프론트엔드 검증, UI 디버깅, 스크린샷 캡처, 로그 확인 기능을 지원하며 서버 라이프사이클을 관리합니다. 브라우저 자동화 작업에 사용하되 컨텍스트 오염을 방지하기 위해 소스 코드를 읽지 않고 스크립트를 직접 실행하세요.
finishing-a-development-branch
테스팅이 스킬은 테스트 통과를 확인한 후 체계적인 통합 옵션을 제시하여 개발자가 완성된 작업을 마무리하도록 돕습니다. 구현이 완료된 후 머지, PR 생성, 브랜치 정리와 같은 워크플로우를 안내합니다. 코드가 준비되고 테스트가 완료되었을 때 개발 프로세스를 체계적으로 마무리하기 위해 사용하세요.
