template-mcp
template-mcp
MCP (Model Context Protocol) Server-Template mit TypeScript, Zod-Validierung und Unterstützung für dualen Transport (stdio/HTTP). Kompatibel mit jedem MCP-Client: Claude Code, Claude Desktop, Cursor, VS Code Copilot, Windsurf, Cline und mehr.
Funktionen
Dualer Transport: stdio (lokal) und Streamable HTTP (remote)
TypeScript strict mit ESM-Modulen
Zod-Validierung für Tool-Eingabeschemata
Joi-Umgebungsvalidierung (Fail-Fast beim Start)
Pino-Logging nach stderr (stdio-sicher)
Modulare Architektur: Tools, Ressourcen und Prompts als separate Module
Factory-Pattern:
createServer()für TestbarkeitVollständige Test-Suite mit MCP SDK In-Memory-Transport
Qualitäts-Tooling: ESLint + Prettier + Husky + lint-staged
Docker-bereit: Multi-Stage-Build
CI/CD: GitHub Actions Pipeline
Related MCP server: xmcp Application
Schnellstart
pnpm install
pnpm devSkripte
Skript | Beschreibung |
| Start mit Hot-Reload (tsx watch) |
| Kompiliert TypeScript + löst Aliase auf |
| Führt den kompilierten Server aus |
| Führt Tests aus |
| Linting des Quellcodes |
| Typ-Prüfung ohne Emit |
Konfiguration
Kopiere .env.example nach .env und passe sie an:
Variable | Standard | Beschreibung |
|
| Transport: |
|
| HTTP-Port (nur für |
|
| Pino-Log-Level |
|
| Umgebung |
Projektstruktur
src/
├── main.ts # Entrypoint: transport selection
├── server.ts # createServer() factory
├── config/ # Env validation + constants
├── common/ # Logger, error helpers, types
├── tools/ # MCP tools (callable by LLMs)
├── resources/ # MCP resources (read-only data)
└── prompts/ # MCP prompts (reusable templates)Hinzufügen eines neuen Tools
Erstelle
src/tools/my-tool.tool.ts:
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
export function registerMyTool(server: McpServer): void {
server.registerTool(
'my_tool',
{
title: 'My Tool',
description: 'What this tool does',
inputSchema: {
param: z.string().describe('Parameter description'),
},
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
},
},
async ({ param }) => ({
content: [{ type: 'text', text: `Result: ${param}` }],
}),
);
}Registriere es in
src/tools/index.ts:
import { registerMyTool } from './my-tool.tool.js';
export function registerTools(server: McpServer): void {
registerGreetTool(server);
registerMyTool(server); // add here
}Füge Tests in
src/tools/__tests__/my-tool.tool.spec.tshinzu
Client-Konfiguration
Claude Code
Hinzufügen zu .claude/settings.json:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}Claude Desktop
Hinzufügen zu claude_desktop_config.json:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}Cursor
Hinzufügen zu Cursor Settings > MCP Servers:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}VS Code (Copilot)
Hinzufügen zu .vscode/settings.json:
{
"mcp": {
"servers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}
}Docker
# Build
docker build -t template-mcp .
# Run (HTTP mode, used for remote access)
docker run -p 3000:3000 template-mcpTech-Stack
Node.js 22 + TypeScript (strict, ESM)
MCP SDK v1 (
@modelcontextprotocol/sdk)Zod (Tool-Eingabevalidierung)
Joi (Umgebungsvalidierung)
Pino (stderr-Logging)
Vitest (Testing)
ESLint + Prettier + Husky
Verifizierung
Alles Folgende ist geprüft und funktioniert zu 100%.
Code-Qualität
Check | Befehl |
Lint + Formatierung |
|
Strenge Typisierung |
|
Build (tsc + Alias) |
|
Unit-Tests (11/11)
pnpm testSuite | Deckung |
| Auflistung, Stile casual/formal/enthusiastic, Ablehnung bei leerem Namen |
| Auflistung, JSON-Felder (name, version, uptime, timestamp) |
| Auflistung, Stile brief/bullet-points, numerische Koersion, Defaults |
Kein Netzwerk oder Ports — verwendet InMemoryTransport des SDKs.
Runtime — stdio-Transport (Standardmodus)
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}' \
| MCP_TRANSPORT=stdio node dist/main.jsJSON-RPC-Antwort auf stdout, Logs auf stderr.
Runtime — HTTP-Transport
MCP_TRANSPORT=http PORT=3100 node dist/main.js &
# Initialize → capturar Mcp-Session-Id del header
# tools/list, resources/list, prompts/list, tools/call greet, resources/read info://serverVerifizierter Endpunkt | Erwartetes Ergebnis |
|
|
| JSON mit name, version, uptime, nodeVersion, timestamp |
Docker
docker build -t template-mcp . # multi-stage: base → deps → build → production
docker run -p 3000:3000 template-mcp # arranca en HTTP modeCI (GitHub Actions)
pnpm install → pnpm lint → pnpm build → pnpm test
Läuft bei jedem Push und PR auf main/master.
Commit-Pipeline (lokal)
git commit → husky → lint-staged → eslint --fix + prettier --write (nur gestagte Dateien)
Bekannte Lücken
HTTP-Transport ohne automatisierte Tests (mittel): Die Unit-Tests verwenden
InMemoryTransport; der HTTP-Transport (StreamableHTTPServerTransport) wurde nur manuell mit curl verifiziert. Für Remote-Produktion sollten Integrationstests mit einer echten Sitzung hinzugefügt werden.Integration mit MCP-Client (mittel): Manuelle Verifizierung durch Hinzufügen zu
.claude/settings.jsonoder Cursor und Bestätigung, dass Tools/Ressourcen/Prompts im Client erscheinen.Extreme Tool-Eingaben (niedrig): Sehr lange Strings, fehlerhaftes Unicode — Zod lehnt diese ab, aber die Fehlerantwort ist nicht via HTTP getestet.
Gleichzeitige Sitzungen (niedrig): Außerhalb des Scopes eines Templates.
Available Tools
1 toolgreetGreet UserARead-onlyIdempotent
Generates a personalized greeting message. Use this tool when you need to greet someone by name with an optional custom greeting style.
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The name of the person to greet | |
| style | No | The greeting style to use | casual |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already indicate readOnlyHint=true, destructiveHint=false, and idempotentHint=true, so the description does not need to repeat those. It adds the behavioral detail that the greeting is 'personalized' and that style is optional with a default value, which is sufficient given the high annotation coverage.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, clear sentence that is front-loaded with the main action and immediately provides usage guidance. Every word is necessary and there is no redundant information.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's simplicity (2 parameters, no output schema, no nested objects) and the rich annotations, the description is complete enough. It covers the purpose and usage adequately. No output schema is needed as the return is self-evident.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema already documents both parameters thoroughly (name with length constraints, style with enum and default). The description adds no new parameter information beyond what's in the schema, earning a baseline score of 3.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states that the tool generates a personalized greeting message, with a specific verb ('greet') and resource ('someone by name'). It also mentions the optional custom greeting style, distinguishing it from any potential siblings (though none exist).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description explicitly says 'Use this tool when you need to greet someone by name with an optional custom greeting style,' providing clear usage context. However, it does not specify when not to use it or mention any alternatives, but since there are no siblings, this is adequate.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
1 tool update
v1.0.0- First observed
greet
TDQS
Scored across 1 tool
Only one tool exists, so there is no ambiguity in choosing between tools.
With only one tool, consistency is not applicable, but the name 'greet' is clear and follows a common verb pattern.
A single tool for a server called 'template-mcp' suggests an extremely narrow scope, which is likely insufficient for meaningful tasks.
The server only offers a greeting function, which is too limited for any substantial workflow; missing any broader functionality.
Maintenance
Related MCP Connectors
A simple Typescript MCP server built using the official MCP Typescript SDK and smithery/cli. This…
A TypeScript MCP server for Home Assistant, enabling programmatic management of entities, automati…
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA TypeScript-based template for rapidly developing MCP servers with modular tool architecture, built-in validation using Zod schemas, and comprehensive error handling.9 npmMIT
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server template designed for building structured tools, prompts, and resources with built-in support for HTTP and STDIO transports. It provides a standardized framework for developers to create and deploy AI-driven services using TypeScript and Zod schema validation.8 npm-
- AlicenseNot gradedqualityBmaintenanceA feature-complete MCP server template in TypeScript demonstrating tools, resources, prompts, and both stdio and HTTP transports.8MIT
- AlicenseNot gradedqualityDmaintenanceA minimal TypeScript MCP server template with example tool, Zod validation, stdio transport, and dotenv setup.8 npmMIT