FastMCP Prompts Example

FastMCP Prompts Example

A tutorial demonstrating how to build reusable, parameterized MCP prompt templates using FastMCP, including patterns for research, summarization, and code review.

Category
访问服务器

README

🧩 FastMCP Prompts Example

Follow on X WhatsApp Channel License

Python FastMCP MCP uv

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 (userassistantuser), 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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选