Skip to content

Model Context Protocol (MCP) TypeScript Server Template Pack

Production template pack for building Model Context Protocol servers in TypeScript. Supports Stdio and SSE transports with schema validation.

By Gordon Geraghty·MIT Licence·Updated: 24 September 2026·ADVANCED
01 Prerequisites & Architecture
Stage 01 Architecture

Model Context Protocol (MCP) Server Architecture

Architecture of Model Context Protocol TypeScript servers bridging LLM clients (Claude Desktop, Cursor, Antigravity) over Stdio/SSE transports to execute typed tools and access contextual resources.

Difficulty:Intermediate Engineering
Time:20–30 mins
Required Access & Permissions:
Node.js 18+ / TypeScript RuntimeClaude Desktop / MCP Client Config Access
STEP 01MCP Client Host
LLM Client (Host)Claude Desktop / Claude Code / Antigravity
STEP 02MCP Transport Protocol
Transport LayerStdio (local subprocess) or SSE (HTTP stream)
STEP 03@modelcontextprotocol/sdk
Tool Dispatcher & Zod SchemaStrict input parameter parsing & execution
STEP 04Backend Services
External APIs & DatastoresGoogle Ads, GA4, BigQuery, CMS integrations
02 Interactive Configurator

Model Context Protocol (MCP) TypeScript Server Template Pack Configurator

Worked Example · Deterministic Calculation

Marketing Analytics & Ads Governance — Model Context Protocol (MCP) Server

TypeScript Model Context Protocol (MCP) server exposing GAQL query execution and unit economics calculation tools to Claude and AI agents.

1 Input Parameters & Assumptions

ParameterValueContext & Provenance
Server Identifiermarketing-analytics-mcp Server NameUnique MCP server identifier
Server Version1.0.0 SemVerInitial production release specification
Transport LayerStandard I/O (stdio) TransportProcess-level stdio communication compatible with Claude Desktop and Antigravity
Exposed Tools2 Registered Tools ToolsGAQL query execution & POAS unit-economics calculation

2 Explicit Mathematical Formula

Protocol Framing: JSON-RPC 2.0 over standard I/O (stdio transport)
Registered Tool 1: query_google_ads_gaql (parameters: query [string, required], accountId [string, required])
Registered Tool 2: calculate_poas_unit_economics (parameters: aov [number, required], cpa [number, required], cogsPercentage [number, required])
Input Validation: Strict JSON Schema parameter enforcement before handler dispatch
Config Export: claude_desktop_config.json snippet

3 Computed Output Metrics

Registered Tool Count2 ToolsToolsExposes GAQL querying and unit-economics calculation to LLMs
Protocol StandardModel Context ProtocolStandardNative JSON-RPC 2.0 stdio framing compatible with Claude Desktop, Cursor, and Antigravity
Computed MetricResultInterpretation & Threshold
Registered Tool Count2 Tools ToolsExposes GAQL querying and unit-economics calculation to LLMs
Protocol StandardModel Context Protocol StandardNative JSON-RPC 2.0 stdio framing compatible with Claude Desktop, Cursor, and Antigravity
Type Safety Guarantee100% Zod / TS SchemaStrict parameter typing prevents ill-formed tool call invocations

Strategic Takeaway & Operational Guidelines

The Model Context Protocol allows language models to interact securely with private data sources and APIs. This template exposes structured GAQL queries and unit economics models as verifiable tools.

INSTRUMENT BOUNDARIES

Model Context Protocol (MCP) TypeScript Server Template Pack — Scope & Limitations

Explicit operational boundaries and constraints defining target use cases and out-of-scope scenarios.

Built For (Target Use Cases)

  • Scaffolding a TypeScript Model Context Protocol server manifest and boilerplate from named tools.
  • Documenting tool names, parameters, and required fields for stdio or SSE transport.
  • Producing a starting claude_desktop_config.json snippet for local MCP server registration.

Not Built For (Limitations & Out-of-Scope)

  • Working tool implementations; generated handlers are stubs returning placeholder text, not real logic.
  • SSE transport code; the generated server always wires StdioServerTransport regardless of the selected transport.
  • Authentication, rate limiting, or deployment configuration for the generated server.

Operational Assumptions & Defaults

  • PRESET_TOOLKITS.marketing_analytics and similar presets define example tool sets, not required ones.
  • Tool parameter types map directly to JSON Schema without additional runtime validation.
  • Generated code targets the @modelcontextprotocol/sdk stdio and SSE transport APIs as documented.

Model Context Protocol (MCP) Server & Tool Pack Builder

MCP SDK & Claude Desktop

Build custom Model Context Protocol (MCP) servers with typed tool definitions, parameter schemas, and instant exports for `@modelcontextprotocol/sdk` TypeScript boilerplate and `claude_desktop_config.json`.

Load Toolkit Preset:

MCP Server Properties

Tool Definitions (2)

Generated MCP Artifacts

{
  "name": "marketing-analytics-mcp",
  "version": "1.0.0",
  "transport": "stdio",
  "tools": [
    {
      "name": "query_google_ads_gaql",
      "description": "Executes a Google Ads Query Language (GAQL) query and returns campaign performance metrics.",
      "inputSchema": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "GAQL query string"
          },
          "accountId": {
            "type": "string",
            "description": "Google Ads CID"
          }
        },
        "required": [
          "query",
          "accountId"
        ]
      }
    },
    {
      "name": "calculate_poas_unit_economics",
      "description": "Computes net contribution margin and break-even ROAS for an e-commerce brand.",
      "inputSchema": {
        "type": "object",
        "properties": {
          "aov": {
            "type": "number",
            "description": "Average order value"
          },
          "cpa": {
            "type": "number",
            "description": "Cost per acquisition"
          },
          "cogsPercentage": {
            "type": "number",
            "description": "COGS %"
          }
        },
        "required": [
          "aov",
          "cpa",
          "cogsPercentage"
        ]
      }
    }
  ]
}
Export & Deployment Actions1-click clipboard transfer, shareable URL hash, and local file downloads.

Built by Gordon Geraghty, Head of Performance MediaZero Data Sent to Server
03 Deployment & Export

Deploy MCP Server to Claude Desktop / Antigravity

Download the generated MCP server package (`index.ts`, `package.json`, `tsconfig.json`), compile with `npm run build`, and add to your `claude_desktop_config.json`.

The Standard Interface for AI Tool Execution

The Model Context Protocol establishes an open standard for connecting AI models to external tools, databases, and APIs. This template pack provides clean error handling and schema validation for production deployments.

Implementation Code & Script

Standard MCP Stdio Server Templatemcp-server.tstypescript

Production MCP server with tool definitions, error boundaries, and input schemas.

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';

const server = new Server(
  { name: 'marketing-analytics-mcp', version: '1.0.0' },
  { capabilities: { tools: {} } }
);

server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [
    {
      name: 'get_campaign_performance',
      description: 'Fetches spend, conversion, and CPA metrics for a given campaign.',
      inputSchema: {
        type: 'object',
        properties: {
          campaignId: { type: 'string', description: 'Google Ads or Meta campaign ID' },
          dateRange: { type: 'string', enum: ['LAST_7_DAYS', 'LAST_30_DAYS'] },
        },
        required: ['campaignId'],
      },
    },
  ],
}));

server.setRequestHandler(CallToolRequestSchema, async (request) => {
  if (request.params.name === 'get_campaign_performance') {
    const campaignId = String(request.params.arguments?.campaignId);
    return {
      content: [{ type: 'text', text: JSON.stringify({ campaignId, spend: 1250.00, conversions: 42, cpa: 29.76 }) }],
    };
  }
  throw new Error('Tool not found');
});

const transport = new StdioServerTransport();
await server.connect(transport);
04 QA & Verification Guide

MCP Server Inspector & Tool Execution QA

Debug and test your MCP server tools using the official MCP Inspector before connecting to production clients.

Pre-Production Verification Checklist

✓
Verify Tool Registration in MCP Inspector

Run npx @modelcontextprotocol/inspector node dist/index.js and verify all tools appear in UI.

✓
Test Zod Schema Input Validation

Pass invalid types to tool arguments and confirm clean error payloads are returned.

✓
Validate claude_desktop_config.json Integration

Confirm Claude Desktop displays the hammer icon and successfully executes registered tools.

Terminal Diagnostic & Debug Commands

Launch MCP Inspector Debuggerbash

Opens local web interface on port 5173 to test tool calls and resource reads.

npx @modelcontextprotocol/inspector node dist/index.js

Failure Remediation & Troubleshooting

Issue: Claude Desktop Fails to Connect to MCP Server

Cause: Server process wrote non-JSON debug logs to stdout, corrupting the Stdio transport.

Fix: Always use console.error() instead of console.log() for debugging in Stdio MCP servers.

How to cite and attribute this tool

MIT Licence

This resource is free, open and un-gated under the MIT Open Source Licence. You are encouraged to use, integrate and cite it with attribution:

Geraghty, G. (2026). Model Context Protocol (MCP) TypeScript Server Template Pack. Gordon Geraghty Resources Hub. https://gordongeraghty.com/resources/ai-engineering/mcp-server-template-pack
BibTeX Format
@misc{geraghty_mcp_server_template_pack,
  author = {Geraghty, Gordon},
  title = {Model Context Protocol (MCP) TypeScript Server Template Pack},
  year = {2026},
  url = {https://gordongeraghty.com/resources/ai-engineering/mcp-server-template-pack},
  note = {Head of Performance Media, Empire Amplify}
}

Changelog & Version History

  • v1.0.0Initial release of TypeScript MCP server template with Stdio and SSE support.