How to Install and Configure Your First MCP Server
Complete walkthrough for setting up MCP server infrastructure from scratch.
Setting up your first MCP server comes down to three real steps: installing an official SDK, writing a minimal server that registers at least one tool, and pointing an actual MCP client at it. Here's each step with working code, not placeholder pseudocode.
Step 1: Install an Official SDK
Anthropic maintains official SDKs for both major languages:
# TypeScript/JavaScript
npm install @modelcontextprotocol/sdk
# Python
pip install mcp
Step 2: Write a Minimal Server
Here's a genuinely minimal, working stdio-based server using the TypeScript SDK, registering one tool:
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-first-server", version: "1.0.0" });
server.registerTool(
"echo",
{
description: "Echoes back the input string",
inputSchema: { message: z.string() }
},
async ({ message }) => ({
content: [{ type: "text", text: message }]
})
);
const transport = new StdioServerTransport();
await server.connect(transport);
This is a complete, runnable server — not a fragment. It exposes exactly one tool (echo) over the stdio transport, which is what most local MCP clients (Claude Desktop, most CLI-based agents) expect for locally-run servers.
Step 3: Point Claude Desktop at It
Claude Desktop reads its MCP server list from a real config file — claude_desktop_config.json, located under your OS's application support directory. Add your server:
{
"mcpServers": {
"my-first-server": {
"command": "node",
"args": ["/absolute/path/to/your/server.js"]
}
}
}
Restart Claude Desktop after saving. If the server starts correctly, its tools appear in the client's tool list — you can verify this directly by asking Claude something that would require the echo tool.
Step 4: Test With the Official Inspector Instead of Guessing
Before wiring a new server into a full AI client, Anthropic's own MCP Inspector tool lets you exercise it directly:
npx @modelcontextprotocol/inspector node /absolute/path/to/your/server.js
This opens a local web UI where you can call tools/list, invoke tools/call with real arguments, and see the raw JSON-RPC messages going back and forth — far faster for debugging a broken tool schema than trying to reproduce the issue through a full chat interface.
Common First-Run Problems
- Relative paths in config: use the full absolute path to your server file — a relative path may not resolve correctly depending on the client's working directory.
- Wrong transport: a server built for stdio won't work if a client expects HTTP/SSE, and vice versa — check what transport your target client actually supports before writing the server.
- Silent startup failures: stdio servers that crash on launch often fail silently from the client's perspective — run the server directly from a terminal first to see any startup errors before wiring it into a client config.
Join the Discussion
Discussion (0)
No comments yet. Be the first to share your thoughts!
Code Snippets (0)
No code snippets shared yet. Be the first to contribute!