Educational example of building MCP prompts with FastMCP โ€” from a simple string template to multi-turn conversations

๐Ÿงฉ FastMCP Prompts Example

Follow on XWhatsApp ChannelLicense

PythonFastMCPMCPuv

A small, focused tutorial showing how to build MCP prompts with FastMCP โ€” reusable, parameterized message templates that any MCP client (Claude Desktop, IDEs, custom agents) can discover and render.

๐Ÿ“š Perfect as a first step into the Model Context Protocol before diving into tools and resources.

๐Ÿ“– What are MCP prompts?

While MCP tools let a model do things and resources let it read things, prompts are user-controlled templates: the client lists them, fills in their arguments, and injects the rendered messages into the conversation. Think of them as slash commands for LLMs.

โœจ What this example covers

main.py demonstrates the three patterns you'll use most, from simplest to most powerful:

# Prompt Pattern Concept demonstrated
1 research_prompt Return a plain str Simplest form โ€” auto-wrapped in a single user message
2 summarize_prompt Optional + constrained args Literal types & defaults become a client-visible argument schema
3 code_review_prompt Return list[Message] Seed a full multi-turn conversation (user + assistant messages)

Along the way you'll also see: naming, descriptions, tags, and server instructions.

๐Ÿš€ Quickstart

Prerequisites: Python 3.12+ and uv.

# 1. Clone and enter the project
git clone https://github.com/mohamedelamraoui1/fastMCP-2-0-example.git
cd fastMCP-2-0-example

# 2. Install dependencies
uv sync

# 3. Run the server (stdio transport)
uv run main.py

If everything is set up correctly, you'll see the FastMCP banner and the server waiting for a client on stdio:

FastMCP server startup banner

๐Ÿ” Test with the MCP Inspector

The fastest way to explore the prompts is the MCP Inspector โ€” a web UI for poking at any MCP server. It requires Node.js (the Inspector is an npm package that FastMCP launches for you).

Step 1 โ€” Launch the Inspector:

uv run fastmcp dev inspector main.py

You'll see output like this, and your browser opens automatically:

๐Ÿš€ MCP Inspector is up and running at:
   http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=<session-token>
โš™๏ธ Proxy server listening on localhost:6277

If the browser doesn't open, copy the full URL (including the token) from the terminal.

Step 2 โ€” Connect to the server. The connection form is pre-filled (transport STDIO, command fastmcp run main.py). Just click Connect โ€” the indicator turns green when the handshake succeeds.

Step 3 โ€” List the prompts. Open the Prompts tab and click List Prompts. You should see all three: research_prompt, summarize_prompt, and code_review_prompt, each with its description.

Step 4 โ€” Render a prompt. Click a prompt, fill in its arguments in the form (e.g. topic = "quantum computing" for research_prompt), and click Get Prompt. The right panel shows the exact messages the server returns.

Step 5 โ€” See the interesting cases:

  • On summarize_prompt, notice the length and tone fields only accept the Literal values from the type hints โ€” that's the argument schema in action.
  • On code_review_prompt, paste any snippet as code and notice the result is three messages (user โ†’ assistant โ†’ user), not one โ€” a pre-seeded conversation.

When you're done, stop the Inspector with Ctrl+C in the terminal.

๐Ÿ–ฅ๏ธ Use it from Claude Desktop

Add the server to your Claude Desktop config (claude_desktop_config.json):

{
  "mcpServers": {
    "prompt-examples": {
      "command": "uv",
      "args": ["run", "--directory", "C:/absolute/path/to/fastMCP-2-0-example", "main.py"]
    }
  }
}

Restart Claude Desktop, then look for the prompts in the + (attachments) menu.

๐Ÿ’ก No API key needed. Claude Desktop uses your Claude account, and this MCP server only serves prompt templates โ€” it never calls an LLM itself. You'd only need an Anthropic API key if you wrote your own client that sends the rendered prompts to the API.

๐Ÿ—‚๏ธ Project structure

.
โ”œโ”€โ”€ main.py          # The MCP server โ€” 3 prompt patterns, fully commented
โ”œโ”€โ”€ assets/          # Screenshots used in this README
โ”œโ”€โ”€ pyproject.toml   # Project metadata & dependencies
โ”œโ”€โ”€ uv.lock          # Locked dependency versions
โ””โ”€โ”€ README.md

๐Ÿ“š Learn more

๐Ÿ› ๏ธ Tech stack

Technology Role
Python 3.12+ Language
FastMCP 3.x MCP server framework
uv Dependency & environment management

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.

Made with โค๏ธ for the MCP community. Follow @mcoding_off for more tutorials.

MCP Server ยท Populars

MCP Server ยท New

    DareDev256

    FCPXML MCP

    ๐ŸŽฌ The first AI-powered MCP server for Final Cut Pro XML. Control your edits with natural language.

    Community DareDev256
    acunningham-ship-it

    Veil

    Stealth browser for AI agents โ€” real Chrome over raw CDP, no Playwright/Puppeteer. TypeScript + MCP-native. Passes sannysoft 57/57, bypasses Cloudflare.

    Cassette-Editor

    Oh My Cassette: Chat Your Raw Clips Into a Finished Cut

    ไฝ ็š„้š่บซ AI ๅ‰ช่พ‘ๆญๆกฃ | Pocket AI co-editor for video montage โ€” AI video editing plugin & MCP server for Claude Code, Codex, Hermes & OpenCode

    Community Cassette-Editor
    trendsmcp-ai

    Trends MCP

    MCP server for live trend data. Query Google Search, YouTube, TikTok, Reddit, Amazon, Wikipedia, News sentiment, Web Traffic, App Downloads, Steam, npm and more. Works with Claude, Cursor, VS Code, GitHub Copilot, ChatGPT, Windsurf, Cline, Raycast and any MCP-compatible.

    Community trendsmcp-ai
    jacob-bd

    Gemini Notebook (formerly Google NotebookLM) CLI & MCP Server

    Programmatic access to Gemini Notebook - via command-line interface (CLI), Model Context Protocol (MCP) server, and AI agent skills.

    Community jacob-bd