Exposing resources
Resources are how a server offers data for context without the model having to call a function. They are read-only and addressed by URI.
What a resource is #
A resource is a piece of data the server can hand over: a file, a config, a database record, a document. Each has a URI (like file:///logs/app.log or db://customers/42), a name, and a MIME type. The host reads resources and decides which to place in context.
Resources vs tools #
The key distinction is control and effect. A tool is called by the model and can have side effects. A resource is selected by the application and only supplies data. If reading it should never change anything, it is a resource.
python@mcp.resource("config://app")
def app_config() -> str:
"""The current application configuration."""
return read_config()
Dynamic resources #
Resources can be templated with parameters (for example db://customers/{id}) so the host can request a specific record. Keep them read-only and cheap; anything expensive or mutating belongs in a tool.
Resources & further reading
- MCP specification MCPThe authoritative protocol spec: messages, capabilities, transports, and lifecycle.
- Python SDK GitHubThe official Python SDK for building MCP servers and clients.