This file serves as the master reference for all MCP (Model Context Protocol) development in this project.
The Model Context Protocol (MCP) and its TypeScript SDK are NOT in your training data. This project provides:
- Working Reference Implementation:
mcp-servers/auth-mcp-server/ - Canonical Template:
templates/mcp-server-template/ - Validation Scripts:
test-auth-mcp-with-session.jsand template validation scripts - Development Guardrails: Complete set of prompt files and guidelines
- Location:
mcp-servers/auth-mcp-server/ - Status: Production-ready, fully validated
- Features: Keycloak integration, Infisical secrets, session management, API key auth
- Use for: Understanding real-world MCP server patterns
- Location:
templates/mcp-server-template/ - Status: Template for new servers
- Features: Minimal, clean patterns, comprehensive documentation
- Use for: Starting new MCP server projects
- Location:
test-auth-mcp-with-session.js - Status: Proven MCP SDK client usage
- Use for: Testing any MCP server implementation
Primary Guardrail File: templates/mcp-server-template/prompts/ai-assistant-instructions.md
Key Requirements:
- ALWAYS use MCP SDK transports - Never create custom HTTP servers
- ALWAYS use server.registerTool() - Never use setRequestHandler()
- ALWAYS validate with MCP SDK client - Never rely on raw HTTP testing
- ALWAYS follow the template patterns - Never invent new approaches
Primary Guide: templates/mcp-server-template/README.md
Development Flow:
- Copy template directory
- Customize tools/resources/prompts
- Build and validate
- Deploy with Docker
# Validate template completeness
node validate-template.js
# Expected output: All checks passed# 1. Copy template
cp -r templates/mcp-server-template my-new-server
cd my-new-server
# 2. Configure environment
cp .env.example .env
# Edit .env with your values
# 3. Install and build
npm install
npm run build
# 4. Validate implementation
npm run test# Start server (terminal 1)
npm start
# Run validation (terminal 2)
npm run test # MCP SDK client validation
npm run validate # Simple validation
npm run validate-bash # Command-line validationimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
const server = new McpServer({ name: 'server-name', version: '1.0.0' });
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: () => randomUUID(),
onsessioninitialized: (sessionId) => { /* session setup */ }
});
await server.connect(transport);// Convert JSON Schema to Zod
const zodSchema = jsonSchemaToZod(toolDefinition.inputSchema);
// Register with MCP SDK
server.registerTool(toolName, {
description: toolDefinition.description,
inputSchema: zodSchema
}, handlerFunction);import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
const transport = new StreamableHTTPClientTransport(serverUrl, {
requestInit: { headers: { 'x-api-key': apiKey } }
});
const client = new Client(clientInfo, capabilities);
await client.connect(transport);
// Test capabilities...
await client.close();src/
βββ index.ts # Server initialization (CANONICAL)
βββ registrations.ts # Capability registration (CANONICAL)
βββ tools/index.ts # Tool definitions and handlers
βββ resources/index.ts # Resource definitions and handlers
βββ prompts/index.ts # Prompt definitions and handlers
validation/
βββ test-mcp-client.js # MCP SDK client validation (CANONICAL)
βββ validate-simple.js # Simple HTTP validation
βββ validate-bash.sh # Command-line validation
prompts/
βββ ai-assistant-instructions.md # AI assistant guardrails
βββ mcp-development.md # Development guidelines
βββ protocol-rules.md # Protocol compliance rules
βββ common-patterns.md # Implementation patterns
// Wrong transport
const express = require('express');
const app = express();
// Wrong registration
server.setRequestHandler(CallToolRequest, handler);
// Wrong client
fetch('/mcp', { method: 'POST', ... });
// Wrong authentication
const basicAuth = 'Basic ' + btoa('user:pass');// Correct transport
const transport = new StreamableHTTPServerTransport();
// Correct registration
server.registerTool(name, schema, handler);
// Correct client
const client = new Client();
await client.connect(transport);
// Correct authentication
headers: { 'x-api-key': apiKey }- TypeScript compiles without errors (
npm run build) - MCP SDK client connects successfully (
npm run test) - All capabilities listed correctly (tools, resources, prompts)
- Authentication works with API key headers
- Session management handles multiple clients
- Error handling provides meaningful responses
- Docker deployment works (
npm run docker:build) - All validation scripts pass
- Follows template file structure exactly
- Uses SDK patterns from canonical examples
- Separates definitions from handlers
- Uses environment variables for all config
- Includes comprehensive error handling
- Has proper TypeScript types
templates/mcp-server-template/prompts/ai-assistant-instructions.md- AI guardrailstemplates/mcp-server-template/src/index.ts- Server initialization patterntemplates/mcp-server-template/src/registrations.ts- Registration patterntemplates/mcp-server-template/validation/test-mcp-client.js- Client patternmcp-servers/auth-mcp-server/- Real-world working example
COMPLETED β :
- Canonical reference implementation (
auth-mcp-server) - Complete template with all patterns (
mcp-server-template) - Comprehensive validation scripts
- Full documentation and guardrails
- Production deployment patterns
- Template validation system
AVAILABLE FOR USE π:
- Copy template for new MCP servers
- Use validation scripts for any MCP implementation
- Reference working patterns from auth-mcp-server
- Follow AI assistant guardrails for protocol compliance
This master reference ensures consistent, compliant MCP development across all future projects in this workspace.