### Quick Start Project Creation Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/REFERENCE.md Create a new MCP server project, navigate into its directory, install dependencies, build the project, and run the inspector. ```bash npx @modelcontextprotocol/create-server my-server cd my-server npm install npm run build npm run inspector build/index.js ``` -------------------------------- ### Example Workflow: Create and Build Server Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md Demonstrates the typical workflow for creating a new server, installing dependencies, building the project, and running the inspector for testing. ```bash # Create a new server with all options specified npx @modelcontextprotocol/create-server weather-server \ --name "weather-mcp" \ --description "Weather data MCP server" ``` ```bash # Enter the new directory cd weather-server ``` ```bash # Install dependencies npm install ``` ```bash # Build the project npm run build ``` ```bash # Test the server (requires MCP inspector installed) npm run inspector build/index.js ``` -------------------------------- ### Post-Creation Server Setup Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/README.md Commands to navigate into the newly created server directory, install dependencies, and set up build processes. Includes options for a one-time build or continuous watch mode. ```bash cd my-server # Navigate to server directory npm install # Install dependencies npm run build # Build once # or... npm run watch # Start TypeScript compiler in watch mode ``` -------------------------------- ### NPM Integration: Using Global Install Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md Shows how to install the create-server tool globally and use the create-mcp-server command. ```bash npm install -g @modelcontextprotocol/create-server ``` ```bash create-mcp-server [options] ``` -------------------------------- ### Usage Example: Get Windows Configuration Directory Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Demonstrates how to use getClaudeConfigDir to retrieve the configuration directory on Windows. Includes error handling for unsupported platforms. ```typescript import { getClaudeConfigDir } from './index.js'; try { const configDir = getClaudeConfigDir(); console.log(configDir); // Output: C:\Users\username\AppData\Roaming\Claude } catch (error) { console.error('Platform not supported:', error.message); } ``` -------------------------------- ### Install Dependencies Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/CONTRIBUTING.md Install the necessary project dependencies using npm. ```bash npm install ``` -------------------------------- ### CreateServerOptions Usage Example Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/types.md Shows how to import and use the createServer function with a populated CreateServerOptions object. This example configures server name, description, and Claude integration. ```typescript import { createServer } from './index.js'; const options = { name: 'my-server', description: 'My MCP server implementation', installForClaude: true }; await createServer('/path/to/server', options); ``` -------------------------------- ### Description Option Examples Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md Shows how to use the --description or -d option to provide a custom description for the MCP server. ```bash create-mcp-server my-server --description "Integrates with my custom service" ``` ```bash create-mcp-server my-server -d "API integration server" ``` -------------------------------- ### Install Dependencies and Build Server Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Installs project dependencies and compiles the TypeScript server code into JavaScript. ```bash cd generated-server npm install npm run build ``` -------------------------------- ### Usage Example: Get macOS Configuration Directory Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Demonstrates how to use getClaudeConfigDir to retrieve the configuration directory on macOS. Includes error handling for unsupported platforms. ```typescript import { getClaudeConfigDir } from './index.js'; try { const configDir = getClaudeConfigDir(); console.log(configDir); // Output: /Users/username/Library/Application Support/Claude } catch (error) { console.error('Platform not supported:', error.message); } ``` -------------------------------- ### Name Option Examples Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md Demonstrates how to use the --name or -n option to specify a custom name for the MCP server. ```bash create-mcp-server my-server --name "Custom Server" ``` ```bash create-mcp-server my-server -n "my-mcp-server" ``` -------------------------------- ### Create a Basic MCP Server Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/REFERENCE.md Use this command to create a new MCP server project with default settings. After creation, navigate to the project directory, install dependencies, and build the project. ```bash npx @modelcontextprotocol/create-server my-server cd my-server && npm install && npm run build ``` -------------------------------- ### Install create-mcp-server Globally Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/REFERENCE.md Install the create-mcp-server package globally using npm. Alternatively, you can use npx to run the command without a global installation. ```bash npm install -g @modelcontextprotocol/create-server ``` ```bash # or use with npx npx @modelcontextprotocol/create-server ``` -------------------------------- ### Directory Argument Examples Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md Illustrates how to specify the required directory argument for the create-mcp-server command, using relative and absolute paths. ```bash create-mcp-server my-server ``` ```bash create-mcp-server ./path/to/my-server ``` ```bash create-mcp-server /absolute/path/my-server ``` -------------------------------- ### Usage Example: Construct Full Configuration File Path Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Shows how to combine the configuration directory obtained from getClaudeConfigDir with a filename to create a full path to a configuration file. ```typescript import { getClaudeConfigDir } from './index.js'; import path from 'path'; const configDir = getClaudeConfigDir(); const configFile = path.join(configDir, 'claude_desktop_config.json'); console.log(configFile); ``` -------------------------------- ### Enable Verbose Logging for Server Creation Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md Run the server creation command with the DEBUG environment variable set to '*' to enable verbose logging. This helps in diagnosing issues during the server setup process. ```bash # Enable verbose logging (varies by implementation) DEBUG=* npx @modelcontextprotocol/create-server my-server ``` -------------------------------- ### Prompt for Claude Desktop Installation Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md This prompt appears on macOS or Windows if the user wants to install the server for Claude.app. The default value is true. ```bash ? Would you like to install this server for Claude.app? ``` -------------------------------- ### Claude Desktop User Prompt for Server Replacement Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Example of the confirmation prompt displayed when attempting to register a server with a name that already exists in the Claude configuration. ```text ? An MCP server named "server-name" is already configured for Claude.app. Do you want to replace it? (y/N) ``` -------------------------------- ### Claude Desktop Configuration File Format Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Example JSON structure for the Claude Desktop configuration file, showing how MCP servers are registered. ```json { "mcpServers": { "server-name": { "command": "node", "args": ["/absolute/path/to/server/build/index.js"] }, "another-server": { "command": "node", "args": ["/absolute/path/to/other-server/build/index.js"] } } } ``` -------------------------------- ### Wrapper Function for Custom Server Workflow Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md This example shows how to create a wrapper function to encapsulate custom logic for server creation, including dynamic path generation and conditional configuration based on the operating system. ```typescript import { createServer } from './index.js'; async function createServerForTeplate( projectName: string, projectDesc: string ) { const serverPath = `./${projectName}`; await createServer(serverPath, { name: projectName, description: projectDesc, installForClaude: process.platform !== 'linux' }); } await createServerForTeplate('notification-server', 'Sends notifications'); ``` -------------------------------- ### Note Type Usage Example Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/types.md Demonstrates how to declare and initialize a collection of notes using the 'Note' type. This is typically used for in-memory data stores. ```typescript const notes: { [id: string]: Note } = { "1": { title: "First Note", content: "This is note 1" }, "2": { title: "Second Note", content: "This is note 2" } }; ``` -------------------------------- ### Example Claude Desktop Configuration Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/configuration.md This JSON structure represents a server entry within the Claude Desktop configuration file. It specifies the command to run and its arguments, typically pointing to the compiled server executable. ```json { "mcpServers": { "server-name": { "command": "node", "args": ["/absolute/path/to/build/index.js"] } } } ``` -------------------------------- ### Create Server in Interactive Mode Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Use this when you want the createServer function to prompt the user for necessary details like name, description, and Claude installation status. This is useful for interactive CLI tools. ```typescript import { createServer } from './index.js'; await createServer('/home/user/my-mcp-server'); // Prompts for name, description, Claude installation ``` -------------------------------- ### Start MCP Server with Stdio Transport Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Initiates the MCP server connection using the standard input/output transport. Catches and logs any connection errors. ```typescript async function main() { const transport = new StdioServerTransport(); await server.connect(transport); } main().catch((error) => { console.error("Server error:", error); process.exit(1); }); ``` -------------------------------- ### Get Prompt Handler Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Handles requests to get prompts, specifically the 'summarize_notes' prompt. It embeds provided notes as resources and constructs a multi-part message for summarization. ```APIDOC ## Get Prompt Handler ### Description Handles requests to get prompts, specifically the 'summarize_notes' prompt. It embeds provided notes as resources and constructs a multi-part message for summarization. ### Method POST ### Endpoint /getPrompt ### Parameters #### Request Body - **params.name** (string) - Required - Prompt name (e.g., `summarize_notes`) ### Response #### Success Response (200) - **messages** (Array) - An array of message objects, each with a role and content. - **role** (string) - The role of the message sender (e.g., "user"). - **content** (object) - The content of the message, which can be text or a resource. - **type** (string) - The type of content, either "text" or "resource". - **text** (string) - Optional - The text content of the message. - **resource** (object) - Optional - The resource content of the message. - **uri** (string) - The URI of the resource. - **mimeType** (string) - The MIME type of the resource. - **text** (string) - The text content of the resource. ### Request Example ```json { "params": { "name": "summarize_notes" } } ``` ### Response Example (with 2 notes) ```json { "messages": [ { "role": "user", "content": { "type": "text", "text": "Please summarize the following notes:" } }, { "role": "user", "content": { "type": "resource", "resource": { "uri": "note:///1", "mimeType": "text/plain", "text": "This is note 1" } } }, { "role": "user", "content": { "type": "resource", "resource": { "uri": "note:///2", "mimeType": "text/plain", "text": "This is note 2" } } }, { "role": "user", "content": { "type": "text", "text": "Provide a concise summary of all the notes above." } } ] } ``` ### Error Handling #### Unknown prompt name - **Condition**: Unknown prompt name - **Error Message**: "Unknown prompt" ``` -------------------------------- ### Data Model and Default Notes Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Defines the structure for a 'Note' object and initializes a collection of notes. This example uses in-memory storage for notes. ```typescript type Note = { title: string; content: string }; const notes: { [id: string]: Note } = { "1": { title: "First Note", content: "This is note 1" }, "2": { title: "Second Note", content: "This is note 2" } }; ``` -------------------------------- ### Example Response Structure for Summarization Prompt Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md This JSON structure represents a typical response from the summarization prompt handler. It includes an initial instruction, embedded notes as resources, and a final instruction for the AI. ```json { "messages": [ { "role": "user", "content": { "type": "text", "text": "Please summarize the following notes:" } }, { "role": "user", "content": { "type": "resource", "resource": { "uri": "note:///1", "mimeType": "text/plain", "text": "This is note 1" } } }, { "role": "user", "content": { "type": "resource", "resource": { "uri": "note:///2", "mimeType": "text/plain", "text": "This is note 2" } } }, { "role": "user", "content": { "type": "text", "text": "Provide a concise summary of all the notes above." } } ] } ``` -------------------------------- ### NPM Integration: Using npx Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md Illustrates how to use the create-server tool via npx, specifying the target directory and optional parameters. ```bash npx @modelcontextprotocol/create-server [options] ``` -------------------------------- ### Reinstall Create Server Package Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md If you encounter an 'Invalid template error', it may indicate a corrupted installation of the create-server package. Reinstalling the package globally using 'npm install -g @modelcontextprotocol/create-server' can resolve this issue. ```bash npm install -g @modelcontextprotocol/create-server ``` -------------------------------- ### Check Generated Server Files Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md After creating a server, verify the generated files and directory structure. Use 'ls -la' to list all files and directories, and 'cat', 'head' to inspect the content of specific files like package.json, tsconfig.json, and the main index file. ```bash # List generated structure ls -la my-server/ ``` ```bash # Check specific files cat my-server/package.json ``` ```bash cat my-server/tsconfig.json ``` ```bash head -20 my-server/src/index.ts ``` -------------------------------- ### Test Server Creation Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/CONTRIBUTING.md Test your changes by creating a new server using the built project. This command is used to verify that your modifications function correctly. ```bash ./build/index.js test-server ``` -------------------------------- ### Create MCP Server with Interactive Prompts Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md Use this command to initiate the creation of a new MCP server project. The tool will prompt you for project name and description. ```bash npx @modelcontextprotocol/create-server my-server ``` -------------------------------- ### Template Context Usage Example Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/types.md Illustrates how to access the 'name' and 'description' fields from the TemplateContext within an EJS template. This shows direct variable interpolation. ```ejs // In EJS templates: <%= name %> // → "my-server" <%= description %> // → "Weather data provider" ``` -------------------------------- ### Create Server on Linux (No Claude Integration) Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md Command to create a server on Linux when Claude desktop integration is not available. This bypasses Claude registration. ```bash # On Linux, Claude Desktop integration is not available # Create server normally (without Claude registration) npx @modelcontextprotocol/create-server my-server # Respond "no" to Claude installation prompt # (prompt will not appear on Linux anyway) ``` -------------------------------- ### Create Server in Programmatic Mode Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Use this when all server configuration options (name, description, installForClaude) are known and can be provided directly. This bypasses user prompts for automated server creation. ```typescript import { createServer } from './index.js'; await createServer('/home/user/weather-server', { name: 'weather-mcp', description: 'Weather data provider for MCP', installForClaude: true }); // No prompts; creates server directly ``` -------------------------------- ### Node.js Version Compatibility Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/types.md The project targets Node.js types starting from version 20.11.24, as specified in package.json. Types are compatible with Node.js 20.11.24 and later. ```json { "@types/node": "^20.11.24" } ``` -------------------------------- ### createServer(directory: string, options?: CreateServerOptions): Promise Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md Main function that orchestrates the entire server creation workflow. This function handles directory creation, template rendering, and optional registration with Claude Desktop. ```APIDOC ## createServer(directory: string, options?: CreateServerOptions) ### Description Main function that orchestrates the entire server creation workflow. ### Signature ```typescript async function createServer(directory: string, options?: { name?: string; description?: string; installForClaude?: boolean; }): Promise ``` ### Parameters #### Path Parameters - **directory** (string) - Required - Directory path to create the server in #### Query Parameters - **options** (object) - Optional - Configuration options - **name** (string) - Optional - Server name (skips prompt if provided) - **description** (string) - Optional - Server description (skips prompt if provided) - **installForClaude** (boolean) - Optional - Whether to register with Claude Desktop (macOS/Windows only) ### Returns - `Promise` — Resolves when server is fully created ### Behavior 1. Validates that target directory does not already exist 2. Prompts for server metadata if not provided in options 3. Creates the target directory 4. Copies template files from `template/` directory 5. Renders EJS templates with server configuration 6. Handles special `dotfile-*` prefixed files (converts to hidden files) 7. Optionally updates Claude Desktop configuration 8. Displays next steps in cyan text 9. Shows success/failure messages with appropriate coloring ### Throws - `process.exit(1)` if directory exists before creation - `process.exit(1)` if any error occurs during creation ### Usage ```typescript import { createServer } from './index.js'; // With options (non-interactive) await createServer('/path/to/my-server', { name: 'my-mcp-server', description: 'My custom MCP implementation', installForClaude: true }); // With prompts (interactive) await createServer('/path/to/my-server'); ``` ``` -------------------------------- ### Create a New MCP Server Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/README.md Use this command to scaffold a new MCP server project in a specified directory. Options can be provided to customize the server's name and description. ```bash # Create a new server in the directory `my-server` npx @modelcontextprotocol/create-server my-server # With options npx @modelcontextprotocol/create-server my-server --name "My MCP Server" --description "A custom MCP server" ``` -------------------------------- ### Get Claude Configuration Directory (TypeScript) Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md Determines the platform-specific Claude configuration directory. Throws an error if the APPDATA environment variable is not set on Windows or if running on an unsupported OS. ```typescript import { getClaudeConfigDir } from './index.js'; const configDir = getClaudeConfigDir(); console.log(configDir); // ~/.../Claude ``` -------------------------------- ### User Instruction: Handle Failed to Create MCP Server Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md Command-line instructions for users to diagnose and resolve issues related to failed MCP server creation, including checking permissions, disk space, and parent directory existence. ```bash # Check permissions on parent directory ls -ld /path/to # Check disk space df -h # Try with different path if permissions issue npx @modelcontextprotocol/create-server ~/my-server # Check if parent directory exists mkdir -p /path/to npx @modelcontextprotocol/create-server /path/to/my-server ``` -------------------------------- ### Examples of Invalid EJS Templates Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md Demonstrates common EJS syntax errors, including unclosed tags, typos in variable names, and JavaScript errors within template tags. ```ejs <%= name ``` ```ejs <%= nam %> ``` ```ejs <% 1 / 0 %> ``` -------------------------------- ### Create MCP Server with Options Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/REFERENCE.md This command creates a new MCP server project and allows you to specify custom options such as the server name and description. ```bash npx @modelcontextprotocol/create-server my-server \ --name "my-server" \ --description "A custom MCP server" ``` -------------------------------- ### Build Project Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/CONTRIBUTING.md Build the project to generate the necessary output files. This is required before running development commands or submitting changes. ```bash npm run build ``` -------------------------------- ### Create Server with Partial Options Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Use this when some server configuration options are known, but others need to be prompted from the user. The function will only ask for the missing required values. ```typescript import { createServer } from './index.js'; await createServer('/home/user/my-server', { name: 'my-custom-server' // Will prompt for description and Claude installation }); ``` -------------------------------- ### Validate Generated TypeScript Compilation Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md Navigate into the generated server directory, install dependencies, and run the build script. The TypeScript compilation process ('npm run build') will catch syntax errors in the generated TypeScript code. ```bash cd my-server npm install npm run build # TypeScript compilation will catch syntax errors ``` -------------------------------- ### Test Server with MCP Inspector Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Launches the MCP Inspector tool to interactively test the built server. ```bash npm run inspector build/index.js ``` -------------------------------- ### CLI Entry Point with Commander.js Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md This snippet shows how to configure the Commander.js instance for the CLI entry point, defining the command name, description, arguments, and options. ```typescript const program = new Command() .name("create-mcp-server") .description("Create a new MCP server") .argument("", "Directory to create the server in") .option("-n, --name ", "Name of the server") .option("-d, --description ", "Description of the server") .action(createServer); program.parse(); ``` -------------------------------- ### Create MCP Server with Explicit Options Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md This command creates a new MCP server project while specifying the server name and description directly as arguments. This bypasses interactive prompts for these specific fields. ```bash npx @modelcontextprotocol/create-server my-server --name "My MCP Server" --description "Custom MCP implementation" ``` -------------------------------- ### Build System Commands Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/REFERENCE.md Commands for compiling, watching, and preparing the TypeScript project for publishing. The output is placed in the `build/` directory. ```bash npm run build # Compile TypeScript to build/ npm run watch # Watch mode for development npm run prepare # Pre-publish hook (runs build) ``` -------------------------------- ### Globally Link Server Binary Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/README.md Optional command to make the created server binary globally available on your system. ```bash # optional npm link # Make your server binary globally available ``` -------------------------------- ### createServer() Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Orchestrates the creation of a complete MCP server project scaffold. It validates the target directory, collects configuration, processes EJS templates, and sets up the project structure. ```APIDOC ## createServer() ### Description Main orchestration function that creates a complete MCP server project scaffold. ### Signature ```typescript async function createServer( directory: string, options?: { name?: string; description?: string; installForClaude?: boolean; } ): Promise ``` ### Parameters #### Path Parameters - **directory** (string) - Required - Target directory path for the new server project #### Query Parameters - **options** (object) - Optional - Configuration object (all fields optional) - **options.name** (string) - Optional - MCP server name; if provided, skips prompt - **options.description** (string) - Optional - MCP server description; if provided, skips prompt - **options.installForClaude** (boolean) - Optional - Whether to register with Claude Desktop (macOS/Windows only) ### Return Type **Type:** `Promise` Returns a promise that resolves when the server project has been successfully created. Rejects only on fatal errors. ### Behavior The function executes the following steps: 1. **Validate directory:** Checks if target directory exists; exits with code 1 if it does 2. **Collect configuration:** Prompts for missing values (name, description, Claude installation) 3. **Create directory:** Creates the target directory 4. **Read templates:** Scans the `template/` directory for all files (recursively) 5. **Process each template file:** - Special handling for `dotfile-*` prefixed files (converts to hidden files with `.` prefix) - Removes `.ejs` extension from filenames - Creates subdirectories as needed - Reads template content as UTF-8 string - Renders template using EJS with configuration object - Writes processed content to target location 6. **Show success message:** Displays "MCP server created successfully!" with green coloring 7. **Update Claude config:** If `installForClaude` is true, calls `updateClaudeConfig()` 8. **Display next steps:** Shows user instructions with cyan coloring 9. **Handle errors:** Catches any errors, shows failure message, and exits with code 1 ### Template Variables All EJS templates receive this context object: ```typescript { name: string, description: string } ``` ### Error Conditions - Target directory exists: Logs red error and exits with code 1 - File read error during template copy: Logs error and exits with code 1 - File write error during template processing: Logs error and exits with code 1 - EJS rendering error: Logs error and exits with code 1 - Directory creation error: Logs error and exits with code 1 ### Prompt Questions If configuration values are not provided via options: - **Server Name:** Shown when `!options.name`. Default: `path.basename(directory)` - **Server Description:** Shown when `!options.description`. Default: `"A Model Context Protocol server"` - **Claude Installation:** (macOS/Windows only) Shown when `os.platform() === "darwin" || os.platform() === "win32"`. Default: `true` ### Output Messages - **Success (green):** `✓ MCP server created successfully!` followed by next steps. - **Failure (red):** `Failed to create MCP server` with error details. - **Claude registration success (green):** `✓ Successfully added MCP server to Claude.app configuration` - **Claude registration warning (yellow):** `Note: Could not update Claude.app configuration` ### Generated File Structure - `/package.json` - `/tsconfig.json` - `/.gitignore` - `/README.md` - `/src/index.ts` ### Generated Content - **package.json template variables:** `<%= name %>`, `<%= description %>` - **src/index.ts template variables:** `<%= name %>` ``` -------------------------------- ### Project Build and Watch Commands Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md Commands for building the TypeScript project, enabling watch mode for development, and preparing for publish. ```bash npm run build # Compile TypeScript and make executable ``` ```bash npm run watch # Watch mode for development ``` ```bash npm run prepare # Runs before publish (calls build) ``` -------------------------------- ### createServer Function Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Creates a new MCP server project at the specified path. It can be used interactively, programmatically with all options, or with partial options where missing values are prompted. ```APIDOC ## createServer ### Description Creates a new MCP server project. This function can be used in interactive mode, programmatic mode with all options specified, or with partial options where missing values will be prompted. ### Signature ```typescript createServer(serverPath: string, options?: { name?: string; description?: string; installForClaude?: boolean; }): Promise ``` ### Parameters #### Path Parameter - **serverPath** (string) - Required - The file system path where the new MCP server project will be created. #### Options Object - **name** (string) - Optional - The name of the server project. If not provided, it may be prompted for. - **description** (string) - Optional - A description for the server project. If not provided, it may be prompted for. - **installForClaude** (boolean) - Optional - Whether to register the server with Claude Desktop. If not provided, it may be prompted for. ### Usage Examples #### Interactive mode (prompts user) ```typescript import { createServer } from './index.js'; await createServer('/home/user/my-mcp-server'); // Prompts for name, description, Claude installation ``` #### Programmatic mode (all options provided) ```typescript import { createServer } from './index.js'; await createServer('/home/user/weather-server', { name: 'weather-mcp', description: 'Weather data provider for MCP', installForClaude: true }); // No prompts; creates server directly ``` #### Partial options (prompts for missing values) ```typescript import { createServer } from './index.js'; await createServer('/home/user/my-server', { name: 'my-custom-server' // Will prompt for description and Claude installation }); ``` ``` -------------------------------- ### User Instruction: Handle Directory Already Exists Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md Command-line instructions for users to resolve the 'Directory Already Exists' error by specifying a new directory name or manually removing the existing one. ```bash # Choose a different directory name npx @modelcontextprotocol/create-server different-name # Or manually remove the existing directory rm -rf existing-directory npx @modelcontextprotocol/create-server existing-directory ``` -------------------------------- ### Successful Server Creation Output Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md These messages are displayed upon successful creation of the MCP server, indicating the next steps for the user. Success messages are green, next steps are cyan, and optional notes are yellow. ```bash ✓ MCP server created successfully! Next steps: cd my-server npm install npm run build # or: npm run watch npm link # optional, to make available globally ``` -------------------------------- ### Prompt for Server Description Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md This prompt is displayed when the server description is not provided via the --description option. The default value is "A Model Context Protocol server". ```bash ? What is the description of your server? ``` -------------------------------- ### Test Generated MCP Server Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/REFERENCE.md After building your MCP server project, use these commands to run the build process and then launch the MCP Inspector for interactive testing. The inspector will be available at http://localhost:3000. ```bash cd my-server npm run build npm run inspector build/index.js ``` -------------------------------- ### Create MCP Server (TypeScript) Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md Orchestrates the server creation workflow, including directory validation, metadata prompting, file copying, EJS template rendering, and optional Claude Desktop integration. Exits with an error code if the target directory exists or if any creation error occurs. ```typescript import { createServer } from './index.js'; // With options (non-interactive) await createServer('/path/to/my-server', { name: 'my-mcp-server', description: 'My custom MCP implementation', installForClaude: true }); // With prompts (interactive) await createServer('/path/to/my-server'); ``` -------------------------------- ### Execute Server Directly Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Runs the compiled server directly using Node.js on stdio. ```bash node build/index.js ``` -------------------------------- ### Handling Existing Directories Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md When a directory with the same name already exists, you can either choose a new name for your server, remove the old directory, or provide all necessary options to the command to avoid interactive prompts. ```bash # Option 1: Use a different name npx @modelcontextprotocol/create-server my-server-2 # Option 2: Remove old directory rm -rf my-server npx @modelcontextprotocol/create-server my-server # Option 3: Provide all options to avoid interactive errors npx @modelcontextprotocol/create-server my-server \ --name "my-server" \ --description "A new server" ``` -------------------------------- ### List Tools Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Provides a list of available tools that can be used. Each tool includes its name, description, and the schema for its input. ```APIDOC ## List Tools ### Description Returns a list of available tools, including their names, descriptions, and input schemas. ### Method POST (inferred from setRequestHandler) ### Endpoint (Not explicitly defined, inferred from schema) ### Request Body No parameters required. ### Response #### Success Response (200) - **tools** (Array<{ name: string; description: string; inputSchema: object; }>) - **name** (string) - The name of the tool (e.g., `create_note`). - **description** (string) - A description of what the tool does. - **inputSchema** (object) - The JSON schema defining the expected input for the tool. ### Response Example ```json { "tools": [ { "name": "create_note", "description": "Create a new note", "inputSchema": { "type": "object", "properties": { "title": { "type": "string", "description": "Title of the note" }, "content": { "type": "string", "description": "Text content of the note" } }, "required": ["title", "content"] } } ] } ``` ``` -------------------------------- ### List Resources Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Retrieves a list of available resources. This handler enumerates all notes and formats them into resource entries with URIs, MIME types, names, and descriptions. ```APIDOC ## List Resources ### Description Enumerates all notes in the `notes` object and returns them as a list of resources. ### Method POST (inferred from setRequestHandler) ### Endpoint (Not explicitly defined, inferred from schema) ### Request Body No parameters required. ### Response #### Success Response (200) - **resources** (Array<{ uri: string; mimeType: string; name: string; description: string; }>) - A list of resource objects. - **uri** (string) - The unique identifier for the resource (e.g., `note:///1`). - **mimeType** (string) - The MIME type of the resource (e.g., `"text/plain"`). - **name** (string) - The name or title of the resource. - **description** (string) - A brief description of the resource. ### Response Example ```json { "resources": [ { "uri": "note:///1", "mimeType": "text/plain", "name": "First Note", "description": "A text note: First Note" } ] } ``` ``` -------------------------------- ### Update Claude Desktop Configuration (TypeScript) Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md Updates the Claude Desktop application configuration to register an MCP server. Reads or creates the configuration file, prompts if a server name already exists, and adds the server with a command pointing to `build/index.js`. Failures are logged as warnings. ```typescript import { updateClaudeConfig } from './index.js'; await updateClaudeConfig('my-server', '/home/user/my-server'); // Configuration updated in Claude Desktop ``` -------------------------------- ### Clone Repository Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/CONTRIBUTING.md Clone your fork of the create-typescript-server repository to your local machine. ```bash git clone https://github.com/YOUR_USERNAME/create-typescript-server.git ``` -------------------------------- ### Manual Configuration for Claude Desktop App Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md This bash command and JSON structure shows how to manually edit the Claude desktop application's configuration file to add your MCP server. This is an alternative to programmatic updates. ```bash # Manual configuration: edit Claude settings file # macOS ~/Library/Application\ Support/Claude/claude_desktop_config.json # Windows %APPDATA%\Claude\claude_desktop_config.json # Add your server manually: { "mcpServers": { "my-server": { "command": "node", "args": ["/absolute/path/to/build/index.js"] } } } ``` -------------------------------- ### TypeScript Implementation: getClaudeConfigDir Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Provides the implementation for getClaudeConfigDir, handling macOS and Windows platforms, and throwing errors for unsupported OS or missing environment variables. ```typescript function getClaudeConfigDir(): string { switch (os.platform()) { case "darwin": return path.join( os.homedir(), "Library", "Application Support", "Claude", ); case "win32": if (!process.env.APPDATA) { throw new Error("APPDATA environment variable is not set"); } return path.join(process.env.APPDATA, "Claude"); default: throw new Error( `Unsupported operating system for Claude configuration: ${os.platform()}`, ); } } ``` -------------------------------- ### Generated Project Structure Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md The file structure created after a successful execution of the CLI command for a project named 'my-server'. ```bash my-server/ package.json tsconfig.json .gitignore README.md src/ index.ts ``` -------------------------------- ### List Prompts Handler Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Handles requests to list available prompts on the server. It returns a list of prompts, each with a name and description. ```APIDOC ## POST /list-prompts ### Description Retrieves a list of all available prompts that can be executed on the server. ### Method POST ### Endpoint /list-prompts ### Parameters No parameters are required for this request. ### Request Example ```json { "params": {} } ``` ### Response #### Success Response (200) - **prompts** (Array<{ name: string; description: string; }>) - A list of available prompts, where each prompt has a name and a description. #### Response Example ```json { "prompts": [ { "name": "summarize_notes", "description": "Summarize all notes" } ] } ``` ``` -------------------------------- ### Default Project Directory Structure Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/configuration.md The generated project follows a fixed directory structure. This structure is determined by template files and cannot be overridden by configuration options. ```plaintext / ├── package.json ├── tsconfig.json ├── .gitignore ├── README.md └── src/ └── index.ts ``` -------------------------------- ### package.json Configuration Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/configuration.md The default package.json file for a generated project. It includes essential metadata, build scripts, and dependencies. ```json { "name": "", "version": "0.1.0", "description": "", "private": true, "type": "module", "bin": { "": "./build/index.js" }, "files": ["build"], "scripts": { "build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"", "prepare": "npm run build", "watch": "tsc --watch", "inspector": "npx @modelcontextprotocol/inspector build/index.js" }, "dependencies": { "@modelcontextprotocol/sdk": "0.6.0" }, "devDependencies": { "@types/node": "^20.11.24", "typescript": "^5.3.3" } } ``` -------------------------------- ### Register Multiple Servers with Claude Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md Iterates through a list of servers and registers each one with Claude Desktop using updateClaudeConfig(). ```typescript import { updateClaudeConfig } from './index.js'; const servers = [ { name: 'weather-server', path: '/path/to/weather-server' }, { name: 'database-server', path: '/path/to/database-server' }, ]; for (const server of servers) { await updateClaudeConfig(server.name, server.path); } ``` -------------------------------- ### updateClaudeConfig(name: string, directory: string): Promise Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/index.md Updates the Claude Desktop application configuration to register a newly created MCP server. This allows Claude Desktop to recognize and launch your server. ```APIDOC ## updateClaudeConfig(name: string, directory: string) ### Description Updates the Claude Desktop application configuration to register the newly created MCP server. ### Signature ```typescript async function updateClaudeConfig(name: string, directory: string): Promise ``` ### Parameters #### Path Parameters - **name** (string) - Required - Name of the MCP server to register - **directory** (string) - Required - Absolute path to the MCP server project directory ### Returns - `Promise` — Resolves when configuration is updated ### Behavior - Reads existing `claude_desktop_config.json` if it exists - Creates configuration file and directories if they don't exist - Prompts user if a server with the same name already exists - Adds or replaces the server configuration with command `node` and args pointing to `build/index.js` - Silently catches failures if Claude configuration cannot be accessed ### Throws - No exceptions are thrown; failures are caught and logged as yellow warnings ### Usage ```typescript import { updateClaudeConfig } from './index.js'; await updateClaudeConfig('my-server', '/home/user/my-server'); // Configuration updated in Claude Desktop ``` ``` -------------------------------- ### Command Definition Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/cli-command.md Defines the create-mcp-server CLI command, including its name, description, required directory argument, and optional name and description flags. ```typescript new Command() .name("create-mcp-server") .description("Create a new MCP server") .argument("", "Directory to create the server in") .option("-n, --name ", "Name of the server") .option("-d, --description ", "Description of the server") .action(createServer) ``` -------------------------------- ### MCP Server Project Structure Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/REFERENCE.md The generated project includes essential files for an MCP server, such as package.json, tsconfig.json, and the main server logic in src/index.ts. ```text / ├── package.json # npm manifest ├── tsconfig.json # TypeScript config ├── .gitignore # git ignore patterns ├── README.md # Auto-generated readme └── src/ └── index.ts # Boilerplate MCP server ``` -------------------------------- ### CreateServerOptions Type Definition Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/types.md Defines the optional configuration parameters for the createServer function. These options control server naming, description, and Claude Desktop integration. ```typescript interface CreateServerOptions { name?: string; description?: string; installForClaude?: boolean; } ``` -------------------------------- ### Troubleshooting Claude Configuration on Windows Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/errors.md If Claude configuration fails on Windows, check APPDATA permissions and the validity of the JSON configuration file. Back up the configuration file before making manual edits. ```powershell # Verify APPDATA is set echo $env:APPDATA # Check file permissions Get-Item -Force $env:APPDATA\Claude\claude_desktop_config.json # Manually edit the file (backup first!) Copy-Item $env:APPDATA\Claude\claude_desktop_config.json ` $env:APPDATA\Claude\claude_desktop_config.json.bak # Edit with notepad notepad $env:APPDATA\Claude\claude_desktop_config.json # Validate JSON before saving ``` -------------------------------- ### Generated File Structure Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/api-reference/functions.md This outlines the typical file structure generated for a new MCP server project, including configuration files, source code, and documentation. ```bash / ├── package.json # Project manifest with dependencies and scripts ├── tsconfig.json # TypeScript compiler configuration ├── .gitignore # Git ignore patterns ├── README.md # Auto-generated readme └── src/ └── index.ts # Boilerplate MCP server with example resources, tools, prompts ``` -------------------------------- ### Server Options Interface Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/types.md Defines the configuration options for a server, including its name and version. These types are part of the MCP SDK. ```typescript interface ServerOptions { name: string; version: string; } interface ServerCapabilities { resources: {}; tools: {}; prompts: {}; } ``` -------------------------------- ### Call Tool Handler (create_note) Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Handles requests to call tools, specifically the 'create_note' tool for adding new notes to the system. It validates input and returns a confirmation message. ```APIDOC ## POST /call-tool ### Description Handles requests to create a new note with a given title and content. It validates the input and returns a success message with the ID of the created note. ### Method POST ### Endpoint /call-tool ### Parameters #### Request Body - **params.name** (string) - Required - Tool name (e.g., `create_note`) - **params.arguments.title** (string) - Required - Note title - **params.arguments.content** (string) - Required - Note content ### Request Example ```json { "params": { "name": "create_note", "arguments": { "title": "Shopping List", "content": "- Milk\n- Eggs\n- Bread" } } } ``` ### Response #### Success Response (200) - **content** (Array<{ type: "text"; text: string; }>) - An array containing a text message confirming the note creation. #### Response Example ```json { "content": [ { "type": "text", "text": "Created note 3: Shopping List" } ] } ``` ### Error Handling - **Condition**: Missing title or content **Error Message**: "Title and content are required" - **Condition**: Unknown tool name **Error Message**: "Unknown tool" ``` -------------------------------- ### List Prompts Handler Source: https://github.com/modelcontextprotocol/create-typescript-server/blob/main/_autodocs/generated-template.md Handles requests to list available prompts. It returns a predefined list of prompts, each with a name and description. Ensure 'ListPromptsRequestSchema' is imported. ```typescript server.setRequestHandler(ListPromptsRequestSchema, async () => { return { prompts: [ { name: "summarize_notes", description: "Summarize all notes", } ] }; }); ```