How to Build an MCP Server
A complete, hands-on developer guide to building, testing, deploying, and publishing custom Model Context Protocol servers in TypeScript and Python. New to MCP itself? Start with What is an MCP? first.
Overview & Core Concepts
An MCP Server is a lightweight process that exposes capabilities — tools, data resources, and prompt templates — over standard JSON-RPC 2.0. Any MCP-compatible AI client (Claude Desktop, Claude Code, Cursor, and others) can connect to your server and use those capabilities on demand, without you writing custom integration code for each client.
Choosing Your Stack
MCP has officially maintained SDKs in several languages. TypeScript and Python are the most mature, with the largest ecosystem of example servers to learn from — this guide covers both in full. If your project already lives in another language, these SDKs work the same way conceptually:
- TypeScript / JavaScript — @modelcontextprotocol/sdk
- Python — mcp (with the FastMCP helper)
- Go — modelcontextprotocol/go-sdk
- Java / Kotlin — modelcontextprotocol/kotlin-sdk
- C# — modelcontextprotocol/csharp-sdk
Building with TypeScript
Install the official SDK and a schema validator:
Here is a complete working TypeScript server that exposes a tool, a resource, and a prompt:
Building with Python
Python developers can use the official mcp library’s FastMCP wrapper, which turns plain decorated functions into MCP primitives:
The same tool, resource, and prompt as above, in a few lines of Python:
Tools, Resources & Prompts
- Tools: Functions that execute side effects or perform calculations. Always provide clear parameters and a descriptive JSON schema so the AI model knows when and how to call them — see
calculate_sum/add_numbersabove. - Resources: Read-only data sources identified by URIs (e.g.
config://app,file:///logs/app.log, ordb://users/123). Clients can list and read them without invoking a tool. - Prompts: Reusable template workflows, like
summarizeabove, that users can invoke directly inside their AI client’s interface.
Testing Locally
Test your server directly in your browser without wiring it into a full AI client, using the official MCP Inspector:
This launches an interactive UI where you can call tools, read resources, and get prompts, while watching the raw JSON-RPC messages in real time.
Once it works in Inspector, point Claude Desktop at it directly:
For a Python server, swap the command for uv run --directory /absolute/path/to/project server.py. Fully restart the client (quit and reopen) after editing its config — see the LLM Agents Guide for the exact config file locations. Claude Code can add a local server directly from the command line instead:
Deploying a Remote Server
Everything above uses the stdio transport: your AI client launches the server as a local subprocess. For a server that multiple people share, or that needs to run somewhere other than the user’s machine, expose it over HTTP/SSE instead as a remote server. One common way to host a remote MCP server is on Cloudflare Workers using the agents package’s McpAgent class:
See Cloudflare’s MCP documentation for authentication, session handling, and other remote-server details.
Publishing & Listing on AllMCPs
Once your server works locally, get it in front of users:
- Publish your package to npm (Node.js) or PyPI (Python), or host it on GitHub with a tagged release.
- Write a
README.mdwith a clearclaude_desktop_config.jsonsnippet and a list of any required environment variables or API keys. - Pick an OSS license — MIT and Apache-2.0 are the most widely accepted for MCP servers.
- Tag a semantic-versioned release so users can pin a specific version.
- Head over to our Submit Page to list your server on AllMCPs and reach thousands of AI developers.
Frequently Asked Questions
Further Reading
- Model Context Protocol specification
- TypeScript SDK on GitHub
- Python SDK on GitHub
- Not sure what MCP actually is under the hood? Read What is an MCP?
- Connecting an existing server to a client instead of building one? See the LLM Agents Guide.
- Ready to take your server to production? Read our Deploying & Hosting Remote MCP Servers Guide.
- Ready to find inspiration? Browse the directory or explore by category.