Summary audio
No audio recap for this lesson.
Study notes
Overview
- Prompts are the final major feature in MCP servers (after resources and tools)
- They allow server authors to expose pre-built, well-tested prompts to client applications
- Users can already accomplish tasks manually, but custom prompts provide better, more reliable results
Purpose of Prompts
- Define high-quality, specialized prompts ahead of time that are tailored to the server's domain
- Prompts have been evaluated and tested to work across various scenarios
- Expose these prompts so clients don't need to develop their own or guess at optimal wording
- Example: a document management server can provide a "format document" prompt instead of leaving users to write their own instructions
How Prompts Work
- Prompts are defined using the @prompt decorator (similar to tools and resources)
- Each prompt has a name and optional description
- Prompts accept arguments (like a document ID) that can be interpolated into the prompt text
- When a client requests a prompt, the server returns a list of messages (user and assistant messages)
- These messages can be sent directly to Claude for processing
Implementation Structure
- Use @prompt decorator with name and description
- Function receives arguments (e. g. , doc_id: string)
- Return a list of messages containing the pre-written prompt
- Arguments are interpolated into the prompt text before returning
Example: Format Document Prompt
- Accepts a document ID as input
- Instructs Claude to read the document using available tools
- Asks Claude to rewrite content in markdown syntax
- Optionally instructs Claude to save changes back to the document
Takeaways
- Prompts are pre-built, tested, domain-specific instructions that MCP servers expose to clients, eliminating the need for users to write their own prompts
- Prompts are defined using the @prompt decorator and accept arguments that get interpolated into the prompt text
- When a client requests a prompt, the server returns a list of messages that can be sent directly to Claude for processing
- Prompts provide better, more reliable results than manual task completion by leveraging server authors' expertise and testing
Flashcards 10 cards
Question
click to reveal · ←/→
Answer
click to flip back
Knowledge check 1 questions