create-typescript-server

repository·main·Indexed 41 days ago

https://github.com/modelcontextprotocol/create-typescript-server

A command line scaffolding tool to quickly bootstrap new Model Context Protocol (MCP) servers using TypeScript. Version 0.3.1 provides a CLI to handle directory creation, template generation, and optional automated configuration for Claude.app on macOS and Windows.

Tokens
1.3K
Snippets
6
Records
8
Agent score
51%

What's inside create-typescript-server

  1. Set up and build your new MCP server

    main

    Once the scaffolding is complete, follow these steps to prepare your server for development or use:

    1. Navigate to the directory: cd <your-server-directory>
    2. Install dependencies: npm install
    3. Build the project: Use npm run build for a one-time compilation, or npm run watch to run the TypeScript compiler in watch mode for continuous development.
    4. (Optional) Global link: Use npm link to make your server binary available globally on your system.
    cd my-server
    npm install
    npm run build
  2. Scaffold a new MCP server with create-typescript-server

    main

    Use npx @modelcontextprotocol/create-server to quickly scaffold a new Model Context Protocol (MCP) server project. You can specify a directory name and optional metadata like the server name and description.

    To create a server in a directory named my-server with default settings:

    npx @modelcontextprotocol/create-server my-server

    To include custom metadata:

    npx @modelcontextprotocol/create-server my-server --name "My MCP Server" --description "A custom MCP server"
    npx @modelcontextprotocol/create-server my-server
  3. Understand the server's MCP capabilities (Resources, Tools, and Prompts)

    main

    This server demonstrates the three core MCP primitives:

    Resources

    Allows clients to list and access data via URIs. In this implementation, notes are accessed using note:// URIs. Each resource includes a title, content, and metadata, typically using a plain text mime type.

    Tools

    Allows clients to perform actions. This server provides the create_note tool, which takes title and content as required parameters to store a new note in the server state.

    Prompts

    Allows clients to use pre-defined templates for LLM interaction. This server provides the summarize_notes prompt, which embeds all note contents as resources and returns a structured prompt designed for LLM summarization.

  4. Install an MCP server for Claude.app

    main

    The create-mcp-server CLI includes an automated feature to add your new server to the Claude.app configuration.

    • Supported Platforms: macOS (darwin) and Windows (win32).
    • Behavior: During the scaffolding process, you will be prompted: Would you like to install this server for Claude.app?.
    • Configuration File: It modifies claude_desktop_config.json located in:
      • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
      • Windows: %APPDATA%/Claude/claude_desktop_config.json
    • Config Format: The tool adds an entry to the mcpServers object using the server name, pointing to the build output:
    "<name>": {
      "command": "node",
      "args": ["/absolute/path/to/your/server/build/index.js"]
    }

    If a server with the same name already exists in the config, the CLI will prompt you for permission to replace it.

  5. Install the MCP server in Claude Desktop

    main

    To use the server with Claude Desktop, you must add its configuration to your claude_desktop_config.json file.

    Config File Locations:

    • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%/Claude/claude_desktop_config.json

    Add an entry under the mcpServers key pointing to the absolute path of the compiled index.js file.

    {
      "mcpServers": {
        "<%= name %>": {
          "command": "/path/to/<%= name %>/build/index.js"
        }
      }
    }
  6. Debug the MCP server using the MCP Inspector

    main

    Because MCP servers communicate via stdio, standard debugging is difficult. Use the MCP Inspector to provide a web-based interface for inspecting server capabilities and messages.

    Run the following command to start the inspector:

    npm run inspector

    The command will provide a URL that you can open in your browser to access the debugging tools.

  7. Create a new MCP server with create-mcp-server

    main

    Use the create-mcp-server CLI to scaffold a new Model Context Protocol (MCP) server in a specified directory. The tool handles directory creation, template file generation (using EJS), and can optionally automatically configure the server for use with Claude.app on macOS and Windows.

    Usage

    Run the command followed by the target directory:

    create-mcp-server <directory>

    CLI Options

    • <directory> (Argument): The path where the new server project will be created.
    • -n, --name <name>: The name of the MCP server. If not provided, it defaults to the basename of the directory.
    • -d, --description <description>: A description of the server. If not provided, it defaults to "A Model Context Protocol server".

    Post-Creation Steps

    Once the server is created, navigate to the directory and perform the following:

    1. cd <directory>
    2. npm install
    3. npm run build (or npm run watch for development)
    4. npm link (optional, to make the server available globally)
    create-mcp-server my-server --name my-custom-server --description "A server that does cool things"