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

Using Prompts

From the client.

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

When a user picks a prompt, the host gets its messages, and sends them to the model. Let's do that ourselves. Get the triage prompt, then pass its messages to Gemini.

Using Prompts
From the video: Using Prompts
  • User picks a prompt
  • Host gets messages
  • Sends to the model

Prompt to model

We get the triage prompt with a customer message. Each MCP message becomes a role and text pair for LangChain. Then the model replies. Run it. The model answers with a single category.

use_prompt.pypython
import asyncio
from mcp import Client
from langchain.chat_models import init_chat_model
from triage_server import mcp

llm = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)

async def main():
    async with Client(mcp) as client:
        prompt = await client.get_prompt("triage", {"message": "My order hasn't arrived"})
    messages = [(m.role, m.content.text) for m in prompt.messages]
    print("category:", llm.invoke(messages).text)

asyncio.run(main())
Output
category: Orders
Also uses triage_server.py
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.prompts.base import UserMessage, AssistantMessage

mcp = MCPServer("northwind")

@mcp.prompt()
def triage(message: str) -> list:
    """Sort a customer message into a category."""
    return [UserMessage(f"Customer wrote: {message}"),
            AssistantMessage("I'll sort this into orders, returns, or repairs."),
            UserMessage("Reply with just the category.")]

Summary

A host gets a prompt's messages and sends them to the model, as the start of the chat. Next, completions.

Key takeaways
  • get_prompt
  • Convert messages
  • Send to model
Next up: Completions — suggest argument values