← Back to Posts

How to Build an MCP Server from Scratch

Learn step-by-step how to create your own Model Context Protocol (MCP) server using Python and FastMCP, with practical examples and tips.

2026-03-27
By Jake Alberio
MCPserverPythonFastMCPtutorial

Introduction

MCP Server SetupMCP Server Setup

What is MCP?

Model Context Protocol (MCP)

MCP is a standardized protocol that allows AI models like Claude to interact with your local tools, data, and applications. By building an MCP server you create a bridge where the AI can call functions, retrieve data, and perform actions securely.

"MCP servers provide the missing link, giving AI agents the tools they need to access live data and perform real actions." – Dev.to tutorial


Prerequisites

  1. Basic knowledge of Python
  2. Python 3.9+ installed
  3. Access to a terminal/command prompt
  4. An internet connection to install packages

Step 1: Set Up Your Project

Use the MCP CLI

The fastest way to scaffold a project is with the MCP command‑line tool.

bash
1mcp create my-mcp-project

This creates a new folder with a basic structure and a sample tool. For more details see the Reddit post introducing the CLI: Introducing MCP‑Framework.

Step 2: Install FastMCP

FastMCP is the recommended Python framework for building MCP servers.

bash
1cd my-mcp-project 2pip install fastmcp

Step 3: Define a Calendar Tool

We'll build a simple event‑calendar MCP server, similar to the one in the Codecademy tutorial.

python
1# calendar_tool.py 2from fastmcp import tool, MCPServer 3 4@tool(name="create_event", description="Create a new calendar event") 5def create_event(title: str, date: str) -> str: 6 # In a real app this would store the event in a DB 7 return f"Event '{title}' scheduled for {date}." 8 9@tool(name="list_events", description="List all calendar events") 10def list_events() -> list: 11 # Placeholder list 12 return ["Meeting at 10am", "Lunch with Alex at 1pm"] 13 14server = MCPServer() 15server.register_tool(create_event) 16server.register_tool(list_events) 17 18if __name__ == "__main__": 19 server.run(host="0.0.0.0", port=8000)

The @tool decorator exposes functions to any MCP‑compatible client.

Step 4: Run the Server

bash
1python calendar_tool.py

You should see something like:

text
1MCP server listening on http://0.0.0.0:8000

Step 5: Test with the MCP Inspector

The MCP Inspector is a web‑based debugging UI. Open your browser and navigate to http://localhost:8000/inspect (or the URL provided by your server). You can manually invoke create_event and list_events to verify they work.

Step 6: Connect Claude Desktop

  1. Open Claude Desktop.
  2. Go to Settings → MCP and add a new endpoint pointing to http://localhost:8000.
  3. Ask Claude: "Show me my calendar events".
  4. Claude will call list_events via the MCP server and display the results.

The Codecademy tutorial walks through this exact flow: Build an MCP Server.


Tips & Best Practices

  • Secure your server – Use HTTPS and authentication if you expose the server beyond localhost.
  • Validate input – Always sanitize parameters received from the AI to avoid injection attacks.
  • Modular design – Keep each tool in its own module for easier maintenance.
  • Logging – Enable detailed logging to troubleshoot communication issues.

Quick Reference Table

CommandDescription
mcp create <project>Scaffold a new MCP project
pip install fastmcpInstall the FastMCP framework
python <file>.pyRun your MCP server
/inspectOpen the MCP Inspector UI

Conclusion

By following these steps you now have a functional MCP server that can create, list, and manage calendar events via natural‑language commands. The same pattern applies to other domains—weather data, file management, or custom business logic. Happy hacking!