Advanced20 min1 prerequisite

Extend Cursor's AI capabilities with Model Context Protocol servers for database access, API integration, and custom tools.

MCP Servers in Cursor

Model Context Protocol (MCP) is an open standard that lets AI assistants connect to external tools and data sources. With MCP servers, Cursor can query databases, access APIs, read documentation, and perform actions beyond just reading your code.

What is MCP?

MCP provides a standardized way for AI to:

  • Access data: Query databases, file systems, APIs
  • Use tools: Run commands, make requests, perform actions
  • Get context: Fetch relevant information dynamically

Think of MCP servers as plugins that give Cursor superpowers.

How MCP Works

Terminal
┌─────────────┐     ┌─────────────┐     ┌─────────────┐
   Cursor    │────▶│ MCP Server  │────▶│  Resource   
    (AI)     │◀────│  (Bridge)   │◀────│  (DB/API)   
└─────────────┘     └─────────────┘     └─────────────┘
  1. You ask Cursor something that needs external data
  2. Cursor calls the appropriate MCP server
  3. The server fetches the data from the external resource
  4. Cursor uses that data in its response

Configuring MCP Servers

The MCP Configuration File

Create or edit ~/.cursor/mcp.json (or per-project in .cursor/mcp.json):

Terminal
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/folder"]
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_URL": "postgresql://user:pass@localhost:5432/db"
      }
    }
  }
}

Configuration Structure

Terminal
{
  "mcpServers": {
    "server-name": {
      "command": "command to run",
      "args": ["array", "of", "arguments"],
      "env": {
        "ENV_VAR": "value"
      }
    }
  }
}

Popular MCP Servers

Filesystem Server

Access files beyond your workspace:

Terminal
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/you/documents",
        "/Users/you/downloads"
      ]
    }
  }
}

Now you can ask:

Terminal
Read the requirements document from my downloads folder

PostgreSQL Server

Query your database:

Terminal
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_URL": "postgresql://localhost:5432/myapp"
      }
    }
  }
}

Ask database questions:

Terminal
Show me the schema for the users table
What are the most recent 10 orders?

SQLite Server

For local SQLite databases:

Terminal
{
  "mcpServers": {
    "sqlite": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-sqlite",
        "--db-path",
        "/path/to/database.db"
      ]
    }
  }
}

GitHub Server

Access GitHub repos and issues:

Terminal
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..."
      }
    }
  }
}

Then:

Terminal
What are the open issues in this repo?
Show me the recent PRs

Brave Search Server

Web search capabilities:

Terminal
{
  "mcpServers": {
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-brave-search"],
      "env": {
        "BRAVE_API_KEY": "your-api-key"
      }
    }
  }
}

Memory Server

Persistent memory across sessions:

Terminal
{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"]
    }
  }
}

Using MCP in Conversations

Once configured, MCP capabilities appear automatically:

Database Queries

Terminal
You: What does our users table look like?

AI: [Queries PostgreSQL via MCP]
    The users table has the following structure:
    - id: UUID (primary key)
    - email: VARCHAR(255)
    - name: VARCHAR(100)
    ...

File Access

Terminal
You: Read the API docs from /docs/api.md

AI: [Reads file via filesystem MCP]
    Here's the API documentation:
    ...

Web Search

Terminal
You: What's the latest on Next.js 15 features?

AI: [Searches via Brave MCP]
    According to recent sources:
    ...

Building Custom MCP Servers

When to Build Custom

Create custom servers when you need:

  • Access to internal APIs
  • Custom business logic
  • Proprietary data sources
  • Specialized tools

Basic Structure

A simple MCP server in TypeScript:

Terminal
import { Server } from "@modelcontextprotocol/sdk/server/index.js"
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"

const server = new Server(
  { name: "my-server", version: "1.0.0" },
  { capabilities: { tools: {} } }
)

// Define a tool
server.setRequestHandler("tools/list", async () => ({
  tools: [{
    name: "get_weather",
    description: "Get current weather for a city",
    inputSchema: {
      type: "object",
      properties: {
        city: { type: "string", description: "City name" }
      },
      required: ["city"]
    }
  }]
}))

// Handle tool calls
server.setRequestHandler("tools/call", async (request) => {
  if (request.params.name === "get_weather") {
    const city = request.params.arguments.city
    const weather = await fetchWeather(city)
    return { content: [{ type: "text", text: JSON.stringify(weather) }] }
  }
})

// Start server
const transport = new StdioServerTransport()
await server.connect(transport)

Registering Custom Servers

Terminal
{
  "mcpServers": {
    "my-custom-server": {
      "command": "node",
      "args": ["/path/to/my-server.js"]
    }
  }
}

Security Considerations

Credentials

Never hardcode credentials:

Terminal
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_URL": "${POSTGRES_URL}"
      }
    }
  }
}

Use environment variables from your shell.

Access Control

Be careful what you expose:

  • Limit database permissions
  • Use read-only connections when possible
  • Restrict file system paths
  • Audit what servers can access

Development vs Production

Terminal
// Development: Full access
{
  "mcpServers": {
    "postgres": {
      "env": {
        "POSTGRES_URL": "postgresql://localhost/dev"
      }
    }
  }
}

// Production: Read-only, limited access
{
  "mcpServers": {
    "postgres": {
      "env": {
        "POSTGRES_URL": "postgresql://readonly:pass@prod/db"
      }
    }
  }
}

Troubleshooting

Server Not Connecting

  1. Check the command path is correct
  2. Verify the server is installed (npx downloads automatically)
  3. Check environment variables are set
  4. Look at Cursor's output panel for errors

Server Errors

Enable logging:

Terminal
{
  "mcpServers": {
    "server-name": {
      "command": "...",
      "args": ["...", "--verbose"]
    }
  }
}

Server Not Appearing

  1. Restart Cursor after config changes
  2. Verify JSON syntax in mcp.json
  3. Check file is in correct location

Real-World Setup Example

A full development setup:

Terminal
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "${workspaceFolder}"
      ]
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_URL": "${DATABASE_URL}"
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
      }
    },
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"]
    }
  }
}

Summary

  • MCP servers extend Cursor with external capabilities
  • Configure in ~/.cursor/mcp.json or .cursor/mcp.json
  • Popular servers: Filesystem, PostgreSQL, GitHub, Search
  • Custom servers can access proprietary systems
  • Security: Use environment variables, limit access
  • Troubleshoot: Check logs, verify paths, restart Cursor

Next Steps

You've completed the Cursor module! You now know how to:

  • Use Tab completion effectively
  • Edit code inline with Cmd+K
  • Leverage the Chat panel
  • Master Composer for multi-file changes
  • Configure Rules for AI
  • Manage context strategically
  • Use Notepads for persistent reference
  • Extend Cursor with MCP servers

Continue to the Claude Code module to learn about agentic AI development from the terminal, or explore GitHub Copilot to see how it compares.

Mark this lesson as complete to track your progress