Cursor IDE MCP Integration, Workspace Rules & Agent Composer Guide
Complete developer reference for setting up Model Context Protocol servers in Cursor IDE, configuring workspace-level .cursor/mcp.json files, passing environment variables, and orchestrating multi-tool agent loops in Cursor Composer.
#1. Native Model Context Protocol Support in Cursor IDE
Cursor IDE features first-class native integration with the Model Context Protocol. Once an MCP server is registered in Cursor, its tools and parameter schemas automatically surface to Cursor Agent Composer (Cmd+I or Ctrl+I) and the background chat agent.
During interactive chat and background agent execution loops, Cursor's AI models (such as Claude 3.5 Sonnet, Claude 3.7 Sonnet, and GPT-4o) can autonomously invoke MCP tools to read file systems, query databases, trigger cloud APIs, and format code changes without requiring manual context switching.
The deep integration allows language models to dynamically inspect live system state, run targeted queries, and verify proposed edits against runtime database constraints before writing code.
#2. Cursor Composer Agent Execution Loop Architecture
When you prompt Cursor Composer with an operational task, the agent engages in an autonomous loop of tool selection, argument compilation, stdio dispatch, and result synthesis.
The following sequence architecture illustrates how Cursor Composer interfaces with registered MCP servers during an agentic coding task:
+--------------------------------------------------------------------+
| Cursor Composer Agent Execution Loop Architecture |
+--------------------------------------------------------------------+
| User Prompt: "@Composer Inspect slow queries on production DB" |
+--------------------------------------------------------------------+
|
v
+--------------------------------------------------------------------+
| Cursor Agent Planner Core |
| - Analyzes context & available tools from .cursor/mcp.json |
| - Selects 'query_database' tool from postgresql-mcp |
| - Compiles argument payload: { sql: "EXPLAIN ANALYZE SELECT..." } |
+--------------------------------------------------------------------+
|
| (JSON-RPC tools/call)
v
+--------------------------------------------------------------------+
| PostgreSQL MCP Server (Stdio) |
| - Validates query arguments against inputSchema |
| - Dispatches query to postgresql://... connection pool |
| - Returns execution plan & buffer timings to Cursor Composer |
+--------------------------------------------------------------------+
|
v
+--------------------------------------------------------------------+
| Autonomous Code Synthesis |
| - Ingests query execution plan into LLM context window |
| - Identifies sequential table scan bottleneck |
| - Generates optimized SQL migration and Prisma index definition |
+--------------------------------------------------------------------+#3. Global vs Project-Specific Configuration (.cursor/mcp.json)
Cursor allows developers to configure MCP servers at two distinct levels:
• Project-Specific Workspace Configuration: Create a .cursor/mcp.json file at the root of your repository. This configuration is automatically detected by Cursor whenever the project is opened, allowing teams to version-control standard tools for the repo.
• Global User Configuration: Configured via Cursor Settings -> Features -> MCP Servers. Global servers are active across all projects opened on your machine, ideal for personal utility servers like Git or note-taking tools.
{
"mcpServers": {
"supabase-db": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://postgres:secret@localhost:54322/postgres"
]
},
"github-mcp": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_workspace_token_here"
}
}
}
}#4. Invoking MCP Tools in Cursor Composer Prompts
Once registered, MCP tools can be invoked naturally in Cursor Composer prompts without special syntax. The AI model automatically selects tools based on your intent:
Example Directives for Cursor Composer:
• Database Inspection: '@Composer Query PostgreSQL for the top 5 failing background jobs and generate a TypeScript interface matching the database columns.'
• API Integration: '@Composer Use GitHub MCP to fetch open issues labeled bug:auth and summarize potential root causes based on local repository code.'
• File System Search: '@Composer Use filesystem tools to inspect all .env.example files across microservices and report missing environment variables.'
#5. Integrating MCP Tools with .cursorrules Enforcement
You can combine MCP servers with .cursorrules to instruct Cursor when and how to invoke specific tools during development sessions:
Add instructions to your .cursorrules file to guide tool selection, parameter constraints, and automated validation before file commits.
This ensures that models do not execute speculative queries or modify production tables without following established team workflows.
# .cursorrules MCP Integration Rules - When asked about database schema or table structures, ALWAYS use the supabase-db MCP server tools to inspect the active database rather than guessing schema types. - Before generating migration files, query current database constraints to prevent duplicate column or foreign key collisions. - Never execute DROP, TRUNCATE, or DELETE operations without explicit user confirmation in the chat prompt. - Always append LIMIT 50 to exploratory SELECT queries to avoid saturating context window token buffers.
#6. Multi-Server Tool Chaining & Workspace Variable Substitution
Cursor Composer excels at chaining operations across multiple MCP servers in a single prompt. For example, the agent can fetch an issue specification from GitHub MCP, inspect table structures using PostgreSQL MCP, generate a patch file, and verify syntax against local linters.
In .cursor/mcp.json, you can utilize workspace variables such as ${workspaceFolder} to define relative paths for server execution, ensuring configurations remain portable across team members' machines.
#Frequently Asked Questions
Yes, provided it does NOT contain raw secret API keys. If your server requires secret tokens, use environment variable references or keep sensitive keys in your local OS environment.