Featured

Deploy OpenClaw in 60 seconds — 20% off logoDeploy OpenClaw in 60 seconds — 20% off

Launch OpenClaw on Hostinger in about 60 seconds and keep your agent live 24/7. Our referral link gives you 20% off, no coupon code needed.

Launch on Hostinger
Run your Hermes agent on Hostinger, fully managed logoRun your Hermes agent on Hostinger, fully managed

Launch Hermes on Hostinger in one click, fully managed, no VPS knowledge needed. Use code ZACAARON10 for 10% off.

Launch on Hostinger
Crawl and scrape any site into clean data, 10% off logoCrawl and scrape any site into clean data, 10% off

Firecrawl crawls and scrapes any site into clean markdown for your agent. Get 1,000 free credits, and new users get 10% off their first purchase.

Try Firecrawl free
6,000+ web scrapers for your AI agent, start free logo6,000+ web scrapers for your AI agent, start free

Apify gives your agent live web data: 6,000+ prebuilt scrapers and actors, MCP-ready. Sign up free with $5 in usage credits.

Try Apify free
One API to scrape, enrich, and extract the internet. logoOne API to scrape, enrich, and extract the internet.

Context.dev gives your agents a single API to scrape, enrich, and extract live web data — no proxies, no parsers, no maintenance.

Start building free
SetupClaw: done-for-you OpenClaw for founders & exec teams logoSetupClaw: done-for-you OpenClaw for founders & exec teams

White-glove OpenClaw for founders and exec teams (4–50+ employees): we install, harden, integrate your tools, and maintain it — secured from day one.

Get it set up for you
SEO data APIs for your agent, $1 free credit logoSEO data APIs for your agent, $1 free credit

DataForSEO gives your agent live access to SERP results, keyword data, backlinks, and on-page SEO data through one API. New accounts get a $1 credit, good for up to 20,000 keyword or backlink lookups.

Try DataForSEO free
Reach 48,000+ AI builders

A flat monthly placement in front of developers actively installing AI tools. No lock-in, cancel anytime.

Advertise here

Works with

Claude CodeClaude DesktopCursorVS CodeClineCodex CLIOpenClaw+ any MCP client

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

A basic MCP server demonstrating tool registration and SSE transport, enabling AI clients to call greeting, arithmetic, and time tools.

README.md

MCP Server with FastAPI (Python)

A hands-on implementation of a Model Context Protocol (MCP) server built with Python using the official MCP SDK and FastAPI/Starlette.

What is MCP?

Model Context Protocol (MCP) is an open standard that enables AI assistants (like Claude, Kiro, Cursor) to connect with external tools, data sources, and APIs through a unified interface — similar to how USB-C standardized device connectivity.

┌─────────────┐         ┌─────────────┐         ┌──────────────┐
│  AI Client  │  ←───→  │  MCP Server │  ←───→  │  Your Tools/ │
│(Claude/Kiro)│  JSON   │  (This Repo)│         │  Data/APIs   │
└─────────────┘         └─────────────┘         └──────────────┘

Features

  • Tools: Functions that AI clients can discover and call
  • greet — Returns a greeting for a given name
  • add_numbers — Adds two numbers and returns the result
  • get_current_time — Returns the current date and time
  • SSE Transport: Server-Sent Events based communication (HTTP)
  • Test Client: A Python client that connects to the server and calls all tools

Tech Stack

  • Python 3.13+
  • MCP Python SDK (v1.9)
  • FastAPI / Starlette
  • Uvicorn (ASGI server)
  • SSE (Server-Sent Events) transport

Getting Started

Prerequisites

  • Python 3.10+
  • pip

Installation

git clone https://github.com/MuhammadIshaqSkd/mcp-fastapi-tutorial.git
cd mcp-fastapi-tutorial

# Create virtual environment
python -m venv venv

# Activate (Windows)
.\venv\Scripts\activate

# Activate (macOS/Linux)
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Running the Server

python server.py

Server starts on http://127.0.0.1:8080 with SSE endpoint at /sse.

Testing with the Client

Open a second terminal (keep the server running):

python test_client.py

Expected output: ``` ================================================== MCP Client - Connecting to server... ==================================================

✅ Connection successful!

📋 Available Tools: ------------------------------ 🔧 greet: Greet someone by name and return a greeting message. 🔧 add_numbers: Return the sum of two numbers. 🔧 get_current_time: Return the current date and time.

🎯 Calling 'greet' tool... Result: Assalam-o-Alaikum, Mishaq! MCP Server se aapko salam!

🎯 Calling 'add_numbers' tool... Result: 15 + 27 = 42

🎯 Calling 'get_current_time' tool... Result: Current time: 2026-06-22 18:15:09

================================================== 🎉 All tools called successfully! ================================================== ```

Project Structure

mcp-fastapi-tutorial/
├── server.py           # MCP Server — registers and exposes tools via SSE
├── test_client.py      # MCP Client — connects to server, lists & calls tools
├── requirements.txt    # Python dependencies
└── README.md

How It Works

  1. Server registers tools using @mcp.tool() decorator
  2. Client connects via SSE to /sse endpoint
  3. Client calls list_tools() to discover available tools
  4. Client calls call_tool("tool_name", {args}) to execute a tool
  5. Server executes the function and returns the result

Key Concepts Demonstrated

| Concept | Description | |---------|-------------| | Tool Registration | Using @mcp.tool() to expose Python functions as MCP tools | | SSE Transport | HTTP-based bidirectional communication via Server-Sent Events | | Client Session | Initializing and managing MCP client-server sessions | | Tool Discovery | Clients dynamically discover available tools at runtime | | Tool Execution | Remote procedure call pattern over the MCP protocol |

Roadmap

  • [x] Basic MCP server with tools
  • [ ] Add Resources (context/data providers for AI)
  • [ ] Add Prompts (reusable prompt templates)
  • [ ] Streamable HTTP transport
  • [ ] Authentication & authorization
  • [ ] Deploy to cloud

Resources

License

MIT

See related servers & alternatives →

Related MCP servers

Browse all →

Related guides

Hand-picked reading to help you choose and use AI & ML servers.