Skip to main content

Connect Claude to an MCP Server

This guide explains how to connect an MCP server to Claude, enabling you to interact with your API using natural language.

You can connect Claude to:

  • A locally generated MCP server created with liblab.
  • A publicly deployed MCP server accessible via a URL.

Before You Start

Before you connect Claude to your MCP server, ensure you have:

  • Access to Claude (Claude Desktop).
  • One of the following:
tip

To learn more about how MCP works, visit the MCP Concept page.

Connect Claude to a Remote MCP Server

Use this method if your MCP server is deployed and accessible over the internet through an URL. If you generated your MCP server using the liblab hosting service, use this option.

  1. Open Claude Desktop.

  2. In the settings, go to Developer and click Edit Config. This will open the claude_desktop_config.json file.

    Claude Desktop developer settings

  3. Add your MCP server configuration using the hosted MCP URL. Replace the placeholder URL (https://mcp.liblab.com/liblab-dev) with your actual values.

    claude_desktop_config.json
    {
    "mcpServers": {
    "liblab": {
    "command": "npx",
    "args": [
    "mcp-remote",
    "https://mcp.liblab.com/liblab"
    ]
    }
    }
    }
  4. Save the file, close and reopen Claude Desktop to reload the configuration.

  5. Start a new chat and test your API integration.

Add Environment Variables for Authentication

If your MCP requires authentication—such as an API key, you can set environment variables that Claude will use when making requests to your API. This is done by restarting the MCP using the restart_sdk tool, a built-in utility available in all MCPs generated by liblab.

To set a new environment variable:

  1. Start a new chat using Claude using the previously connected MCP.
  2. Ask Claude to restart the MCP and provide the environment variable and its value.

Here’s an example where an API key is passed as an environment variable. Note that the variable name (e.g. apiKey) and value format depend on the specific API used to generate the MCP:

restart the mcp and use the apiKey:<your-api-key>

Claude will recognize the intent to use the restart_sdk tool and apply the environment variable. All future requests will then include this authentication data.

Connect Claude to a Remote MCP Server

Use this method if your MCP server is deployed and accessible over the internet through a URL. If you generated your MCP server using the liblab hosting service, use this option.

  1. Open Claude Desktop.

  2. In the settings, go to Developer and click Edit Config. This will open the claude_desktop_config.json file.

    Claude Desktop developer settings

  3. Add your MCP server configuration using the hosted MCP URL. Replace the placeholder URL (https://mcp.liblab.com/liblab-dev) with your actual values.

    claude_desktop_config.json
    {
    "mcpServers": {
    "liblab": {
    "command": "npx",
    "args": [
    "mcp-remote",
    "https://mcp.liblab.com/liblab"
    ]
    }
    }
    }
  4. Save the file, close and reopen Claude Desktop to reload the configuration.

  5. Start a new chat and test your API integration.

Add Environment Variables for Authentication

If your MCP requires authentication—such as an API key—you can set environment variables that Claude will use when making requests to your API. This is done by restarting the MCP using the restart_sdk tool, a built-in utility available in all MCPs generated by liblab.

To set a new environment variable:

  1. Start a new chat in Claude using the previously connected MCP.
  2. Ask Claude to restart the MCP and provide the environment variable and its value.

Here’s an example where an API key is passed as an environment variable. Note that the variable name (e.g. apiKey) and value format depend on the specific API used to generate the MCP:

restart the mcp and use the apiKey:<your-api-key>

Claude will recognize the intent to use the restart_sdk tool and apply the environment variable. All future requests will then include this authentication data.

Connect Claude to a Local MCP Server

Use this method if you’re running the MCP server locally, generated from an OpenAPI spec using liblab CLI.

Generate your MCP server with liblab

If you haven’t yet generated your MCP server, follow the Generate an MCP Server with liblab CLI guide.

After generating the server using the liblab CLI, navigate to the output folder and run the setup script:

cd output/mcp
npm run setup

Now, you need to update Claude's configuration:

  1. Open Claude Desktop and go to Settings > Developer > Edit Config.

  2. Modify claude_desktop_config.json to point to the local MCP server file path:

    claude_desktop_config.json
    {
    "mcpServers": {
    "your-local-api": {
    "command": "node",
    "args": [
    "<path-to-liblab-generated-mcp-server>/output/mcp/dist/index.js"
    ],
    "env": {
    "YOUR_API_KEY": "<your-api-key>"
    }
    }
    }
    }
    MCP server authentication

    Make sure to use the correct environment variable name expected by your API.

  3. Save the file and restart Claude Desktop.

  4. Open a new conversation and test the integration.

    Using Exa MCP in Claude

Next Steps

To continue working with MCP and Claude, check out the following resources: