What an MCP server is and why you might build one

An MCP server (Model Context Protocol server) is a program that connects AI models like Claude to tools, data sources, or services outside the model itself. Instead of an AI having built-in knowledge of how to do something, an MCP server acts as a bridge — it tells the AI what capabilities are available and handles the actual work when the AI asks for it.

You build your own MCP server when you want Claude or another AI model to interact with something specific to your work: a private database, internal company tools, a custom API, local files on your computer, or specialized software. The server translates requests from the AI into actions your system understands, then sends the results back.

Think of it like this: if you want Claude to look up information in your company's customer database, you don't give Claude direct access to that database (which would be a security problem). Instead, you build an MCP server that knows how to safely query that database and return only the information Claude asked for.

Key Takeaways

  • An MCP server is a program that lets AI models access tools and data you control, without giving the AI direct access to sensitive systems.
  • You write an MCP server in Python, JavaScript, or another language, using the Model Context Protocol specification from Anthropic.
  • The server defines what the AI can ask for (called "tools" or "resources") and handles the actual work when requests come in.
  • You run the server locally on your computer or on a server, then connect Claude or another compatible AI client to it.
  • Common reasons to build one: connect AI to private databases, internal APIs, local files, or specialized software your organization uses.

Understanding the Model Context Protocol specification

The Model Context Protocol is a standard created by Anthropic that defines how AI models and external tools communicate. It's open-source, which means anyone can read the specification and build servers that follow it.

The protocol works in two directions. First, your MCP server tells the AI client (like Claude) what it can do — for example, "I can read files from this folder" or "I can query this database." Second, when the AI wants to use one of those capabilities, it sends a request to your server, your server does the work, and it sends the result back to the AI.

You don't need to understand every detail of the protocol to build a basic server. Anthropic provides SDKs (software development kits) for Python and JavaScript that handle most of the protocol work for you. You focus on writing the logic that does the actual task.

Setting up your development environment

Start by choosing a language. Python is the most common choice for MCP servers because it's readable and has good libraries for most tasks. JavaScript (Node.js) is also well-supported. Both have official SDKs from Anthropic.

If you choose Python, install Python 3.10 or later from python.org. Then create a new folder for your project and set up a virtual environment to keep dependencies isolated:

  1. Create a folder: mkdir my-mcp-server and cd my-mcp-server
  2. Create a virtual environment: python -m venv venv
  3. Activate it: on Mac or Linux, run source venv/bin/activate; on Windows, run venv\Scripts\activate
  4. Install the MCP SDK: pip install mcp

If you choose JavaScript, install Node.js 18 or later from nodejs.org. Create a folder, then run npm init -y to create a package.json file, and npm install @modelcontextprotocol/sdk to install the SDK.

Building a simple MCP server with Python

A basic MCP server in Python has three parts: import the SDK, define what tools your server offers, and write the code that runs when those tools are called.

Here's a minimal example that offers a single tool — a calculator that adds two numbers:

from mcp.server import Server from mcp.types import Tool, TextContent import json server = Server("my-calculator") @server.tool() def add_numbers(a: int, b: int) -> str: result = a + b return f"The sum of {a} and {b} is {result}" if __name__ == "__main__": server.run()

Save this as server.py. The @server.tool() decorator tells the MCP SDK that add_numbers is a tool the AI can call. The function takes parameters (in this case, two integers) and returns a string result.

To run it, type python server.py in your terminal. The server will start and wait for connections. In a real setup, you'd connect a Claude client to this server, and Claude could then ask it to add numbers.

Connecting your server to Claude or another AI client

Once your server is running, you need to tell an AI client how to reach it. The most common way is through a configuration file that lists all your MCP servers and how to start them.

If you're using Claude Desktop (the desktop application from Anthropic), the configuration file is usually at ~/.config/Claude/claude_desktop_config.json on Mac or Linux, or %APPDATA%\Claude\claude_desktop_config.json on Windows.

The file looks like this:

{ "mcpServers": { "my-calculator": { "command": "python", "args": ["/path/to/server.py"] } } }

Replace /path/to/server.py with the actual path to your server file. When you restart Claude Desktop, it will automatically start your server and make its tools available to Claude.

Real-world examples: what you can build

A file reader server lets Claude read and summarize documents from a specific folder on your computer without having access to your entire file system. You define which folder is safe to read from, and the server only returns files from that location.

A database query server connects Claude to a private database. Claude can ask questions in plain language ("Show me all customers who signed up last month"), and your server translates that into a safe SQL query, runs it, and returns the results.

An API wrapper server sits between Claude and an internal API your company uses. Instead of giving Claude direct access to the API (which might have rate limits or security concerns), your server handles the requests, applies any necessary filtering, and returns safe results.

A system command server lets Claude run specific shell commands on your computer — but only the ones you explicitly allow. For example, you might allow it to check disk space or restart a service, but not to delete files or access sensitive directories.

Security considerations when building an MCP server

Because an MCP server acts as a bridge between an AI and your systems, security matters. The AI should never have more access than you intend.

Always validate and limit what the AI can ask for. If you're building a file reader, specify exactly which folders are readable. If you're building a database query server, use parameterized queries to prevent SQL injection, and restrict which tables and columns the AI can access. Never pass user input directly to a system command without checking it first.

Run your server with the minimum permissions it needs. If it only needs to read files, don't run it as an administrator. If it connects to a database, use a database user account that has only the permissions required for that specific task.

Keep the MCP SDK and any libraries your server uses up to date. Security fixes are released regularly, and running old versions leaves you exposed.

Frequently Asked Questions

Do I need to know how to code to build an MCP server?

Yes, you need to write code. The SDKs make it simpler than building from scratch, but you should be comfortable reading and writing Python or JavaScript. If you're new to coding, start with a tutorial for your chosen language before building an MCP server.

Can I run an MCP server on a remote machine instead of my computer?

Yes. Instead of running the server locally, you can run it on a server you control and configure Claude to connect to it over the network. You'll need to handle authentication and encryption (usually with HTTPS or a similar secure protocol) to keep the connection safe.

What happens if my MCP server crashes or stops responding?

Claude will report an error when it tries to use a tool and the server doesn't respond. Restart the server and try again. In production, you can use a process manager like systemd (on Linux) or a task scheduler (on Windows) to automatically restart the server if it crashes.

Can multiple AI clients connect to the same MCP server?

Yes. A single MCP server can serve multiple clients. If you build a database query server, both Claude Desktop and a web application using Claude's API could connect to it and use the same tools.

Where can I find examples of MCP servers other people have built?

Anthropic maintains a repository of example servers on GitHub at github.com/anthropics/mcp-servers. These include servers for reading files, querying databases, and integrating with popular services. You can read the code to understand how they work and adapt them for your own use.