Navigation
MCP TypeScript Template: Beginner-Friendly, Production-Ready - MCP Implementation

MCP TypeScript Template: Beginner-Friendly, Production-Ready

MCP TypeScript Template: The beginner-friendly, production-ready foundation for building MCP servers with clean code, utilities, and examples. Future client support coming soon!

Developer Tools
4.0(63 reviews)
94 saves
44 comments

Users create an average of 54 projects per month with this tool

About MCP TypeScript Template

What is MCP TypeScript Template: Beginner-Friendly, Production-Ready?

The MCP TypeScript Template is a pre-configured foundation for developing Model Context Protocol (MCP) servers using TypeScript. Designed for rapid onboarding, it provides production-grade utilities, structured code patterns, and working examples to simplify the implementation of tools and resources. This template ensures developers can start building secure, scalable MCP services without reinventing core infrastructure components.

How to Use MCP TypeScript Template: Beginner-Friendly, Production-Ready?

Begin by cloning the repository and following the setup steps:

  1. Install Node.js and npm
  2. Run npm install to install dependencies
  3. Build the project using npm run build
  4. Start the server with npm run start

Customize the provided example implementations (like the Echo Tool/Resource) to match your use case. Leverage the modular architecture to extend functionality while maintaining type safety and security standards.

MCP TypeScript Template Features

Key Features of MCP TypeScript Template: Beginner-Friendly, Production-Ready?

  • Type Safety: TypeScript integration with strict validation schemas (Zod) and global type definitions prevents common runtime errors
  • Security Framework: Built-in sanitization, rate limiting, and input validation protect against injection attacks and abuse
  • Modular Utilities: Pre-built logging, error handling, and request context management reduce boilerplate code
  • Developer Aids: The .clinerules cheat sheet and structured project layout accelerate development
  • Scalable Architecture: Clear separation of tools/resources and server registration patterns support enterprise-level growth

Use Cases of MCP TypeScript Template: Beginner-Friendly, Production-Ready?

Perfect for:

  • Rapid prototyping of AI-driven microservices
  • Building secure communication layers between models and backend systems
  • Creating reusable tool/resource modules for larger MCP ecosystems
  • Production environments requiring audit trails via structured logging
  • Teams transitioning legacy systems to MCP-compliant architectures

MCP TypeScript Template FAQ

FAQ from MCP TypeScript Template: Beginner-Friendly, Production-Ready?

Q: Is this template compatible with existing TypeScript projects?

A: Yes, the modular design allows seamless integration into existing codebases while maintaining type consistency.

Q: How are errors handled in production?

A: The centralized errorHandler module with customizable logging tiers ensures both developers and operators receive actionable alerts.

Q: Can I add custom security policies?

A: Absolutely, the security.ts utilities provide extension points for organization-specific compliance requirements.

Q: What's the roadmap for client-side support?

A: Upcoming releases will include bidirectional client implementations for connecting to major AI platforms.

Content

MCP TypeScript Template

TypeScript Model Context Protocol Version License Status GitHub

A beginner-friendly foundation for building Model Context Protocol (MCP) servers (and in the future also clients) with TypeScript. This template provides a comprehensive starting point with production-ready utilities, well-structured code, and working examples for building an MCP server.

Copy this repo to kickstart your own MCP server and set your vibe code session up for success!

Using this template as your repo will get you:

  • Utilities : A set of reusable utilities for logging, error handling, ID generation, rate limiting, and request context management.
  • Type Safety : Strong typing with TypeScript to catch errors at compile time.
  • Security : Built-in security features to protect against common vulnerabilities.
  • Error Handling : A robust error handling system that categorizes and formats errors consistently.
  • Documentation : Comprehensive documentation for tools and resources, including usage examples and implementation details.
  • Example Implementations : Working examples of echo_message (tool) and echo://hello (resource) to help you get started quickly.

.clinerules : This repository includes a .clinerules file that serves as a developer cheat sheet for your LLM coding agent with quick reference for the codebase patterns, file locations, and code snippets. When copying this template for your own project, be sure to update the cheat sheet to reflect your modifications and additions.

Table of Contents

  • Overview
    • What is Model Context Protocol?
    • Architecture & Components
  • Features
    • Core Utilities
    • Type Safety
    • Error Handling
    • Security
    • Example Implementations
  • Installation
  • Configuration
  • Project Structure
  • Tool & Resource Documentation
    • Tools
    • Resources
  • Development Guidelines
    • Adding a New Tool
    • Adding a New Resource
  • Future Plans
  • License

Overview

What is Model Context Protocol?

Model Context Protocol (MCP) is a framework that enables AI systems to interact with external tools and resources. It allows language models to:

  • Execute tools that perform actions and return results
  • Access structured resources that provide information
  • Create contextual workflows through standardized interfaces

This template gives you a head start in building MCP servers that can be used by AI systems to extend their capabilities.

Architecture & Components

The template follows a modular architecture designed for clarity and extensibility:

Click to expand architecture diagram
flowchart TB
    subgraph API["API Layer"]
        direction LR
        MCP["MCP Protocol"]
        Val["Validation"]
        San["Sanitization"]

        MCP --> Val --> San
    end

    subgraph Core["Core Components"]
        direction LR
        Config["Configuration"]
        Logger["Logging System"]
        Error["Error Handling"]
        Server["MCP Server"]

        Config --> Server
        Logger --> Server
        Error --> Server
    end

    subgraph Implementation["Implementation Layer"]
        direction LR
        Tool["Tools"]
        Resource["Resources"]
        Util["Utilities"]

        Tool --> Server
        Resource --> Server
        Util --> Tool
        Util --> Resource
    end

    San --> Config
    San --> Server

    classDef layer fill:#2d3748,stroke:#4299e1,stroke-width:3px,rx:5,color:#fff
    classDef component fill:#1a202c,stroke:#a0aec0,stroke-width:2px,rx:3,color:#fff
    class API,Core,Implementation layer
    class MCP,Val,San,Config,Logger,Error,Server,Tool,Resource,Util component

Core Components:

  • Configuration System : Environment-aware configuration with validation
  • Logging System : Structured logging with sensitive data redaction
  • Error Handling : Centralized error processing with consistent patterns
  • MCP Server : Protocol implementation for tools and resources
  • Validation Layer : Input validation using Zod schemas
  • Utilities : Reusable utility functions for common operations

Features

Core Utilities

  • Logging : Configurable logging with file rotation and sensitive data redaction
  • Error Handling : Pattern-based error classification and standardized reporting
  • ID Generation : Secure unique identifier creation with prefix support
  • Rate Limiting : Request throttling to prevent API abuse
  • Request Context : Request tracking and correlation
  • Sanitization : Input validation and cleaning

Type Safety

Error Handling

  • Pattern-Based Classification : Automatically categorize errors based on message patterns
  • Consistent Formatting : Standardized error responses with additional context
  • Error Mapping : Custom error transformation for domain-specific errors
  • Safe Try/Catch Patterns : Centralized error processing helpers

Security

  • Input Validation : Schema-based validation using Zod
  • Input Sanitization : Protection against injection attacks
  • Parameter Bounds : Enforced limits to prevent abuse
  • Sensitive Data Redaction : Automatic redaction in logs

Example Implementations

Installation

Prerequisites

Setup

  1. Clone this repository:

    git clone https://github.com/cyanheads/mcp-ts-template.git

cd mcp-ts-template
  1. Install dependencies:

    npm install

  2. Build the project:

    npm run build

  3. Start the server:

    npm run start

Configuration

Environment Variables (Optional)

Create a .env file based on .env.example:

# Server Configuration
NODE_ENV=development # development, production
LOG_LEVEL=info # debug, info, warn, error

# Rate Limiting
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=100

Configuration System

The configuration system provides a flexible way to manage settings:

  • Environment Config : Load settings from environment variables
  • MCP Servers Config : Configure MCP server connections (for future client implementations)
  • Lazy Loading : Configurations are loaded only when needed

Project Structure

The codebase follows a modular structure:

src/
├── config/                 # Configuration management
│   ├── envConfig.ts        # Environment variable handling
│   ├── index.ts            # Unified configuration
│   └── mcpConfig.ts        # MCP server configuration
│
├── mcp-server/             # MCP server implementation
│   ├── resources/          # Resource implementations
│   │   └── echoResource/   # Example resource
│   ├── tools/              # Tool implementations
│   │   └── echoTool/       # Example tool
│   └── utils/              # Server utilities
│       └── registrationHelper.ts  # Registration helpers
│
├── types-global/           # Shared type definitions
│   ├── errors.ts           # Error types and codes
│   ├── mcp.ts              # MCP protocol types
│   └── tool.ts             # Tool registration types
│
├── utils/                  # Common utilities
│   ├── errorHandler.ts     # Error handling
│   ├── idGenerator.ts      # ID generation
│   ├── logger.ts           # Logging system
│   ├── rateLimiter.ts      # Rate limiting
│   ├── requestContext.ts   # Request context
│   ├── sanitization.ts     # Input sanitization
│   └── security.ts         # Security utilities
│
└── [index.ts](src/index.ts)                # Application entry point
.clinerules                 # Developer cheat sheet for LLM coding agent

Tool & Resource Documentation

Tools

Tool Description
Echo Tool Formats and echoes messages with various options. Demonstrates input validation, error handling, and proper response formatting.

See the Echo Tool documentation for detailed usage examples and implementation details.

Resources

Resource Description
Echo Resource Returns echo messages based on input parameters. Demonstrates resource registration, URI handling, and consistent response formatting.

See the Echo Resource documentation for detailed usage examples and implementation details.

Development Guidelines

Adding a New Tool

  1. Create a new directory under src/mcp-server/tools/
  2. Define types and schemas in a types.ts file
  3. Implement the handler in a dedicated file
  4. Create an index.ts file that registers the tool
  5. Add your tool to the server registration in src/mcp-server/server.ts

Example tool registration:

// In your tool's index.ts
export const registerMyTool = async (server: McpServer): Promise<void> => {
  return registerTool(server, { name: "my_tool" }, async (server, logger) => {
    server.tool(
      "my_tool",
      {
        /* input schema */
      },
      async (params) => {
        // Your implementation
      }
    );
  });
};

// In src/mcp-server/server.ts
await registerMyTool(mcpServer);

Adding a New Resource

  1. Create a new directory under src/mcp-server/resources/
  2. Define types and schemas in a types.ts file
  3. Implement the handler in a dedicated file
  4. Create an index.ts file that registers the resource
  5. Add your resource to the server registration in src/mcp-server/server.ts

Future Plans

This template serves as a foundation for:

  • MCP Client Implementation : Support for creating MCP clients that connect to various AI models

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Copyright 2025 Casey Hand @cyanheads

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Built with the Model Context Protocol

Related MCP Servers & Clients