AI Hints
Home›MCP Tutorial›Richer Prompts
MCP · Lesson 44 of 120

Prompts with Resources

Embed the data.

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

A good prompt often needs data. A returns question prompt should include the returns policy. The prompt function can read that data, and put it right into the message.

Prompts with Resources
From the video: Prompts with Resources
  • Prompts need data
  • Include the policy
  • In the message

Policy inside the prompt

The returns policy function is a resource. The prompt calls the same function, and puts the policy text into the message. Run it. The prompt arrives with the policy already inside.

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

mcp = MCPServer("northwind")
@mcp.resource("policy://returns")
def returns_policy() -> str:
    """Northwind's returns policy."""
    return "You can return any unused item within 30 days of delivery."

@mcp.prompt()
def returns_question(question: str) -> str:
    """Answer a returns question using the policy."""
    return f"Policy: {returns_policy()}\n\nUsing only the policy, answer: {question}"

async def main():
    async with Client(mcp) as client:
        print((await client.get_prompt("returns_question", {"question": "Can I return a used saddle?"})).messages[0].content.text)
asyncio.run(main())
Output
Policy: You can return any unused item within 30 days of delivery.

Using only the policy, answer: Can I return a used saddle?

Data in prompts

Put the facts the model needs right in the prompt. Reuse your resource functions, so there's one source of truth. And keep the data short, because it all goes into the context.

keyvalue
Includethe facts needed
Reuseresource functions
One sourceof truth
Keepit short

Summary

Prompts can include resource data, so the model gets the facts with the instructions. Next, using prompts from the client.

Key takeaways
  • Call the resource
  • Into the message
  • One source of truth
Next up: Using Prompts — from the client