What a Claude MCP server is and why you'd build one

A Model Context Protocol (MCP) server is a program that connects Claude to tools, data sources, or services outside of Claude itself. Instead of Claude having built-in access to everything, an MCP server acts as a bridge — you build it, you run it, and you decide what Claude can reach through it.

You build an MCP server when you want Claude to interact with something specific to your work: a private database, internal company tools, local files on your computer, a custom API, or specialized software. Claude can't access these things on its own, so the server you create becomes the middleman that makes it possible.

The server runs on your machine or your infrastructure, not on Anthropic's servers. This means you control what data Claude sees, how it's processed, and where it goes — useful if you're working with sensitive information or proprietary systems.

Key Takeaways

  • An MCP server is a program you write that lets Claude use tools and access data you define, running on your own computer or server.
  • You'll need Node.js installed, the MCP SDK from Anthropic, and a code editor — the whole setup takes under an hour on most machines.
  • The server communicates with Claude through JSON-RPC messages over stdio, a standard protocol that handles all the back-and-forth automatically.
  • You define what Claude can do by writing tool definitions and handler functions that describe each action and what it does.
  • Once running, you connect Claude to your server through Claude Desktop or the API, and Claude can then call the tools you've built.

Setting up your development environment

Start by installing Node.js version 18 or later on your machine. Download it from nodejs.org and run the installer — this gives you Node and npm (the Node package manager) in one step. Open a terminal and run node --version to confirm it installed.

Create a new folder for your project and open a terminal inside it. Run npm init -y to create a package.json file, which tracks your project's dependencies. Then install the MCP SDK by running npm install @modelcontextprotocol/sdk.

Open the folder in a code editor — VS Code is free and widely used, but any text editor works. You now have everything needed to write your first server.

Understanding how MCP servers communicate with Claude

An MCP server talks to Claude using JSON-RPC, a lightweight messaging format. When Claude wants to use a tool your server provides, it sends a message asking for it. Your server receives that message, does the work, and sends back the result. This all happens over stdio (standard input/output), the same channel your terminal uses.

You don't write the JSON-RPC code yourself — the MCP SDK handles it. You focus on defining what tools exist and what they do. The SDK wraps your code in the protocol layer automatically.

Think of it like a restaurant: Claude is the customer, your server is the kitchen, and JSON-RPC is the ticket system. Claude writes a ticket (sends a message), the kitchen reads it and cooks (your code runs), and the ticket comes back with the dish (the result returns).

Creating your first tool definition

A tool is something Claude can ask your server to do. You define each tool by telling the SDK three things: the tool's name, what it does, and what inputs it needs.

Here's the structure of a simple tool that reads a file from your computer:

The tool is named "read_file". It takes one input: a file path (a string). When Claude calls it, your server reads that file and returns its contents. Claude can then work with that content — summarize it, edit it, answer questions about it.

In code, you define this by creating a tool object with a name, description, and input schema. The input schema describes what Claude needs to provide — in this case, a string called "path". Then you write a handler function that actually reads the file when Claude calls the tool.

Writing the server code

Create a file called server.js in your project folder. Start by importing the MCP SDK:

const { Server } = require('@modelcontextprotocol/sdk/server/index.js');

Create a new Server instance, then define your tools. For each tool, write a handler function — the code that actually runs when Claude calls it. The handler receives the inputs Claude provided, does the work, and returns a result.

At the end of your file, start the server by calling the start method. This tells the server to begin listening for messages from Claude.

A minimal server that provides one tool looks like this structure: import the SDK, create a server, define one tool with its handler, then start the server. The whole thing is usually 30 to 50 lines of code.

Testing your server before connecting to Claude

Run your server from the terminal with node server.js. If it starts without errors, it's listening. The server won't do anything visible yet — it's just waiting for Claude to send it messages.

To test without Claude, you can send test messages manually using a tool like curl or Postman, or write a simple test script that sends JSON-RPC messages to your server's stdio. The MCP SDK documentation includes examples of test messages for each tool type.

Common issues at this stage: missing dependencies (run npm install again), syntax errors in your code (check the error message in the terminal), or the wrong Node version (confirm with node --version).

Connecting your server to Claude Desktop or the API

If you're using Claude Desktop, the configuration file is located at:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

Open this file and add your server under the "mcpServers" section. You'll specify the command to start your server (usually node /path/to/your/server.js) and any environment variables it needs. Save the file, restart Claude Desktop, and your tools will appear in Claude's interface.

If you're using the Claude API, you configure the server connection in your API request. The exact method depends on which client library you're using — check Anthropic's documentation for your language (Python, JavaScript, etc.).

Common patterns and next steps

Most MCP servers follow a few standard patterns. A resource server gives Claude access to files or data — like reading documents from a folder or querying a database. A tool server lets Claude perform actions — like sending emails, creating files, or calling external APIs. Many servers do both.

Once your first server works, you can expand it by adding more tools, connecting to real databases or APIs, or handling more complex inputs. The MCP SDK supports tools that take multiple inputs, return different types of data, and handle errors gracefully.

The Anthropic documentation includes example servers for common use cases: reading files, querying databases, calling REST APIs, and integrating with popular services. Start with an example close to what you need, then modify it for your specific use case.

Frequently Asked Questions

Do I need to know JavaScript to build an MCP server?

The official SDK is in JavaScript (Node.js), but Anthropic and the community have built SDKs in Python, Go, and other languages. If you prefer Python, you can build servers in Python instead. The concepts are the same across languages.

Can Claude access my server if it's running on my local machine?

Yes, if Claude Desktop is running on the same machine. Claude Desktop reads the configuration file and starts your server as a subprocess. If you're using the API from a remote server, your server needs to be reachable from that location — usually on your own infrastructure or a VPS you control.

What happens if my server crashes while Claude is using it?

Claude will get an error message. The server won't automatically restart — you'll need to restart it manually or set up a process manager like PM2 to restart it automatically. For production use, monitoring and auto-restart are important.

Can multiple people use the same MCP server?

If the server is running on a shared machine or accessible over the network, yes — but you'll need to handle authentication and access control yourself. The MCP protocol doesn't include built-in user management, so you add that layer if needed.

How do I know if my tool definition is correct?

The SDK validates your tool definition when the server starts. If the schema is malformed, you'll get an error in the terminal. Once the server starts without errors, Claude can see and call your tools. If Claude can't use a tool the way you expected, check the tool's description and input schema — Claude follows those exactly.