template-mcp
Provides a multi-stage Docker build for deploying the MCP server in HTTP mode for remote access.
Provides a CI/CD pipeline that runs linting, build, and tests on every push and PR to main/master.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@template-mcp add a greeting tool that accepts a name and returns a personalized message"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
template-mcp
MCP (Model Context Protocol) server template with TypeScript, Zod validation, and dual transport support (stdio/HTTP). Compatible with any MCP client: Claude Code, Claude Desktop, Cursor, VS Code Copilot, Windsurf, Cline, and more.
Features
Dual transport: stdio (local) and Streamable HTTP (remote)
TypeScript strict with ESM modules
Zod validation for tool input schemas
Joi env validation (fail-fast on startup)
Pino logging to stderr (stdio-safe)
Modular architecture: tools, resources, and prompts as separate modules
Factory pattern:
createServer()for testabilityFull test suite with MCP SDK in-memory transport
Quality tooling: ESLint + Prettier + Husky + lint-staged
Docker ready: multi-stage build
CI/CD: GitHub Actions pipeline
Related MCP server: xmcp Application
Quick Start
pnpm install
pnpm devScripts
Script | Description |
| Start with hot reload (tsx watch) |
| Compile TypeScript + resolve aliases |
| Run compiled server |
| Run tests |
| Lint source code |
| Type check without emit |
Configuration
Copy .env.example to .env and adjust:
Variable | Default | Description |
|
| Transport: |
|
| HTTP port (only for |
|
| Pino log level |
|
| Environment |
Project Structure
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)Adding a New Tool
Create
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}` }],
}),
);
}Register in
src/tools/index.ts:
import { registerMyTool } from './my-tool.tool.js';
export function registerTools(server: McpServer): void {
registerGreetTool(server);
registerMyTool(server); // add here
}Add tests in
src/tools/__tests__/my-tool.tool.spec.ts
Client Configuration
Claude Code
Add to .claude/settings.json:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}Cursor
Add to Cursor Settings > MCP Servers:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}VS Code (Copilot)
Add to .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 input validation)
Joi (env validation)
Pino (stderr logging)
Vitest (testing)
ESLint + Prettier + Husky
Verificación
Todo lo siguiente está comprobado y funcionando al 100%.
Calidad de código
Check | Comando |
Lint + formato |
|
Tipado estricto |
|
Build (tsc + alias) |
|
Tests unitarios (11/11)
pnpm testSuite | Cubre |
| Listado, estilos casual/formal/enthusiastic, rechazo de nombre vacío |
| Listado, campos JSON (name, version, uptime, timestamp) |
| Listado, estilos brief/bullet-points, coerción numérica, defaults |
Sin red ni puertos — usa InMemoryTransport del SDK.
Runtime — transporte stdio (modo por defecto)
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.jsRespuesta JSON-RPC en stdout, logs en stderr.
Runtime — transporte HTTP
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://serverEndpoint verificado | Resultado esperado |
|
|
| JSON con 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
Corre en cada push y PR a main/master.
Pipeline de commits (local)
git commit → husky → lint-staged → eslint --fix + prettier --write (solo archivos staged)
Gaps conocidos
HTTP transport sin tests automáticos (medio): los unit tests usan
InMemoryTransport; el transporte HTTP (StreamableHTTPServerTransport) solo se verificó manualmente con curl. Para producción remota añadir tests de integración con sesión realIntegración con cliente MCP (medio): verificar manualmente agregando a
.claude/settings.jsono Cursor y confirmando que tools/resources/prompts aparecen en el clienteTool inputs extremos (bajo): strings muy largos, unicode malformado — Zod los rechaza pero el error response no está testeado vía HTTP
Sesiones concurrentes (bajo): fuera del scope de un template
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.
Inputs: name (required), style.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
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.5 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.4 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.23 npmMIT