New tutorials dropping soon — subscribe to the newsletter for updates.

Using MCP Servers in Claude Code

Stay lazy, code smarter

New tutorials and tips straight to your inbox

Using MCP Servers in Claude Code

January 20, 20253:00

Learn how to configure and use MCP (Model Context Protocol) servers to give Claude Code access to external tools and data sources.

What is MCP?

The Model Context Protocol (MCP) is a standard interface that lets Claude Code communicate with external tools and data sources. Think of it like USB for AI — any tool that implements the protocol can plug into Claude Code.

Why MCP Matters

Out of the box, Claude Code can read files and run commands. MCP extends that to:

  • Databases — Query your dev database, inspect schemas, run migrations
  • APIs — Hit internal services, check deployment status, read documentation
  • Custom tools — Anything you can write a function for

Setting Up Your First MCP Server

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

{
  "mcpServers": {
    "weather": {
      "command": "node",
      "args": ["./mcp-servers/weather/dist/index.js"]
    }
  }
}

Building a Simple MCP Server

Here's a minimal MCP server in TypeScript:

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

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

server.tool(
  "lookup_user",
  "Look up a user by email",
  { email: z.string().email() },
  async ({ email }) => ({
    content: [{
      type: "text" as const,
      text: JSON.stringify({ id: "123", email, name: "Jane" }),
    }],
  })
);

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

How Claude Discovers Tools

When you start a session, Claude Code reads your .mcp.json, starts each server, and discovers what tools are available. When you ask a question that needs external data, Claude automatically calls the right tool.

Best Practices

  1. One tool per task — Don't create a do_everything tool. Keep them focused.
  2. Validate inputs with Zod — Always validate what Claude sends.
  3. Return structured JSON — Easier for Claude to parse than prose.
  4. Handle errors gracefully — Return helpful messages so Claude can retry or self-correct.

Popular MCP Servers

The ecosystem is growing fast. Some useful ones:

  • @modelcontextprotocol/server-filesystem — Enhanced file operations
  • @modelcontextprotocol/server-github — GitHub API access
  • @modelcontextprotocol/server-postgres — PostgreSQL queries
  • Community servers for Slack, Linear, Notion, and more

Stay lazy.

Get bite-sized AI coding tips delivered to your inbox every week. No spam, unsubscribe anytime.