Tutorials

How to Build a Free MCP Server (Model Context Protocol)

Learn to build a Model Context Protocol (MCP) server in Python with FastMCP. A practical 2026 guide that wires a free weather API into Claude and Cursor.

FT
Free API Hub Team
·Jun 11, 2026·6 min read
How to Build a Free MCP Server (Model Context Protocol)

The Model Context Protocol (MCP) has quickly become the standard way to give AI assistants like Claude, Cursor and ChatGPT access to your own tools and data. If you have ever wanted your AI assistant to call a real API, read your files, or run your code, an MCP server is how you make that happen — and you can build one for free in about 20 lines of Python.

This guide walks you through building your first MCP server step by step using FastMCP, the Python framework behind most MCP servers in the wild. By the end you will have a working server that fetches live weather from a free API, and you will connect it to Claude so the assistant can call it on demand.

What Is the Model Context Protocol?

MCP is an open protocol that lets an AI client (like Claude Desktop or Cursor) talk to external servers you control. Each server can expose three kinds of things: tools (functions the model can call), resources (read-only data the model can load), and prompts (reusable prompt templates). The client and server speak a shared JSON message format, so any MCP-aware app can use any MCP server without custom glue code.

The practical win is simple: instead of copy-pasting data into a chat, you let the assistant pull it directly. Wire a weather API into a server once, and every MCP client you own can ask for the weather from then on.

What You Will Build

A small MCP server that exposes one tool, get_weather, backed by the free, no-key Open-Meteo API. You will run it locally and connect it to Claude Desktop so you can ask, in plain English, for the current weather anywhere on Earth.

Prerequisites

  • Python 3.10 or newer installed.
  • Basic comfort with the terminal and running a Python file.
  • An MCP client to test with — Claude Desktop (free) or Cursor work well.

Step 1: Install FastMCP

FastMCP wraps the official mcp SDK with a clean, decorator-based API. Install it with pip:

pip install fastmcp httpx

We add httpx too, since the server will make HTTP calls to a free API. That is all the setup you need.

Step 2: Write Your First MCP Server

Create a file called server.py. Start with the smallest server that works — a single tool that adds two numbers:

from fastmcp import FastMCP

mcp = FastMCP("Free API Tools")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers and return the result."""
    return a + b

if __name__ == "__main__":
    mcp.run()

Two details matter here. First, the type hints (a: int) tell FastMCP what arguments the tool takes, and it builds the schema for you automatically. Second, the docstring becomes the tool description the model reads, so write it clearly — the assistant decides whether to call a tool based on that sentence.

Step 3: Add a Tool That Calls a Free API

Now the useful part. Replace the add tool with one that fetches live weather from Open-Meteo, which needs no API key and no signup:

import httpx
from fastmcp import FastMCP

mcp = FastMCP("Free API Tools")

@mcp.tool()
def get_weather(latitude: float, longitude: float) -> dict:
    """Get the current weather for a location by latitude and longitude."""
    url = "https://api.open-meteo.com/v1/forecast"
    params = {"latitude": latitude, "longitude": longitude, "current_weather": True}
    response = httpx.get(url, params=params, timeout=10)
    response.raise_for_status()
    return response.json()["current_weather"]

if __name__ == "__main__":
    mcp.run()

That is a complete, working tool. When the model calls get_weather with coordinates, the server hits Open-Meteo and returns the live result. The timeout and raise_for_status() calls keep things honest: the request fails loudly instead of hanging or returning junk.

Step 4: Add a Resource

Resources are read-only data the client can load for context. Add one that describes the server:

@mcp.resource("info://server")
def server_info() -> str:
    """Short description of what this MCP server provides."""
    return "Free API Hub demo server. Exposes a get_weather tool backed by Open-Meteo."

The string "info://server" is the resource URI the client uses to request it. Tools do things; resources provide things. Most servers use both.

Step 5: Run and Test Your Server

The fastest way to try it before touching any AI client is the built-in inspector:

fastmcp dev server.py

That launches a local web inspector where you can list your tools, fill in arguments, and call get_weather by hand. If the response comes back with a temperature, your server works. To run it normally over the default stdio transport, just use:

python server.py

Step 6: Connect the Server to Claude Desktop

FastMCP can register the server with Claude Desktop for you in one command:

fastmcp install claude-desktop server.py

Prefer to do it manually? Open Claude Desktop's config file (claude_desktop_config.json) and add your server under mcpServers, using an absolute path:

{
  "mcpServers": {
    "free-api-tools": {
      "command": "python",
      "args": ["/absolute/path/to/server.py"]
    }
  }
}

Restart Claude Desktop. You should see your server's tools appear. Now ask: "What is the current weather at latitude 40.71, longitude -74.01?" Claude will call get_weather and answer with live data.

Step 7: Use It in Cursor and Other Clients

Because MCP is a shared standard, the same server works in Cursor, too. Add an entry to Cursor's mcp.json with the same command and args shape, reload, and the get_weather tool is available inside the editor. One server, many clients — that is the point of the protocol.

Common Mistakes to Avoid

  • Using a relative path in the client config. Clients run from a different folder, so always use the absolute path to server.py.
  • Vague docstrings. The model picks tools by their description. "Get current weather by coordinates" works far better than "weather stuff".
  • No error handling on API calls. Keep the timeout and raise_for_status() so a slow or failed request does not stall the whole client.
  • Forgetting to restart the client after editing the config. New servers only load on restart.

Frequently Asked Questions

Is building an MCP server free?

Yes. MCP is an open protocol, the mcp SDK and FastMCP are open source, and the Open-Meteo API used here needs no paid plan. You can build and run everything at no cost.

Do I need Claude to use MCP?

No. MCP is client-agnostic. Claude Desktop, Cursor, and a growing list of other apps support it, and your server works with any of them without changes.

What can a tool return?

Plain text, numbers, or structured data like a dictionary. FastMCP serializes the return value into the response the client reads, so returning a clean dict is usually best.

Can I expose any API as a tool?

Yes. Wrap any HTTP call in a function, add a type-hinted signature and a clear docstring, and decorate it with @mcp.tool(). A directory of free, key-optional APIs makes a great starting point.

stdio or HTTP transport?

Use the default stdio transport for local desktop clients like Claude Desktop. Switch to the HTTP transport when you want to host the server remotely and share it across machines.

Wrapping Up

You built a working MCP server, exposed a real tool backed by a free API, and connected it to Claude and Cursor — the core skills behind every AI-agent integration. From here, add more tools: geocoding, currency rates, dictionary lookups, sports scores. Each one becomes a new capability your assistant can use on demand.

Looking for free, key-optional APIs to turn into MCP tools? Browse the full directory at Free API Hub and pick your next one to wire up.

#MCP#Model Context Protocol#FastMCP#Python#Claude#AI agents#free API
Share this article:
FT
Free API Hub Team
Editorial at FreeAPIHub
The FreeAPIHub editorial team tests every API endpoint, runs every code example, and verifies free tiers before publishing. Corrections and suggestions welcome via GitHub.
Explore the rest of FreeAPIHub

Hand-tested free APIs, AI models, and developer tools — all in one place.

🧩Browse Free APIs🤖Browse AI Models🛠Browse AI Tools🗂Browse Categories

Get 5 new free APIs every week

Free forever. No spam, unsubscribe anytime.

✓ Curated picks✓ Code examples✓ No spam