AI Workflows

Setting Up MCP in Cursor with Claude Desktop

Learn how to configure MCP in Cursor using Claude Desktop by following these step-by-step instructions.

4 min read

Learn how to configure MCP in Cursor using Claude Desktop by following these step-by-step instructions. This guide will cover everything from project setup to deployment and verification.

prerequisites

  • Claude Desktop application: Download and install the app from the official source.
  • Code editor: Install Cursor or another JavaScript-friendly editor like VS Code.
  • Node.js and TypeScript: Ensure Node.js (preferably LTS) and TypeScript are installed on your system.
    • Verify installations using node --version and tsc --version commands.

Creating the MCP Server Project

To get started, set up the project structure and ensure the necessary Node.js environment is ready.

steps

  1. Create a project directory:

    bash
    mkdir my-mcp-server
    cd my-mcp-server
  2. Initialize the project:

    bash
    npm init -y
  3. Install required dependencies:

    bash
    npm install typescript @openai/ai npm-run-all

Setting Up Server Files

With the initial setup complete, structure your project and configure essential files.

steps

  1. Create the project structure:

    bash
    mkdir src
    touch src/index.ts
  2. Configure package.json: Open package.json in your editor and update it with the following:

    json
    {
      "name": "my-mcp-server",
      "version": "1.0.0",
      "type": "module",
      "scripts": {
        "build": "tsc"
      },
      "files": ["build"]
    }
  3. Add a TypeScript configuration: Create a tsconfig.json file in the project’s root directory:

    json
    {
      "compilerOptions": {
        "target": "ES2020",
        "module": "ES2020",
        "outDir": "build",
        "rootDir": "src",
        "strict": true,
        "esModuleInterop": true,
        "moduleResolution": "node"
      },
      "include": ["src"]
    }

Coding Your MCP Server

Here, you will write the server logic to define tools and capabilities.

steps

  1. Set up index.ts in src: Write the following code to define your server:

    typescript
    import { createServer } from "@openai/ai";
    
    const server = createServer({
        name: "WeatherMCPServer",
        capabilities: {
            tools: {
                getWeather: {
                    description: "Fetch current weather for a location",
                    parameters: { location: { type: "string" } },
                    action: async (params) => {
                        // Dummy weather data
                        return { temperature: "72°F", location: params.location };
                    },
                },
            },
        },
    });
    
    server.listen().then(() => {
        console.log("MCP server is running.");
    });
  2. Add helper functions: If your tools require API calls or other logic, you may write functions within this file.

  3. Finalize the server: Ensure all code logic for your MCP tools, resources, and server metadata is implemented.

Building and Deploying the Server

Compile the TypeScript source and configure Claude Desktop.

steps

  1. Build the server:

    bash
    npm run build
  2. Copy the file path for deployment: Locate the generated build/index.js file and copy its absolute file path.

  3. Configure Claude Desktop:

    • Open Claude Desktop and go to Settings.
    • Enable Developer Mode.
    • Edit the claude_desktop_config.json file in the configuration interface.
    • Replace the mcp_server_path field with the absolute path to your index.js.
  4. Restart Claude Desktop: Close and reopen Claude Desktop to apply the changes.

  5. Verify the integration:

    • Open a chat in Claude Desktop.
    • Test your added MCP tools by querying them interactively in the chat interface.

FAQ

How do I fix errors in the Claude MCP integration?

Verify the mcp_server_path in the Claude configuration file and ensure the server tool keys in your code match exactly with the MCP JSON.

Can I run multiple MCP servers in Claude Desktop?

Yes, use unique tool names and different server paths for each MCP instance. Update the mcp_server_path for the desired server.

Why is my MCP server not responding to requests in Claude Desktop?

Ensure the server is running, the build process is complete, and the correct path to index.js is configured in Claude Desktop. Restart the app to apply changes.


Official reference: Claude documentation.