Files
mcp-use__mcp-use/docs/python/server/prompts.mdx
Pietro Zullo 8348c59a53 docs: reorganize, fix accuracy, and update for agent readability (#1502)
* docs: reorganize navigation and clean up content

- Remove 'Misc' group with misplaced blog posts
- Remove 'Libraries' redirect group from Home nav
- Simplify 'Dev Tools' group (flatten Inspector, CLI, Tunneling)
- Remove individual changelog versions from Python nav (keep summary)
- Remove changelog from TypeScript 'Get Started' group
- Remove tunneling duplicate from Python Development group
- Rewrite mcp101 as clean MCP concepts page (was pitch deck)
- Delete typescript/blog posts (not technical docs)
- Add redirects for deleted blog post URLs

* docs: fix content accuracy and remove sloppy language

- Fix broken python/server/mcp-apps link in home page
- Remove informal pitch-speak from python/server/index.mdx
- Fix grammar error in typescript/server/index.mdx
- Update typescript/client/logging.mdx: remove fake 'coming soon' API code
- Fix non-existent model name gpt-5.1 in typescript quickstart
- Fix mcp_use naming in development contributing guide

* docs: fix incorrect TypeScript server API calls in inspector docs

- Replace server.addTool() with server.tool() (correct mcp-use API)
- Add missing zod import to debugging-chatgpt-apps example

* docs: fix fake model names (gpt-5.1 → gpt-4o) in agent docs

* docs: update model names, fix APIs, and add agent visibility hints

- Replace all deprecated model names with latest: gpt-4.1, gpt-4.1-mini,
  claude-sonnet-4-6, claude-opus-4-7, gemini-2.5-flash across all docs
- Fix TypeScript server.tool() API in installation.mdx (old positional string form)
- Fix TypeScript agent.run() in quickstart.mdx (deprecated string form → object)
- Remove broken manufact.com/docs/llms.txt hidden hints from 5 pages
- Add <Visibility for="agents"> block to mcp101.mdx with install commands,
  key classes, and API signatures for agent-oriented navigation
- Add LangChain provider install note to Python quickstart (mcp-use agent
  requires a separate langchain-* provider package)
- Update model name cards in Python llm-integration.mdx

* docs: clean up remaining stale model names and improve accuracy

- Update supported model lists in Python and TypeScript llm-integration pages
- Fix cost optimization table to use current model IDs
- Update TypeScript agent overview supported providers list

* docs: add LangChain provider install to TypeScript quickstart agent section

The MCPAgent requires a separate @langchain/* provider package; this was
not mentioned before the code example that imports from @langchain/openai.

* docs: update to latest flagship model IDs (May 2026)

- OpenAI: gpt-4.1 → gpt-5.5, gpt-4.1-mini → gpt-5.5-mini
- Google: gemini-2.5-flash → gemini-3.1-flash, gemini-2.5-pro → gemini-3.1-pro
- Groq: llama-3.1-* → llama-4-scout-17b-16e-instruct
- Anthropic (claude-opus-4-7, claude-sonnet-4-6) already current, no change

* docs: replace all em dashes with hyphens

* docs: restore llms.txt hints using Visibility component

* docs: simplify TypeScript logging page to unsupported notice only

* docs: rewrite mcp101 to explain MCP protocol with mcp-use examples and doc links

* docs: remove goal.md

* docs: revert nav changes, keep only Misc group removal and blog redirects

* docs: reorder mcp101 to Server/App -> Client/Inspector -> Agent, restore title

* docs: add code examples for Resources and Prompts in mcp101

* docs: remove em dashes from mcp101

* docs: add MCPClient code examples to mcp101

* docs: add React client example to mcp101

* docs: add agent code examples to mcp101

* docs: expand MCP Apps section in mcp101 with example and links

* docs: restore Contacts, Socials, and Founders sections to mcp101

* docs: add context-setting intro paragraph to mcp101 for new readers

* docs: add MCP stores section to mcp101 intro with Claude, ChatGPT, Cursor

* docs: fix Claude store link

* docs: fix ChatGPT store link

* docs: fix Cursor store link

* docs: replace store Cards with linked image grid

* docs: add captions to store images

* docs: add Notifications to client primitives table in mcp101

* docs: add lead-in paragraph before resource cards at bottom of mcp101

* docs: move resource cards to end of page after Contacts/Socials/Founders

* docs: demote Contacts/Socials/Founders to bold text to remove from TOC

* docs: move Contacts/Socials/Founders to very end of mcp101

* docs: add Resources and Contacts section headers, link official MCP docs

* chore(docs): update site metadata, footer links, and rename mcp_use to mcp-use

* update docs metadata + images

* docs: enhance MCP section by highlighting the reach of MCP stores with 1 billion weekly active users

* api ref
2026-05-14 18:49:06 +02:00

180 lines
5.3 KiB
Plaintext

---
title: "Prompts"
description: "Define and expose prompts from your MCP server"
icon: "message-square"
---
Prompts are reusable message templates that help AI agents interact with your server effectively. They provide structured ways to guide conversations and standardize common interactions.
## Example
```python
@server.prompt(
name="code_review",
title="Code Review",
description="Generate a code review prompt for a given language and focus area",
)
def code_review_prompt(language: str, focus: str = "general") -> str:
"""Generate a code review prompt."""
focus_instructions = {
"general": "for overall quality, readability, and best practices.",
"security": "focusing on security vulnerabilities and potential exploits.",
"performance": "focusing on performance optimizations and efficiency.",
}
instruction = focus_instructions.get(focus, focus_instructions["general"])
return f"Please review the following {language} code {instruction}"
```
## Anatomy of a Prompt
When a client calls `prompts/list`, the server returns metadata for each prompt including its arguments. Here's the JSON-RPC response that the example above produces when a client calls `prompts/list`:
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"prompts": [
{
"name": "code_review",
"title": "Code Review",
"description": "Generate a code review prompt for a given language and focus area",
"arguments": [
{
"name": "language",
"required": true
},
{
"name": "focus",
"required": false
}
]
}
]
}
}
```
Here's what maps to what:
| Python | MCP Schema | Notes |
|--------|-----------|-------|
| `name="code_review"` | `"name"` | Falls back to function name if omitted |
| `title="Code Review"` | `"title"` | Human-readable display name |
| `description="Generate a code review..."` | `"description"` | Falls back to docstring if omitted |
| `language: str` (no default) | `{"name": "language", "required": true}` | Parameters without defaults are required |
| `focus: str = "general"` | `{"name": "focus", "required": false}` | Parameters with defaults are optional |
| `context: Context` | *(not in schema)* | Automatically excluded |
### Argument Descriptions
You can add descriptions to prompt arguments the same way as tools, using `Annotated` and `Field`:
```python
from typing import Annotated
from pydantic import Field
@server.prompt(name="code_review")
def code_review_prompt(
language: Annotated[str, Field(description="The programming language of the code")],
focus: Annotated[str, Field(description="Review focus area", default="general")],
) -> str:
"""Generate a code review prompt."""
return f"Please review the following {language} code for {focus}."
```
This adds `description` to each argument in the response:
```json
{
"arguments": [
{
"name": "language",
"description": "The programming language of the code",
"required": true
},
{
"name": "focus",
"description": "Review focus area",
"required": false
}
]
}
```
## Minimal Definition
At minimum, a prompt only needs a function:
```python
@server.prompt()
def greeting() -> str:
"""A friendly greeting prompt."""
return "Hello! How can I help you today?"
```
The function name becomes the prompt name, and the docstring becomes the description.
## Using Context
Access the MCP context for advanced features. Add a `Context` parameter - it's automatically excluded from the prompt's arguments:
```python
from mcp_use.server import Context
@server.prompt(name="contextual")
async def contextual_prompt(context: Context) -> str:
"""A prompt that uses context information."""
return "Based on the current context, please..."
```
## Multi-Message Prompts
Return structured messages for complex prompts:
```python
from mcp.types import PromptMessage, TextContent
@server.prompt(name="interview")
def interview_prompt(role: str) -> list[PromptMessage]:
"""Generate an interview prompt sequence."""
return [
PromptMessage(
role="user",
content=TextContent(
type="text",
text=f"I'm interviewing for a {role} position.",
),
),
PromptMessage(
role="assistant",
content=TextContent(
type="text",
text=f"I'll help you prepare for your {role} interview. Let's start with common questions.",
),
),
]
```
## Async Prompts
Prompts can be async for dynamic content generation:
```python
@server.prompt(name="daily_brief")
async def daily_brief() -> str:
"""Generate a daily briefing prompt."""
from datetime import datetime
today = datetime.now().strftime("%A, %B %d")
return f"Good morning! Today is {today}. What would you like to accomplish?"
```
## Prompts vs Tools vs Resources
| Aspect | Prompts | Tools | Resources |
|--------|---------|-------|-----------|
| Purpose | Guide interactions | Perform actions | Expose data |
| Returns | Message templates | Action results | Content/data |
| Use case | Conversation starters, templates | Operations | Files, configs |
| Invocation | User selects prompt | Agent calls tool | Agent reads resource |