MCP extensions advanced

Claude Code MCP Servers: Extend Your AI Coding Assistant

Learn how to use MCP (Model Context Protocol) servers with Claude Code. Connect databases, APIs, and tools to supercharge your AI-powered development.

Updated: February 5, 2026 9 min read

What is MCP?

MCP (Model Context Protocol) is an open protocol that allows AI assistants like Claude Code to connect to external data sources and tools. Think of MCP servers as “plugins” for Claude Code — they extend its capabilities beyond the built-in tools.

With MCP, Claude Code can:

  • Query databases directly
  • Access API documentation
  • Connect to design tools
  • Interact with project management systems
  • Run custom workflows

How MCP Works with Claude Code

You → Claude Code → MCP Server → External Service

           Response/Data

MCP servers run as local processes that Claude Code communicates with. They expose resources (data) and tools (actions) that Claude Code can use during your session.

Setting Up Your First MCP Server

Step 1: Create Configuration

Create a .mcp.json file in your project root:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory"]
    }
  }
}

Step 2: Restart Claude Code

claude

Claude Code automatically detects and connects to configured MCP servers on startup.

Step 3: Use It

> List all markdown files in the allowed directory

Claude Code will use the filesystem MCP server to access files outside its normal scope.

Database Servers

PostgreSQL:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
    }
  }
}

Now Claude Code can query your database:

> Show me the schema of the users table and find any users with duplicate emails

SQLite:

{
  "mcpServers": {
    "sqlite": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-sqlite", "./data/app.db"]
    }
  }
}

Web & API Servers

Fetch (Web Access):

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

This lets Claude Code fetch web pages, API responses, and documentation.

Development Tools

GitHub:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "your-github-token"
      }
    }
  }
}

Access issues, PRs, and repository data directly.

Building a Custom MCP Server

You can build your own MCP server for internal tools. Here’s a minimal example in TypeScript:

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

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

// Register a tool
server.setRequestHandler("tools/list", async () => ({
  tools: [{
    name: "get_status",
    description: "Get system status",
    inputSchema: { type: "object", properties: {} },
  }],
}));

server.setRequestHandler("tools/call", async (request) => {
  if (request.params.name === "get_status") {
    return {
      content: [{ type: "text", text: "System is running!" }],
    };
  }
});

const transport = new StdioServerTransport();
await server.connect(transport);

MCP Best Practices

Security

  • Never expose production databases — Use read-only replicas or development databases
  • Limit file system access — Only allow specific directories
  • Use environment variables for tokens and secrets
  • Review MCP server code before installing third-party servers

Performance

  • MCP servers run locally, so they’re fast
  • Keep database queries focused — avoid SELECT * on large tables
  • Use caching for expensive API calls

Project Configuration

Put MCP config in your project’s .mcp.json:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/myapp_dev"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}"
      }
    }
  }
}

Don’t commit secrets — Use environment variable references and add .mcp.json to .gitignore if it contains sensitive data.

Real-World Use Cases

Debugging with Database Access

> The /api/orders endpoint is returning wrong totals.
  Check the orders table for order #12345 and compare 
  the line items with the calculated total.

Claude Code queries the database, finds the discrepancy, and fixes the code.

Code Review with GitHub Context

> Review the open PR #42 and check if it follows our coding conventions.
  Leave comments on any issues.

Documentation Generation

> Fetch our API docs from the internal wiki and generate 
  TypeScript types for all the endpoints.

Next Steps

Not working?

Check common errors and instant fixes in the Error Fix Center.

Fix Errors →