What an MCP Server Does and Why You'd Build One
An MCP server (Model Context Protocol server) is a program that sits between an AI process and the tools or data it needs to work with. Instead of building those connections into the AI itself, an MCP server acts as a translator — it takes requests from the AI, talks to your databases or APIs or file systems, and sends back the results in a format the AI understands.
You build your own MCP server when you want an AI tool to work with something specific to your business or workflow — your internal database, your company's file storage, a custom tool you've written, or a service that doesn't have a pre-built MCP server yet. The server runs on your machine or your infrastructure, so you control what data the AI can see and what it can do.
This is different from using a hosted AI service. You're not asking Claude or another AI to connect to your systems directly. Instead, you're building a small program that Claude (or another MCP-compatible process) can call when it needs something from you.
Key Takeaways
- An MCP server is a program that connects an AI process to your tools, databases, or APIs by translating requests between them.
- You need Node.js or Python installed on your machine, plus the MCP SDK for whichever language you choose.
- A working MCP server requires three parts: a way to receive requests from the AI, logic that does the actual work, and a way to send responses back.
- Testing your server locally before connecting it to an AI process catches most problems and saves troubleshooting time later.
- The MCP specification is maintained by Anthropic and documented at modelcontextprotocol.io, where you'll find examples and the full protocol details.
Install the Tools You Need First
Before you write any code, you need a runtime environment and the MCP SDK. Most MCP servers are built in Node.js or Python — pick whichever you're more comfortable with, because both work equally well.
For Node.js: read and install from nodejs.org. Once installed, open a terminal or command prompt and run node --version to confirm it worked. Then create a new folder for your project, open a terminal in that folder, and run npm init -y to set up a Node project. Finally, install the MCP SDK by running npm install @modelcontextprotocol/sdk.
For Python: read and install from python.org (version 3.8 or newer). Confirm it works by running python --version in a terminal. Create a folder for your project, open a terminal in that folder, and create a virtual environment by running python -m venv venv. set up it by running source venv/bin/set up on Mac or Linux, or venv\Scripts\set up on Windows. Then install the MCP SDK by running pip install mcp.
You also need a text editor or IDE to write code. Visual Studio Code (free, from code.visualstudio.com) works well for both languages and has built-in terminal support.
Understand the Three Parts of an MCP Server
Every MCP server has the same basic structure, regardless of what it connects to. Understanding these three parts makes writing your server much clearer.
The first part is the transport layer — how the server receives messages from the AI process and sends messages back. Most MCP servers use stdio (standard input and output), which means the AI process runs your server as a subprocess and talks to it through pipes. This is simpler than setting up a network connection and works well for local development.
The second part is the handler logic — the actual code that does the work. When the AI asks for something (like "fetch the user with ID 42" or "list all files in this folder"), your handler code runs and produces a result. This is where you write the code that talks to your database, calls your API, reads your files, or whatever your server is supposed to do.
The third part is the tool or resource definitions — you tell the AI process upfront what your server can do. You describe each tool (like "get_user" or "list_files") by giving it a name, a description, and the parameters it accepts. The AI reads these definitions and knows when and how to call your server.
Write a straightforward Server in Node.js
Here's a minimal working MCP server in Node.js that defines one tool called "greet". This server doesn't connect to anything external — it just shows you the structure you'll use for a real server.
Create a file called server.js in your project folder and paste this code:
const { Server } = require("@modelcontextprotocol/sdk/server/index.js"); const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js"); const server = new Server({ name: "my-first-server", version: "1.0.0", }); server.setRequestHandler(require("@modelcontextprotocol/sdk/types.js").CallToolRequest, async (request) => { if (request.params.name === "greet") { const name = request.params.arguments.name || "World"; return { content: [{ type: "text", text: `Hello, ${name}!` }], }; } throw new Error(`Unknown tool: ${request.params.name}`); }); server.setRequestHandler(require("@modelcontextprotocol/sdk/types.js").ListToolsRequest, async () => { return { tools: [ { name: "greet", description: "Greet someone by name", inputSchema: { type: "object", properties: { name: { type: "string", description: "The person's name" }, }, }, }, ], }; }); const transport = new StdioServerTransport(); server.connect(transport);
Save the file. This server defines one tool called "greet" that takes a name parameter and returns a greeting. The ListToolsRequest handler tells the AI what tools are available. The CallToolRequest handler actually runs the tool when the AI calls it.
Test Your Server Before Connecting It to an AI
Before you connect your server to Claude or another AI process, test it locally to make sure it works. The MCP project provides a testing tool called the MCP Inspector.
In your project folder, run npm install --save-dev @modelcontextprotocol/inspector to install the inspector. Then run npx mcp-inspector node server.js. This starts your server and opens a web interface in your browser where you can call your tools and see the responses.
In the inspector, you'll see your server listed. Click on it, then click "Call Tool". Select "greet" from the dropdown, enter a name in the arguments field, and click "Call". You should see your greeting come back. If something breaks, the inspector shows you the error message, which tells you what to fix in your code.
Test every tool your server defines before you move on. This catches mistakes early and saves you from debugging through the AI process, which is much harder.
Connect Your Server to Claude or Another MCP Client
Once your server works in the inspector, you connect it to an AI process that supports MCP. Claude Desktop (the desktop version of Claude) is the most common choice.
To connect your server to Claude Desktop, you need to edit Claude's configuration file. On Mac, this file is at ~/Library/process Support/Claude/claude_desktop_config.json. On Windows, it's at %APPDATA%\Claude\claude_desktop_config.json. On Linux, it's at ~/.config/Claude/claude_desktop_config.json.
Open that file in a text editor. If it doesn't exist, create it. Add your server to the "mcpServers" section. For the Node.js server above, add this:
{ "mcpServers": { "my-first-server": { "command": "node", "args": ["/path/to/your/server.js"] } } }
Replace /path/to/your/server.js with the full path to your server file. On Windows, use backslashes or forward slashes — both work. Save the file, then restart Claude Desktop. When Claude starts, it will launch your server in the background. You can now ask Claude to use your tools.
Common Problems and How to Fix Them
The server starts but Claude doesn't see the tools. Check that your server.js file is in the path you specified in the config file. Restart Claude Desktop completely — closing the window isn't always enough. On Windows, check the Task Manager to make sure no old Claude processes are still running.
Claude sees the tools but calling them returns an error. Open the MCP Inspector again and test the tool there. If it works in the inspector but fails in Claude, the problem is usually in how you're passing arguments. Check that the parameter names in your handler match exactly what you defined in the inputSchema.
The server crashes when Claude calls it. Add console.log statements to your handler code to see where it's failing. Run the server in the inspector and call the tool — the inspector shows you the exact error. Common causes are trying to access a property that doesn't exist, or forgetting to return the response in the right format.
Your server needs to talk to a database or API but the connection fails. Test the connection outside the MCP server first — write a small script that connects to your database or calls your API directly. Once that works, add it to your server. This separates the MCP plumbing from the actual work your server does.
Frequently Asked Questions
Can I run an MCP server on a remote machine instead of my computer?
Yes, but you need to change the transport layer from stdio to HTTP or WebSocket. The stdio transport only works for local processes. For remote servers, you'll need to set up a network transport, which is more complex. Start with a local server first, then move to remote hosting once you understand how MCP works.
What's the difference between a tool and a resource in MCP?
A tool is something the AI calls when it needs to do something — fetch data, write a file, run a calculation. A resource is something the AI can read or reference — a document, a database record, a file. Tools are actions; resources are data. Most servers start with tools.
Do I need to restart Claude every time I change my server code?
Yes. Claude starts your server once when it launches. If you change the code, you need to restart Claude so it starts the new version. During development, keep the MCP Inspector open instead — you can test changes without restarting anything.
Can multiple AI applications use the same MCP server?
Yes. Any MCP-compatible process can connect to your server if you configure it correctly. The configuration format varies by process, but the server itself doesn't change. You define it once and point multiple clients to it.
Where do I find examples of real MCP servers?
The official MCP repository on GitHub (github.com/modelcontextprotocol/servers) contains example servers for common tasks like reading files, querying databases, and calling APIs. The documentation at modelcontextprotocol.io also has tutorials and the full protocol specification.