Sponsored by Deepsite.site

mcp-server-template-ts

Created By
duyquangnvxa year ago
A starter template for building robust Model Context Protocol (MCP) servers using TypeScript. This template provides a structured foundation for creating servers that can effectively communicate with Large Language Models (LLMs) through the MCP standard.
Content

mcp-server-template-ts

A TypeScript template for building Model Context Protocol (MCP) servers with a modular and scalable structure.

Overview

This project provides a TypeScript-based template for creating MCP servers that can expose resources, tools, and prompts to Large Language Models (LLMs). The template follows a modular architecture that makes it easy to add new functionality.

The Model Context Protocol (MCP) enables rich, bidirectional communication between LLMs and external services. This template helps you create servers that allow LLMs to:

  • Access structured data via resources
  • Perform actions and computations via tools
  • Generate context-specific responses via prompts

Features

  • TypeScript-based: Fully typed for better development experience
  • Modular Architecture: Add new tools and capabilities easily
  • MCP Standards: Built on the official MCP TypeScript SDK
  • Extensible: Simple base classes to extend for your custom functionality
  • Ready to use: Includes example tools and configuration

Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

# Clone the repository
git clone https://github.com/yourusername/mcp-server-template-ts.git
cd mcp-server-template-ts

# Install dependencies
npm install

Building and Running

# Build the project
npm run build

# Start the MCP server
npm start

# In development, you can use watch mode
npm run watch

Testing with MCP Inspector

You can test your MCP server using the MCP Inspector tool:

npm run inspector

Project Structure

mcp-server-template-ts/
├── src/
│   ├── index.ts         # Main entry point
│   ├── base/            # Base classes and interfaces
│   │   ├── base-tool.ts # Base tool implementation
│   └── tools/           # Tool implementations
│       └── demo-tools.ts # Example tools
├── tsconfig.json        # TypeScript configuration
└── package.json         # Project dependencies

Adding New Tools

  1. Create a new class that extends BaseTool in the src/tools directory:
import { BaseTool, ToolResult } from "../base/base-tool.js";
import { z } from "zod";

export class MyNewTool extends BaseTool {
    name = "my-new-tool";
    description = "Description of my new tool";
    schema = z.object({
        // Define your parameters with Zod
        param1: z.string().describe("Description of parameter 1"),
        param2: z.number().describe("Description of parameter 2")
    });

    async execute(input: z.infer<this["schema"]>): Promise<ToolResult> {
        // Implement your tool logic here
        const result = `Processed ${input.param1} with value ${input.param2}`;
        
        return {
            content: [{ type: "text", text: result }]
        };
    }
}
  1. Register your tool in src/index.ts:
import { MyNewTool } from "./tools/my-tool.js";

// Inside the main function
(new MyNewTool()).register(server);

Adding Resources

To add a resource to your MCP server, modify the index.ts file:

// Register a static resource
server.resource(
  "example-resource",
  "example://resource",
  async (uri) => ({
    contents: [{
      uri: uri.href,
      text: "Example resource content"
    }]
  })
);

// Register a dynamic resource with parameters
server.resource(
  "dynamic-resource",
  new ResourceTemplate("dynamic://{param}", { list: undefined }),
  async (uri, { param }) => ({
    contents: [{
      uri: uri.href,
      text: `Dynamic resource with parameter: ${param}`
    }]
  })
);

Adding Prompts

To add a prompt template to your MCP server, modify the index.ts file:

// Register a prompt template
server.prompt(
  "example-prompt",
  {
    param1: z.string(),
    param2: z.number().optional()
  },
  ({ param1, param2 = 0 }) => ({
    messages: [{
      role: "user",
      content: {
        type: "text",
        text: `Process this with ${param1} and value ${param2}`
      }
    }]
  })
);

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

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

Acknowledgments

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
WindsurfThe new purpose-built IDE to harness magic
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Serper MCP ServerA Serper MCP Server
Tavily Mcp
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Playwright McpPlaywright MCP server
DeepChatYour AI Partner on Desktop
ChatWiseThe second fastest AI chatbot™
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
CursorThe AI Code Editor
RedisA Model Context Protocol server that provides access to Redis databases. This server enables LLMs to interact with Redis key-value stores through a set of standardized tools.
Amap Maps高德地图官方 MCP Server
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code