Setting Up Your First MCP Server
Step-by-step guide to creating and running your first MCP server
MCPgee Team
MCP Expert
Setting Up Your First MCP Server
Introduction
In this hands-on tutorial, you will build your first MCP server from scratch. We will create a simple note-taking server that allows AI assistants to read and write notes. By the end, you will have a working MCP server connected to Claude Desktop or Claude Code.
If you have not read the introductory guide yet, start with What is MCP? to understand the core concepts.
Choosing Your Development Environment
Language Options
MCP servers can be built in any language, but we will focus on the two most popular options:
- TypeScript/Node.js (Recommended)
McpServer class
- Excellent TypeScript support and type safety
- Large ecosystem of examples
- Python
FastMCP high-level API
- Great for data science and ML integrations
- Familiar syntax for many developers
Project Setup
TypeScript Setup
- Create Project Directory
- Initialize Node.js Project
- Install Dependencies
- Configure TypeScript
tsconfig.json:
- Update package.json
Python Setup
- Create Project Directory
- Create Virtual Environment
- Install Dependencies
Building the Note-Taking Server
Server Architecture
Our note-taking server will:
- Store notes in memory (with optional file persistence)
- Provide tools to create, read, update, and delete notes
- Expose notes as resources that AI can browse
- Support searching through notes
TypeScript Implementation (High-Level McpServer API)
The McpServer class from @modelcontextprotocol/sdk/server/mcp.js is the recommended way to build MCP servers. It provides a clean, declarative API that handles protocol details for you.
Create src/index.ts:
Python Implementation (FastMCP)
Create server.py:
Testing Your Server
Local Testing
- Run the Server
TypeScript:
Python:
- Test with JSON-RPC
You can test your server by sending JSON-RPC messages via stdin:
Connecting to Claude Desktop
- Locate Claude Desktop Config
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows: %APPDATA%\Claude\claude_desktop_config.json
- Linux: ~/.config/Claude/claude_desktop_config.json
For detailed configuration guidance, see the Claude Desktop integration tutorial.
- Add Your Server
Edit the config file:
For Python:
- Restart Claude Desktop
Close and reopen Claude Desktop to load your server. You should see your tools listed in the toolbox icon.
- Test the Integration
In Claude, try: - "Create a note about MCP servers" - "Search for notes about MCP" - "List all my notes"
Connecting to Claude Code
If you use Claude Code (the CLI), you can add MCP servers via the command line:
Using the Low-Level Server API
If you need more control over protocol handling, you can use the low-level Server class from @modelcontextprotocol/sdk/server/index.js. This is useful when you need custom request handling, middleware patterns, or advanced protocol features.
The high-level McpServer is recommended for most use cases. Choose the low-level Server only when you need custom protocol handling.
Adding Persistence
File-Based Storage
To make notes persist across server restarts, you can save notes to disk. Here is a minimal example:
Call loadNotes() at startup and saveNotes(notes) after every mutation.
Exploring Existing Servers
Before building everything from scratch, check the MCP servers directory for production-ready servers you can use or learn from:
- Filesystem Server - Read and write files on your local machine
- GitHub Server - Interact with GitHub repos, issues, and PRs
- PostgreSQL Server - Query PostgreSQL databases safely
Deployment Options
1. Local with Claude Desktop
The simplest option - configure your server in claude_desktop_config.json and let Claude Desktop manage the process lifecycle. See the Claude Desktop integration guide for details.
2. Docker Container
3. Remote via Streamable HTTP
For remote deployment, serve your MCP server over Streamable HTTP instead of stdio. This lets clients connect over the network. The MCP SDK provides helpers for this transport - see the build MCP server tutorial for advanced patterns.
Next Steps
Congratulations! You have built your first MCP server. From here you can:
- Dive deeper into production-ready server architecture
- Learn about MCP vs Traditional APIs to understand architectural trade-offs
- Connect your server to Claude Desktop with advanced configuration
- Build a Python server following the Python MCP server guide
- Browse the servers directory for inspiration
Conclusion
You now have a working note-taking server with CRUD operations, integration with Claude Desktop, and an understanding of both the high-level and low-level MCP SDK APIs. This server demonstrates the core concepts of MCP: resources, tools, and the client-server communication model.
MCP servers can integrate with any system - databases, APIs, file systems, or custom services. The protocol's flexibility allows you to expose any functionality to AI assistants in a standardized, secure way.
Code Examples
Key Takeaways
- McpServer from @modelcontextprotocol/sdk/server/mcp.js is the recommended high-level API for TypeScript servers
- FastMCP from mcp.server.fastmcp is the recommended high-level API for Python servers
- MCP servers communicate via stdio for local use or Streamable HTTP for remote deployment
- Tools use Zod schemas (TypeScript) or type hints (Python) for automatic input validation
- Claude Desktop and Claude Code both support connecting to MCP servers with simple configuration
Troubleshooting
Server does not appear in Claude Desktop after configuration
Verify your JSON syntax is valid and all paths are absolute. Completely quit Claude Desktop (not just close the window) and reopen it. Test the server manually by running the exact command from your configuration in a terminal.
Cannot find module '@modelcontextprotocol/sdk'
Run npm install @modelcontextprotocol/sdk in your project directory. Ensure your package.json has "type": "module" for ESM support. Check that your Node.js version is 18 or later.
Python import error: No module named 'mcp'
Install the MCP Python package with pip install mcp. Make sure you are using the virtual environment where the package is installed. The package name is mcp, not mcp-server-sdk.
Server starts but tools do not work in Claude
Ensure your server writes protocol messages to stdout only. All logging must go to stderr. In TypeScript use console.error for logs. In Python set PYTHONUNBUFFERED=1 in your Claude Desktop config env.
Next Steps
- Build a production-ready server with the Build MCP Server tutorial
- Connect to Claude Desktop with advanced configuration
- Explore the MCP servers directory for real-world examples
- Learn about MCP vs APIs to understand when MCP is the right choice
Was this helpful?
Stay Updated with MCP Insights
Join 5,000+ developers and get weekly insights on MCP development, new server releases, and implementation strategies delivered to your inbox.
We respect your privacy. Unsubscribe at any time.
MCPgee Team
We write in-depth guides, tutorials, and reviews to help developers get the most out of the Model Context Protocol ecosystem.
Frequently Asked Questions
Related Tutorials
What is Model Context Protocol?
Understand the basics of MCP and why it matters for AI development
Integrating with Claude Desktop
Complete guide to connecting your MCP servers with Claude Desktop
Building Your First MCP Server
Deep dive into building production-ready MCP servers with advanced patterns
Recommended MCP Servers
Popular servers related to this tutorial that you can start using right away.
n8n-mcp
A comprehensive MCP server that provides full control over n8n automation workflows through natural language. It offers
Dify MCP Server
Production-ready platform for agentic workflow development.
gemini-cli-mcp
A secure MCP server that wraps the Google Gemini CLI, allowing clients to query Gemini models using local OAuth sessions
Netdata MCP Server
Real-time infrastructure monitoring with metrics, logs, alerts, and ML-based anomaly detection.
Awesome Claude Skills MCP Server
A curated list of awesome Claude Skills, resources, and tools for customizing Claude AI workflows
TrendRadar
A real-time hotspot monitoring and news aggregation assistant that provides AI-powered analysis of trending topics acros
Explore MCP Servers
Browse our directory of 33,000+ MCP servers. Find the perfect tools for your AI-powered workflows.