- Learn
- AI Code Editors
- Cursor
- MCP Servers in Cursor
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
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Cursor │────▶│ MCP Server │────▶│ Resource │
│ (AI) │◀────│ (Bridge) │◀────│ (DB/API) │
└─────────────┘ └─────────────┘ └─────────────┘
- You ask Cursor something that needs external data
- Cursor calls the appropriate MCP server
- The server fetches the data from the external resource
- 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):
{
"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
{
"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:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/you/documents",
"/Users/you/downloads"
]
}
}
}
Now you can ask:
Read the requirements document from my downloads folder
PostgreSQL Server
Query your database:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"POSTGRES_URL": "postgresql://localhost:5432/myapp"
}
}
}
}
Ask database questions:
Show me the schema for the users table
What are the most recent 10 orders?
SQLite Server
For local SQLite databases:
{
"mcpServers": {
"sqlite": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sqlite",
"--db-path",
"/path/to/database.db"
]
}
}
}
GitHub Server
Access GitHub repos and issues:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..."
}
}
}
}
Then:
What are the open issues in this repo?
Show me the recent PRs
Brave Search Server
Web search capabilities:
{
"mcpServers": {
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "your-api-key"
}
}
}
}
Memory Server
Persistent memory across sessions:
{
"mcpServers": {
"memory": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"]
}
}
}
Using MCP in Conversations
Once configured, MCP capabilities appear automatically:
Database Queries
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
You: Read the API docs from /docs/api.md
AI: [Reads file via filesystem MCP]
Here's the API documentation:
...
Web Search
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:
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
{
"mcpServers": {
"my-custom-server": {
"command": "node",
"args": ["/path/to/my-server.js"]
}
}
}
Security Considerations
Credentials
Never hardcode credentials:
{
"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
// 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
- Check the command path is correct
- Verify the server is installed (
npxdownloads automatically) - Check environment variables are set
- Look at Cursor's output panel for errors
Server Errors
Enable logging:
{
"mcpServers": {
"server-name": {
"command": "...",
"args": ["...", "--verbose"]
}
}
}
Server Not Appearing
- Restart Cursor after config changes
- Verify JSON syntax in
mcp.json - Check file is in correct location
Real-World Setup Example
A full development setup:
{
"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.jsonor.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.