AI Hints
Home›MCP Tutorial›Resources Quiz and Prompts
MCP · Lesson 42 of 120

Prompt Arguments

Fill in the blanks.

⏱ 2 min read▶ Video at 38:08🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

Prompt arguments work like tool inputs. Each parameter becomes an argument the user fills in. Optional ones have defaults, and descriptions help the user know what to type.

Prompt Arguments
From the video: Prompt Arguments
  • Like tool inputs
  • Users fill them
  • Defaults and descriptions

A prompt with options

Tone has a default of friendly. The client sees each argument, with whether it's required. We fill only the required one. Run it. The arguments are listed, and the default tone is used.

prompt_args.pypython
import asyncio
from mcp import Client
from mcp.server.mcpserver import MCPServer

mcp = MCPServer("northwind")

@mcp.prompt()
def apology(customer: str, problem: str, tone: str = "friendly") -> str:
    """Draft an apology email to a customer."""
    return f"Write a {tone} apology to {customer} about: {problem}"

async def main():
    async with Client(mcp) as client:
        p = (await client.list_prompts()).prompts[0]
        print([(a.name, a.required) for a in p.arguments])
        r = await client.get_prompt("apology", {"customer": "Sam", "problem": "a late delivery"})
        print(r.messages[0].content.text)
asyncio.run(main())
Output
[('customer', True), ('problem', True), ('tone', False)]
Write a friendly apology to Sam about: a late delivery

Summary

Prompt parameters become arguments. Defaults make them optional. Next, prompts with more than one message.

Key takeaways
  • Arguments
  • required
  • Defaults
Next up: Multi-Message Prompts — a short conversation