MCP ExplorerExplorer

Create Mcp Server

@Makoqon 10 months ago
2 MIT
FreeCommunity
AI Systems
#mcp#mcp-server#typescript#create-mcp-server
create mcp server cli in TS.

Overview

What is Create Mcp Server

create-mcp-server is a command-line tool designed for quickly creating standardized MCP (Model Context Protocol) servers using Node.js. It simplifies the setup process by providing a structured template for server development.

Use cases

Use cases for create-mcp-server include quickly developing standard services with pre-configured middleware and automatic error handling, as well as scenarios requiring deep customization and control over the request lifecycle.

How to use

To use create-mcp-server, you can run the command ‘npx @ad/create-mcp-server your-server-name’ to create a new MCP server project. Alternatively, you can install it globally using npm and then create a project with ‘create-mcp-server your-server-name’. After creating the project, navigate into the project directory, install dependencies with ‘npm install’, and build the project using ‘npm run build’.

Key features

Key features include an interactive configuration interface, support for both high-level and low-level API development, rapid project generation through a template engine, and intelligent configuration that automatically generates package.json and TypeScript settings.

Where to use

create-mcp-server can be used in various fields including web development, API development, and microservices architecture, where rapid development and standardized server setups are required.

Content

npm

MCP Server Scaffolding Tool

A command - line tool for quickly creating standardized MCP (Model Context Protocol) servers using Node.js

✨Features

🛠️ Interactive Configuration

  • Provides a user
  • friendly command
  • line interactive interface

📦 Multi - level API Support

  • Supports both High
  • Level and Low
  • Level API development

⚡ Rapid Generation

  • Fast project generation based on a template engine

🔧 Intelligent Configuration

  • Automatically generates package.json and TypeScript configurations

🚀 Quick Start

Create a Project


# by npx
npx create-ts-mcp-server your-server-name

Initialization Steps of CLI

# config your project name
? What is the name of your MCP (Model Context Protocol) server? (your-mcp-server-name)
# config your project description
? What is the description of your server? (A Model Context Protocol server)
# @modelcontextprotocol/sdk API level,High-Level upper layer encapsulation of simple and easy-to-use API (suitable for most simple scenarios, more recommended), Low-Level API for underlying detail processing is suitable for complex scenarios
? What is the API level of your server?
 High-Level use (Recommended): It is a commonly used and encapsulated interface for developers. It shields many complex details, is easy to use, and is suitable for most scenarios.
 Low-Level use: It is a low-level interface, which is suitable for developers who need to customize the implementation details. (Use arrow keys)
❯ High-Level API
  Low-Level API
# config your server transport type
? What is the transport type of your server?
 Standard Input/Output (stdio):The stdio transport enables communication through standard
input and output streams. This is particularly useful for local integrations and command-line
 tools.
 Server-Sent Events (SSE):SSE transport enables server-to-client streaming with HTTP POST
requests for client-to-server communication. 
❯ Standard Input/Output (stdio)
  Server-Sent Events (SSE)
# success message
✔ MCP server created successfully!

Next steps:
  cd your-mcp-server-name
  npm install
  npm run build  #  build your server first
  npm run inspector # debug your server

Develope Command

cd your-server-name

npm install # install dependencies

npm run build # build project

npm run inspector # stdio: type debug your server

npx tsx ./src/index.ts # sse: run your sse server

Directory Structure

The typical project structure generated is as follows:

your-server-name/
├── src/
│   ├── server     
│       ├── server.ts # mcp server
│   ├── index.ts      # Service entry file
├── package.json
└── tsconfig.json

📚 API Level Explanation

High-Level API

Use cases: Rapid development of standard services Features:

Pre-configured common middleware
Automatic error handling
Standardized routing configuration
Out-of-the-box RESTful support

Example:

// Quickly create a service instance
server.tool(
  "calculate-bmi",
  {
    weightKg: z.number(),
    heightM: z.number()
  },
  async ({ weightKg, heightM }) => ({
    content: [{
      type: "text",
      text: String(weightKg / (heightM * heightM))
    }]
  })
);

Low-Level API

Use cases: Scenarios requiring deep customization Features:

Full control over the request lifecycle
Manual management of the middleware chain
Custom protocol handling
Low-level performance optimization

Example:

server.setRequestHandler(CallToolRequestSchema, async (request) => {
  switch (request.params.name) {
    case "create_note": {
      const title = String(request.params.arguments?.title);
      const content = String(request.params.arguments?.content);
      if (!title || !content) {
        throw new Error("Title and content are required");
      }

      const id = String(Object.keys(notes).length + 1);
      notes[id] = { title, content };

      return {
        content: [{
          type: "text",
          text: `Created note ${id}: ${title}`
        }]
      };
    }

    default:
      throw new Error("Unknown tool");
  }
});

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers