From agent-almanac
Scaffolds complete, runnable MCP servers in TypeScript or Python from tool specifications, with transport config, handlers, and test harness. Use for new projects, migrations to MCP, or prototyping tool surfaces.
npx claudepluginhub pjt222/agent-almanacThis skill uses the workspace's default tool permissions.
---
Builds complete MCP servers from specs or natural language, generating tools, resources, validation, tests, and docs in TypeScript (@modelcontextprotocol/sdk) or Python (FastMCP). Use for AI agent tool/resource access.
Generates complete Python MCP server project with uv init, mcp[cli], FastMCP, typed tools/resources/prompts, stdio/HTTP transport options, error handling, and testing setup.
Provides patterns for building, testing, deploying Model Context Protocol (MCP) servers in Python/TypeScript: tools, resources, prompts, transports (stdio, SSE, streamable HTTP), decision trees.
Share bugs, ideas, or general feedback.
Generate a complete, runnable MCP server project from a tool specification document, using the official MCP SDK for TypeScript or Python.
analyze-codebase-for-mcp or written manually) and need a working servertypescript or python)stdio or sse)none, bearer-token, api-key)true or false, default: false)1.1. Choose the implementation language based on project context:
1.2. Choose the transport mechanism:
1.3. Determine authentication requirements:
Expected: Clear language, transport, and auth choices documented.
On failure: If requirements are ambiguous, default to TypeScript + stdio + no auth for fastest time-to-working-server.
2.1. Create the project 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. Create the standard directory structure:
$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. Add 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"
}
}
Expected: A buildable project skeleton with all dependencies installed.
On failure: If npm/pip install fails, check network connectivity and registry access. For TypeScript, ensure Node.js >= 18. For Python, ensure Python >= 3.10.
3.1. Parse the tool specification document and for each 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. Generate one handler file per tool category from the specification.
3.3. Add input validation beyond type checking:
3.4. Add structured error responses for all anticipated failure modes.
Expected: A handler file per category with typed parameters and error handling.
On failure: If the spec contains ambiguous types, default to string and add a TODO comment for manual refinement.
4.1. Create the 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 authentication is required, add middleware:
Authorization headerX-API-Key header4.3. Add a shebang line for stdio servers to enable direct execution:
#!/usr/bin/env node
Expected: A working entry point that starts the MCP server on the configured transport.
On failure: If the SDK version does not match the import paths, check the @modelcontextprotocol/sdk version and adjust imports. The SDK restructured paths between versions.
5.1. Build 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. Create test fixtures for each tool: valid inputs, invalid inputs, and edge cases.
5.3. Add a test script to package.json or pyproject.toml.
Expected: A test harness that exercises every tool with both valid and invalid inputs.
On failure: If InMemoryTransport is not available in the SDK version, fall back to spawning the server as a subprocess and communicating via stdio pipes.
6.1. Generate a README.md with:
6.2. Generate 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. Generate 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"]
Expected: Complete documentation and configuration files for immediate use.
On failure: If the generated README has placeholder values, search the project for actual values to substitute. If Docker build fails, verify the base image matches the Node.js/Python version used.
npm run build or equivalent)tools/list JSON-RPC requestclaude mcp add command@modelcontextprotocol/sdk package restructured its exports between versions. Always check the installed version's actual export paths.#!/usr/bin/env node as the first line to be executable.async. Synchronous operations block all other tool calls on the server.type: "module" in package.json: The MCP SDK uses ESM imports. Without "type": "module", Node.js treats files as CommonJS and imports fail.console.log in tool handlers corrupts the protocol stream. Use console.error or a file logger instead.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 after deploymentcontainerize-mcp-server - package the server in Docker for distribution