Tutorial

Building Your First MCP Server for Claude Code

Extend Claude Code's capabilities by building custom Model Context Protocol servers that connect to your tools, APIs, and data sources.

What is MCP?

The Model Context Protocol (MCP) is an open standard that lets you extend Claude Code with custom tools and data sources. Instead of copying data into prompts or describing APIs verbally, MCP servers give Claude direct, structured access to external systems.

Think of MCP servers as plugins for Claude Code. Once installed, Claude can use them naturally - querying your database, fetching from your internal APIs, or interacting with services like Jira, Notion, or your custom tools.

Why Build an MCP Server?

  • 1. Private data access - Connect Claude to internal databases, APIs, or file systems without exposing sensitive data in prompts
  • 2. Real-time information - Give Claude access to live data: stock prices, weather, deployment status, or anything with an API
  • 3. Custom actions - Let Claude trigger webhooks, create tickets, send notifications, or perform any operation your systems support
  • 4. Reduced context usage - Instead of pasting data, Claude fetches only what it needs, keeping conversations focused

MCP Server Anatomy

An MCP server exposes three types of capabilities to Claude:

// MCP Server Capabilities

Tools

Functions Claude can call (e.g., create_issue, query_database)

Resources

Data Claude can read (e.g., files, database schemas, API docs)

Prompts

Pre-built prompt templates for common tasks

Building a Simple MCP Server

Let's build a basic MCP server that gives Claude access to a todo list. We'll use TypeScript with the official MCP SDK.

Step 1: Set Up the Project

# Create project directory

mkdir todo-mcp && cd todo-mcp

npm init -y

npm install @modelcontextprotocol/sdk

Step 2: Create the Server

// index.ts

import

{ Server }

from

"@modelcontextprotocol/sdk/server"

;


// In-memory todo storage

let

todos: string[] = [];


const

server =

new

Server({

name:

"todo-server"

,

version:

"1.0.0"

});


// Define tools

server.setRequestHandler(

"tools/list"

, () => ({

tools: [

{ name:

"add_todo"

, description:

"Add a new todo item"

},

{ name:

"list_todos"

, description:

"List all todos"

},

{ name:

"complete_todo"

, description:

"Mark a todo as done"

}

]

}));

Step 3: Configure Claude Code

Add your server to Claude Code's configuration:

// ~/.claude/settings.json

{

"mcpServers": {

"todo": {

"command":

"node"

,

"args": [

"/path/to/todo-mcp/index.js"

]

}

}

}

Real-World MCP Use Cases

Database Query Server

Let Claude query your PostgreSQL, MongoDB, or any database. It can explore schemas, run SELECT queries, and help write migrations - all without you copying table structures into chat.

Jira/Linear Integration

Create issues, update status, fetch sprint data. When Claude finishes a task, it can automatically create a PR and update the corresponding ticket.

Documentation Server

Index your internal docs, API references, or wikis. Claude can search and reference them when answering questions about your codebase.

Deployment Pipeline

Trigger deployments, check pipeline status, roll back releases. Give Claude controlled access to your CI/CD system.

Security Best Practices

Important Security Considerations

  • Principle of least privilege - Only expose the minimum capabilities needed
  • Read-only by default - Make write operations explicit and confirmable
  • Validate inputs - Never trust tool arguments without validation
  • Audit logging - Log all tool invocations for review
  • Rate limiting - Prevent runaway operations

Getting Started Resources

The MCP ecosystem is growing rapidly. Here's where to find more:

  • - Official MCP specification and SDK documentation
  • - Community-built MCP servers for popular services
  • - Example implementations for common patterns

Conclusion

MCP servers transform Claude Code from a general-purpose assistant into a tool deeply integrated with your specific workflow. Whether you're connecting to internal APIs, databases, or third-party services, the protocol provides a clean, secure way to extend Claude's capabilities.

Start simple - build a server for one tool you use frequently. As you get comfortable, expand to cover more of your development workflow. The investment pays off quickly when Claude can directly interact with your systems instead of you being the middleware.