Connect Cursor to an MCP Server
This guide explains how to connect an MCP server to Cursor, enabling you to interact with your API using natural language directly from your development environment.
You can connect Cursor to:
- A locally generated MCP server created with liblab.
- A publicly deployed MCP server accessible via a URL.
Before You Start
Before connecting Cursor to your MCP server, make sure you have:
- The Cursor editor installed and running.
- One of the following:
- A local MCP server generated with liblab CLI.
- A publicly deployed MCP server URL generated on your liblab dashboard.
To learn more about how MCP works, visit the MCP Concept page.
Connect Cursor 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.
-
Open Cursor Desktop and go to Settings > Developer > Edit Config.
-
Select MCP Tools and click Add Custom MCP. Cursor will open the
mcp.json
file. -
Add your MCP server configuration using the hosted MCP URL. Replace the placeholder URL (
https://mcp.liblab.com/liblab-dev
) and environment variable with your actual values. Save and close themcp.json
file.mcp.json{
"mcpServers": {
"liblab": {
"type": "url",
"url": "https://mcp.liblab.com/liblab-dev"
},
}
}
} -
Cursor will fetch the MCP Tool and list them indicating the connection was sucessfull.
-
Once connected, you can chat with your API using natural language right inside Cursor. Cursor will ask your permission before performing any request to the MCP.
Add Environment Variables for Authentication
If your MCP requires authentication—such as an API key, you can set environment variables that Cursor 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:
- Start a new chat using Cursor using the previously connected MCP.
- Ask Cursor 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>
Cursor 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 Cursor to a Local MCP Server
Use this method if you’re running the MCP server locally, generated from an OpenAPI spec using liblab CLI.
If you haven’t yet generated your MCP server, follow the Generate an MCP Server with liblab CLI guide.
After generating the MCP server using liblab CLI, run the setup and start the local server:
cd output/mcp
npm run setup
Now, you need to update Cursor's settings:
-
Open Claude Desktop and go to Settings > Developer > Edit Config.
-
Select MCP Tools and click Add Custom MCP. Cursor will open the
mcp.json
file. -
Add your MCP server configuration using the hosted MCP URL. Replace the placeholder URL and environment variable with your actual values. Save and close the
mcp.json
file.mcp.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 authenticationMake sure to use the correct environment variable name expected by your API.
-
Cursor will start the local MCP server and get the tool available, listing them to indicate the connection was sucessfull.
-
Once connected, you can chat with your API using natural language right inside Cursor. Cursor will ask your permission before performing any request to the MCP.
Next Steps
To continue working with MCP and Cursor, check out the following resources: