RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /MCP Server Implementation
  6. /Ch. 7
MCP Server Implementation

07. Prompts in MCP

Chapter 7 of 22 · 20 min
KEY INSIGHT

Prompts are reusable template structures that standardize complex AI interactions across multiple invocations. Prompts in MCP provide pre-defined templates that clients can invoke. Rather than repeating complex prompt construction, clients reference prompt names and provide arguments. **Prompt Definition:** ```python from mcp.types import Prompt, PromptArgument review_prompt = Prompt( name="code_review", description="Generate a code review for the provided diff", arguments=[ PromptArgument( name="language", description="Programming language of the code", required=True ), PromptArgument( name="diff", description="Git diff to review", required=True ) ] ) ``` **Implementing Prompt Handlers:** ```python @app.list_prompts() async def list_prompts() -> list[Prompt]: return [ review_prompt, Prompt( name="debug_assistant", description="Systematic debugging assistance", arguments=[ PromptArgument( name="error_message", description="Error to investigate", required=True ) ] ) ] @app.get_prompt() async def get_prompt(name: str, arguments: dict) -> GetPromptResult: match name: case "code_review": return GetPromptResult( messages=[ PromptMessage( role="user", content=TextContent( type="text", text=f"Review this {arguments['language']} code:\n\n{arguments['diff']}" ) ) ] ) ``` **Prompt Composition:** Prompts can include multiple messages with different roles. This enables few-shot learning within prompts. ```python case "debug_assistant": return GetPromptResult( messages=[ PromptMessage( role="system", content=TextContent( type="text", text="You are a debugging specialist. Ask clarifying questions before proposing solutions." ) ), PromptMessage( role="user", content=TextContent( type="text", text=f"Error encountered: {arguments['error_message']}" ) ) ] ) ``` **Static Prompts:** Some prompts require no arguments. These work well for system-level instructions. ```python system_prompt = Prompt( name="security_reminder", description="Standard security reminder for sensitive operations", arguments=[] ) ``` **Dynamic Prompts:** Prompts can reference current resources or state: ```python case "status_report": current_status = get_system_status() # Fetch live data return GetPromptResult( messages=[ PromptMessage( role="user", content=TextContent( type="text", text=f"System status:\n{current_status}" ) ) ] ) ``` **Use Cases:** Prompts excel for: code review templates, debugging workflows, documentation generation, testing checklists. Any repetitive prompt structure benefits from extraction into a prompt.

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Create three prompts for a documentation workflow: (1) api_doc_template taking endpoint and method arguments, (2) readme_generator taking project_name and features arguments, (3) changelog_entry with no arguments that includes current date automatically.

← Chapter 6
Tools in MCP
Chapter 8 →
File System Server