What Is an MCP Server?
An MCP server is a lightweight process that exposes tools, resources, and prompts to AI clients like Claude, Cursor, or any MCP-compatible application. Think of it as an API adapter purpose-built for AI — instead of returning raw JSON for a frontend, you're returning structured context that an LLM can reason over.
The protocol was created by Anthropic and is now an open standard. When you build an MCP server, your tools become available to any AI that speaks MCP — today that includes Claude Desktop, Cursor, VS Code Copilot, and many more.
The Three Primitives
Every MCP server is built from three core building blocks:
- Tools — executable functions the AI can call (like
search_databaseorsend_email) - Resources — read-only data the AI can fetch (like files, API responses, or database records)
- Prompts — reusable prompt templates with parameters
Most MCP servers focus on tools — they're the most commonly used primitive and the easiest to get started with.
Prerequisites
Before you start, you'll need:
- Node.js 18+ (for TypeScript) or Python 3.10+ (for Python)
- Basic familiarity with async/await and REST APIs
- An MCP client to test with (Claude Desktop is the easiest)
Option 1: TypeScript MCP Server
The TypeScript SDK is the most mature and widely used. Start by installing the package:
npm init -y
npm install @modelcontextprotocol/sdkThen create your server file. Here's a minimal example that exposes a get_weather tool:
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
const server = new Server(
{ name: "weather-server", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
// Declare your tools
server.setRequestHandler(ListToolsRequestSchema, 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(CallToolRequestSchema, async (request) => {
if (request.params.name === "get_weather") {
const city = request.params.arguments?.city as string;
// Call your real weather API here
return {
content: [
{
type: "text",
text: `Weather in ${city}: 72°F, partly cloudy`,
},
],
};
}
throw new Error("Unknown tool");
});
// Start the server
const transport = new StdioServerTransport();
await server.connect(transport);Run it with npx ts-node server.ts (or compile first with tsc). The server communicates over stdio — that's how MCP clients like Claude Desktop launch and talk to it.
Option 2: Python MCP Server
The Python SDK uses a decorator-based API that's very clean. Install it first:
pip install mcpThen build the same weather server in Python:
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp import types
app = Server("weather-server")
@app.list_tools()
async def list_tools():
return [
types.Tool(
name="get_weather",
description="Get current weather for a city",
inputSchema={
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
)
]
@app.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "get_weather":
city = arguments["city"]
# Call your real weather API here
return [types.TextContent(type="text", text=f"Weather in {city}: 72°F, partly cloudy")]
raise ValueError(f"Unknown tool: {name}")
async def main():
async with stdio_server() as streams:
await app.run(*streams, app.create_initialization_options())
if __name__ == "__main__":
import asyncio
asyncio.run(main())Connecting to Claude Desktop
To test your server, add it to Claude Desktop's config. Open ~/Library/Application Support/Claude/claude_desktop_config.json on macOS (or the equivalent on Windows/Linux) and add:
{
"mcpServers": {
"weather": {
"command": "node",
"args": ["/path/to/your/server.js"]
}
}
}Restart Claude Desktop and you'll see a hammer icon in the chat interface. Click it to see your tools — Claude can now call get_weather whenever it's relevant.
Adding Resources
Resources let you expose read-only data. They're identified by URIs and can represent anything from files to live API data:
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
resources: [
{
uri: "file:///data/config.json",
name: "App Configuration",
mimeType: "application/json",
},
],
}));
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
if (request.params.uri === "file:///data/config.json") {
const content = await fs.readFile("./config.json", "utf-8");
return {
contents: [{ uri: request.params.uri, mimeType: "application/json", text: content }],
};
}
throw new Error("Resource not found");
});Error Handling Best Practices
MCP servers should handle errors gracefully. Key patterns:
- Return errors in content — don't throw for tool logic failures. Return a text content block with the error message so the AI can understand what went wrong.
- Throw for protocol errors — unknown tools, missing required params, and auth failures should throw.
- Validate inputs — always validate required fields before calling downstream APIs.
- Timeout long operations — wrap slow API calls in a timeout to prevent hanging the AI client.
Deploying Your MCP Server
Most MCP servers run locally via stdio — they're launched by the AI client as a child process. But you can also deploy them as HTTP servers using the SSE (Server-Sent Events) transport for remote access.
For local distribution:
- Publish to npm (TypeScript) or PyPI (Python) so users can install with
npxoruvx - Use
npx your-packageas the command in config — no install required - Bundle with pkg or nexe for zero-dependency executables
For remote/cloud deployment:
- Use the SSE transport instead of stdio
- Deploy to Railway, Fly.io, or any Node.js/Python host
- Add OAuth or API key auth for multi-user servers
Common Patterns and Use Cases
Once you have the basics down, MCP servers are incredibly versatile:
- Database access — expose SQL query tools so AI can fetch live data
- File system — let AI read/write project files (be careful with write permissions)
- API wrappers — turn any REST API into MCP tools (GitHub, Slack, Linear, etc.)
- Code execution — run sandboxed code and return results
- Memory/state — persist information between AI conversations
Discovering Existing MCP Servers
Before building from scratch, it's worth checking if someone has already built what you need. EveryMCP indexes thousands of MCP servers with search, filtering by category, and detailed documentation. The ecosystem is growing fast — new servers ship every day.
Popular categories include:
- Database MCP servers (PostgreSQL, MySQL, SQLite, MongoDB)
- Developer tools (GitHub, GitLab, Jira, Linear)
- Productivity (Notion, Google Drive, Slack)
Next Steps
Building an MCP server is one of the fastest ways to give AI models real capabilities. Start small — one tool, one resource — and iterate. The SDK handles the protocol so you can focus on your logic.
Once you've shipped your first server, submit it to EveryMCP so developers can discover it. The MCP ecosystem grows when builders share their work.
Looking for MCP servers to use right now? Browse the EveryMCP directory →