AI
What Is MCP (Model Context Protocol) and How to Build Your First MCP Server
MCP (Model Context Protocol) lets AI assistants like Claude connect to your tools, APIs, and data sources. Learn what MCP is, how it works, and how to build a simple MCP server in TypeScript that Claude can use.
What Is MCP and Why Does It Matter?
MCP (Model Context Protocol) is an open standard created by Anthropic that defines how AI assistants communicate with external tools and data sources. Before MCP, every AI integration was a custom one-off — a different API format for every tool, with no shared convention. MCP standardizes the connection layer so any MCP-compatible AI (Claude, Cursor, VS Code Copilot, and others) can connect to any MCP-compatible server using the same protocol.
Think of MCP as USB for AI tools. Before USB, every device needed its own proprietary cable and driver. USB standardized the connection so any device could plug into any computer. MCP does the same for AI and tools — once you build an MCP server for your database, API, or file system, any MCP-compatible AI can connect to it without custom integration work.
- MCP is an open standard by Anthropic for AI-to-tool communication
- Supported by Claude (Desktop and API), Cursor, VS Code, and other AI clients
- An MCP server exposes tools, resources, and prompts that the AI can call
- One MCP server works with any MCP-compatible AI client without re-integration
- The MCP SDK is available in TypeScript, Python, and other languages
How MCP Works: Servers, Tools, and Resources
An MCP server is a process that runs on the same machine as the AI client (local) or on a remote server (remote). The server declares a list of tools (functions the AI can call), resources (data the AI can read), and prompts (pre-defined instruction templates). When the AI needs to perform an action — query a database, read a file, call an API — it sends a tool call to the MCP server and the server executes it and returns the result.
The AI does not execute code directly. It tells the MCP server what to do, the server does it, and the AI incorporates the result into its response. This architecture keeps the AI sandboxed while giving it real capabilities. You control exactly which tools the server exposes, so the AI can only do what you explicitly allow.
- Tools: functions the AI can call (search database, send email, read file)
- Resources: data the AI can read (file contents, database records, API responses)
- Prompts: pre-defined instruction templates the AI can invoke
- Transport: local servers use stdio; remote servers use HTTP with Server-Sent Events
- Security: the AI can only call tools you explicitly define in the server
Setting Up Your MCP Server Project
The official MCP SDK for TypeScript is published by Anthropic as @modelcontextprotocol/sdk. Building an MCP server requires three things: initializing an McpServer instance, registering tools with their input schema, and connecting the server to a transport. For local development with Claude Desktop, the transport is stdio — the server communicates via standard input and output.
# Create a new MCP server project
mkdir my-mcp-server && cd my-mcp-server
npm init -y
npm install @modelcontextprotocol/sdk zod
npm install -D typescript @types/node tsx
# Create tsconfig.json
npx tsc --init --target ES2022 --module Node16 --moduleResolution Node16Building Your First MCP Tool
An MCP tool is a function with a name, description, and input schema defined with Zod. The description is what the AI reads to decide whether to call the tool — write it clearly so the AI knows exactly what the tool does and when to use it. The input schema validates the arguments the AI passes before your handler runs.
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-mcp-server',
version: '1.0.0',
});
// Register a tool that fetches weather data
server.tool(
'get_weather',
'Get the current weather for a city. Returns temperature and conditions.',
{ city: z.string().describe('The city name to get weather for') },
async ({ city }) => {
// Replace with real API call
const weather = await fetchWeatherApi(city);
return {
content: [{ type: 'text', text: JSON.stringify(weather) }],
};
}
);
// Start the server with stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);Connecting Your MCP Server to Claude Desktop
Claude Desktop reads MCP server configuration from a JSON file at ~/Library/Application Support/Claude/claude_desktop_config.json on macOS, or %APPDATA%/Claude/claude_desktop_config.json on Windows. Add your server to the mcpServers object and restart Claude Desktop. The server starts automatically when Claude Desktop launches and stops when it closes.
Once connected, Claude knows about your tools and will call them automatically when a user request matches the tool description. You do not need to tell Claude to use the tool — it reads the tool descriptions and decides when each one is appropriate.
{
"mcpServers": {
"my-mcp-server": {
"command": "node",
"args": ["/absolute/path/to/my-mcp-server/dist/index.js"],
"env": {
"WEATHER_API_KEY": "your-api-key-here"
}
}
}
}Practical MCP Server Ideas to Build
The most useful MCP servers connect AI to data and systems you already work with daily. A database MCP server lets Claude query your Postgres or SQLite database in plain English. A file system MCP server lets Claude read and write files in a specific directory. A Jira or Linear MCP server lets Claude create tickets, update statuses, and list open issues.
For developers, the highest-value first MCP server to build is one that connects to your internal documentation or codebase. Claude can answer questions about your own APIs, find relevant code examples, and suggest implementations based on your actual patterns rather than generic examples — turning it into a context-aware pair programmer for your specific system.
- Database server: let Claude query your PostgreSQL or SQLite in plain English
- File system server: read and write files in a sandboxed directory
- REST API wrapper: wrap any REST API as MCP tools for Claude to call
- Internal docs server: let Claude answer questions about your own codebase or API docs
- Browser automation: wrap Playwright as MCP tools for Claude to control a browser
FAQ
What is MCP (Model Context Protocol)?
MCP is an open standard created by Anthropic that defines how AI assistants communicate with external tools, APIs, and data sources. It standardizes the connection protocol so any MCP-compatible AI (Claude, Cursor, VS Code) can connect to any MCP-compatible server without custom integration work per AI client.
Which AI clients support MCP?
Claude Desktop, the Claude API (via tool use), Cursor IDE, VS Code with GitHub Copilot, and several other AI coding and chat tools support MCP. The standard is open and adoption is growing rapidly — most major AI development tools either support it or have announced support.
What language do I use to build an MCP server?
Anthropic publishes official MCP SDKs for TypeScript and Python. The TypeScript SDK (@modelcontextprotocol/sdk) is the most commonly used. Community SDKs exist for Go, Rust, Java, and other languages. TypeScript is the recommended choice for most developers because the SDK is mature and the examples are comprehensive.
Is MCP the same as function calling or tool use?
MCP and tool use are related but different. Tool use (function calling) is a feature of the AI model itself — the model generates structured arguments for a function you define in your API call. MCP is a protocol layer on top of that: it standardizes how tools are discovered, described, and called so one server works with any compatible AI client without rewriting the integration per client.
Can I use MCP with the Claude API in my own app?
Yes. The Claude API supports MCP through the tool use feature. You define tools in your API request and the model calls them as needed. For full MCP server hosting (remote servers accessible over HTTP), you set up your MCP server with an HTTP transport and connect it to the API. Local stdio servers work with Claude Desktop; HTTP servers work with the API.
How is MCP different from a REST API?
A REST API is designed for human-written client code that knows exactly which endpoint to call with which parameters. MCP is designed for AI models that decide dynamically which tool to call based on natural language context. MCP tools have human-readable descriptions that the AI reads to understand what each tool does and when to use it — REST APIs have no equivalent for AI self-discovery.
Is MCP secure?
MCP servers only expose the tools you explicitly define — the AI cannot call functions or access data you have not declared. Local stdio servers run on your machine and are not network-accessible. Remote HTTP servers should require authentication. You review and approve the tool list when you connect a server to your AI client, so you always know what capabilities the AI has access to.
Related free tools
If you want to turn this topic into action, use one of ShortIQ's free tools for campaign planning, UTM structure, or QR distribution.
Continue Reading
Explore more guides on link shortener SaaS strategy, Bitly alternatives, and white label link management.
Free newsletter
Get new guides in your inbox
We publish practical guides on dev tooling, prompt engineering, marketing workflows, and deployment. No fluff — straight to the point.
No spam. Unsubscribe any time.
Was this article helpful?
Tell us if this guide solved the problem or what was still missing. We use this to improve the blog and only follow up if you explicitly allow it.