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·Eruo Fredoline
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. 5
MCP Server Implementation

05. Resources in MCP

Chapter 5 of 22 · 20 min
KEY INSIGHT

Resources expose data to AI applications through a URI-based system with optional change subscriptions that keep AI context current. Resources in MCP represent data that servers expose to clients. Unlike tools, resources do not perform actionsΓÇöthey provide information. AI applications request resources when context is needed for task completion. **Resource Structure:** Each resource has a URI, name, description, and MIME type. URIs follow a custom scheme that the server defines. ```python from mcp.types import Resource, ResourceTemplate # Single resource file_resource = Resource( uri="file:///config/app.yaml", name="application_config", description="Current application configuration", mimeType="application/yaml" ) # Resource template (dynamic resources) config_template = ResourceTemplate( uriTemplate="file:///config/{filename}", name="dynamic_config", description="Configuration files by name", mimeType="application/yaml" ) ``` **Implementing Resource Handlers:** Servers must implement handlers for listing and reading resources. ```python @app.list_resources() async def list_resources() -> list[Resource]: return [ Resource( uri="file:///data/status.txt", name="status", description="System status file", mimeType="text/plain" ) ] @app.read_resource() async def read_resource(uri: str) -> str: if uri == "file:///data/status.txt": with open("/data/status.txt", "r") as f: return f.read() raise ValueError(f"Unknown resource: {uri}") ``` **Resource Templates:** Templates handle dynamic resource URIs. The client provides substituted values when requesting. ```python @app.list_resource_templates() async def list_resource_templates() -> list[ResourceTemplate]: return [ ResourceTemplate( uriTemplate="file:///users/{user_id}/profile", name="user_profile", description="User profile by ID" ) ] @app.read_resource() async def read_resource(uri: str) -> str: # Parse template variables from URI if uri.startswith("file:///users/"): user_id = uri.split("/")[3] return get_user_profile(user_id) ``` **Change Notifications:** Resources can notify clients when content changes. This keeps AI context accurate without repeated polling. ```python # Server sends notification when resource changes await app.request_context.session.send_resource_updated( uri="file:///data/status.txt" ) ``` Clients subscribe to resources during listing. Servers must track subscriptions and send updates accordingly. **Failure Modes:** - Missing resource files return appropriate errors, not empty strings - Large resources should stream or limit size - Permissions errors surface as specific error codes, not generic failures

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

Build a resource server that exposes two resources: a static "about" document and a dynamic resource showing the server's current memory usage. Implement subscriptions for the memory resource.

← Chapter 4
Python SDK Setup
Chapter 6 →
Tools in MCP