Skip to main content
Glama

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 Testbarkeit

  • Vollstä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 dev

Skripte

Skript

Beschreibung

pnpm dev

Start mit Hot-Reload (tsx watch)

pnpm build

Kompiliert TypeScript + löst Aliase auf

pnpm start

Führt den kompilierten Server aus

pnpm test

Führt Tests aus

pnpm lint

Linting des Quellcodes

pnpm type-check

Typ-Prüfung ohne Emit

Konfiguration

Kopiere .env.example nach .env und passe sie an:

Variable

Standard

Beschreibung

MCP_TRANSPORT

stdio

Transport: stdio oder http

PORT

3000

HTTP-Port (nur für http-Transport)

LOG_LEVEL

info

Pino-Log-Level

NODE_ENV

development

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

  1. 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}` }],
    }),
  );
}
  1. 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
}
  1. Füge Tests in src/tools/__tests__/my-tool.tool.spec.ts hinzu

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-mcp

Tech-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

pnpm lint

Strenge Typisierung

pnpm type-check

Build (tsc + Alias)

pnpm build

Unit-Tests (11/11)

pnpm test

Suite

Deckung

greet.tool.spec.ts (5)

Auflistung, Stile casual/formal/enthusiastic, Ablehnung bei leerem Namen

server-info.resource.spec.ts (2)

Auflistung, JSON-Felder (name, version, uptime, timestamp)

summarize.prompt.spec.ts (4)

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.js

JSON-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://server

Verifizierter Endpunkt

Erwartetes Ergebnis

tools/call greet {"name":"Freddy","style":"casual"}

"Hey Freddy! How's it going?"

resources/read info://server

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 mode

CI (GitHub Actions)

pnpm installpnpm lintpnpm buildpnpm 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.json oder 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.

Install Server
F
license - not found
A
quality
D
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Tools

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A TypeScript-based template for rapidly developing MCP servers with modular tool architecture, built-in validation using Zod schemas, and comprehensive error handling.
    9
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A 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.
    9
  • A
    license
    Not graded
    quality
    D
    maintenance
    A minimal TypeScript MCP server template with example tool, Zod validation, stdio transport, and dotenv setup.
    78
    MIT

View all related MCP servers

Related MCP Connectors

  • A TypeScript MCP server for Home Assistant, enabling programmatic management of entities, automati…

  • A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…

  • MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Freddymhs/template-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server