AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring Model Context Protocol (MCP) in Cursor: Connect Databases and Custom APIs

Lara Jorge Ricart · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Software engineers using Cursor often encounter a hard context ceiling: while Cursor Agent and Composer navigate local files, generate diffs, and refactor codebases with high precision, they remain blind to live runtime state. An agent editing an ORM schema cannot verify whether a database migration matches the actual PostgreSQL schema, inspect live table indexes, or fetch payload specs from an internal microservice gateway.

Cursor solves this context-silo problem through native support for the Model Context Protocol (MCP). By configuring MCP servers, developers grant Cursor’s AI models direct, programmatic access to databases, cloud infrastructure, and private APIs through standardized tool calls.


The Core Problem: Breaking Beyond Local File Boundaries

Modern software engineering requires continuous interaction with systems outside the file tree:

MCP establishes a universal, JSON-RPC-based protocol between Cursor (the client) and external tools (the servers). When configured, Cursor Agent autonomously inspects available MCP tools, decides when to trigger them, executes queries or API requests, and incorporates structured JSON responses directly into its multi-step reasoning.


Configuration Architecture: Global vs. Project-Level Scope

Cursor supports two distinct configuration locations for MCP servers:

ScopeFile PathTarget Use CaseVersion Control Strategy
Project-Level.cursor/mcp.json (Repository root)Team-wide shared databases; project-specific microservices; custom CI/CD scriptsCommit to Git; reference credentials via ${env:VARIABLE}
Global~/.cursor/mcp.json (User home directory)Personal developer utilities; local shell scripts; cross-project tools (e.g., GitHub, Slack)Exclude from Git; keep on individual developer workstation

365Finds Institutional Recommendation

365Finds strongly advises technical teams to standardize on project-level .cursor/mcp.json for database connectors and workspace APIs. Global UI configurations create invisible drift across engineering teams: one engineer's Cursor Agent effortlessly verifies database schemas while a teammate's agent fails because the local configuration is absent. By checking .cursor/mcp.json into repository version control and resolving sensitive keys through environment variables, the entire engineering team shares identical agent capabilities without leaking credentials.


Standard JSON Syntax: Local stdio vs. Remote sse

Cursor handles two primary transport mechanisms:

  1. stdio (Standard Input/Output): Cursor launches a local subprocess (via npx, uvx, python, or node) and communicates over standard I/O streams.
  2. sse (Server-Sent Events / HTTP): Cursor connects over HTTP/HTTPS to a running daemon or remote server endpoint.

1. Connecting a Custom Database via Local stdio

To connect a PostgreSQL instance, declare an entry inside the mcpServers object using the official PostgreSQL MCP server. You can use Node's npx or Python's uvx:

{
  "mcpServers": {
    "postgres-dev": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://app_user:${env:DEV_DB_PASSWORD}@localhost:5432/app_development"
      ]
    }
  }
}

If your tool requires dedicated runtime variables rather than inline CLI arguments, pass them in the env block:

{
  "mcpServers": {
    "postgres-staging": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "postgresql://readonly_user:${env:STAGING_DB_PASSWORD}@db.staging.internal:5432/analytics"
      }
    }
  }
}

2. Connecting Custom API Microservices via Remote sse / HTTP

When connecting Cursor to an organization-wide API tool, internal documentation daemon, or remote service, use the url property with authentication headers:

{
  "mcpServers": {
    "internal-api-gateway": {
      "url": "https://api-mcp.internal.company.net/sse",
      "headers": {
        "Authorization": "Bearer ${env:INTERNAL_MCP_TOKEN}",
        "X-Environment": "staging"
      }
    }
  }
}

3. Running Custom In-Repo Tools

If your team maintains internal automation scripts in Python or TypeScript, expose them directly from the project directory using Cursor's variable interpolation:

{
  "mcpServers": {
    "repo-debugger": {
      "command": "python3",
      "args": [
        "${workspaceFolder}/scripts/mcp_inspect_service.py"
      ],
      "env": {
        "API_ENDPOINT": "http://127.0.0.1:8080/api/v1"
      }
    }
  }
}

Security Guardrails: Safeguarding Secrets and Data Integrity

Connecting autonomous coding agents to live infrastructure introduces significant operational risks. 365Finds establishes two mandatory technical guardrails for teams implementing MCP in Cursor:

1. Never Hardcode Raw Credentials

Do not write raw database passwords or API keys directly into .cursor/mcp.json. Cursor natively interpolates environment variables from your shell session or local .env setup:

Add .env and any local credential files to your .gitignore.

2. Enforce Read-Only Database Connections

Cursor Agent and Composer possess autonomous execution loops. If an agent receives write permissions to a database, a hallucinated migration or troubleshooting prompt could trigger unexpected UPDATE or DROP TABLE statements.


Activating and Interacting with MCP in Cursor Agent & Composer

Once .cursor/mcp.json is saved in your repository:

Step 1: Verify Server Status

  1. Open Cursor and navigate to Cursor Settings (Cmd + , or Ctrl + ,).
  2. Select Features > MCP Servers (or Customize > Tools & MCP).
  3. Confirm that your declared server appears in the list with a green status indicator.
  4. Click the refresh icon to reload server tools or inspect the exact list of available tool schemas (such as query, list_tables, or describe_table).

Step 2: Prompting Composer and Chat

Cursor's Agent Mode automatically identifies when an MCP tool is relevant. You do not need complex manual syntax to trigger it. Simply prompt the agent with natural language:

"Check the schema of the users table via postgres-dev and generate an updated Prisma schema and TypeScript interface matching the actual column types."

When the agent decides to invoke an MCP tool:

  1. Cursor displays a tool call card in the Composer / Chat feed indicating the action and parameters.
  2. If human approval is required by your security policy, review the SQL statement or API payload and click Run.
  3. The server executes the request, returns the raw JSON payload to Cursor, and the agent synthesizes the code edits directly into your active workspace.

Operational Comparison

Architecture PatternTransportSetup OverheadCollaboration FitSecurity Posture
Local Stdio (npx / uvx)stdio via subprocessLow (zero server infrastructure required)High when using .cursor/mcp.json and ${env:VAR}Tied to local machine process; requires strict local DB permission isolation
Remote Gateway (sse)HTTP / Server-Sent EventsMedium (requires hosting an MCP daemon)Exceptional (centralized access control for entire org)Centralized token rotation and backend audit logging; zero client secret exposure
Custom Script (python / ts)stdio via local interpreterLow to MediumHigh (scripts versioned directly in repo)Depends on in-house script validation and sanitization

References