📚 Resources: Exposing data
Resources let you provide data to Claude without requiring a function call. The Host automatically includes resources in the model's context.
Types of resources
Static resources
Fixed data that doesn't change. Example: company documentation, a knowledge base entry, or API reference.
Dynamic resources
Data that changes. Example: current file contents, database records, or recent Git commits. Fetched on-demand.
URI-templated resources
Parameterised resources. Example: file://{path} — Claude can request any file by path.
Implementing resources
from mcp.types import Resource, TextContent
@server.read_resource()
def read_resource(uri: str):
if uri == "docs://readme":
return TextContent(
type="text",
text="# My Project\nThis is the README..."
)
return None
# Register the resource
server.resources = [
Resource(
uri="docs://readme",
name="README",
description="Project documentation"
)
]
💬 Prompts: Reusable instructions
Prompts are parameterised instruction templates. Think of them as "use cases" that Claude can invoke to run standardised workflows.
from mcp.types import Prompt
@server.get_prompt()
def get_prompt(name: str, arguments: dict):
if name == "code_review":
code = arguments.get("code", "")
return (
"Review this code for best practices:\n"
f"```\n{code}\n```\n\n"
"Provide constructive feedback."
)
return None
server.prompts = [
Prompt(
name="code_review",
description="Review code for best practices",
arguments=[
{
"name": "code",
"description": "The code to review"
}
]
)
]
When to use Resources vs Prompts
| Resources | Prompts | |
|---|---|---|
| Purpose | Provide data to reference | Standardise workflows |
| When Claude uses it | Automatically, to provide context | When explicitly invoked |
| Example | Company knowledge base, file contents | Code review template, customer support classifier |
Quick summary
- Resources provide data Claude can reference (static or dynamic)
- Prompts are reusable instruction templates with parameters
- Combine Tools, Resources, and Prompts to build powerful, flexible servers
- Next: real-world examples where all three work together