Access static and templated resources from MCP servers.
New in version 2.0.0Resources are data sources exposed by MCP servers. They can be static files or dynamic templates that generate content based on parameters.
New in version 2.11.0You can use the meta field to filter resources based on their tags:
Copy
async with client: resources = await client.list_resources() # Filter resources by tag config_resources = [ resource for resource in resources if hasattr(resource, '_meta') and resource._meta and resource._meta.get('_fastmcp', {}) and 'config' in resource._meta.get('_fastmcp', {}).get('tags', []) ] print(f"Found {len(config_resources)} config resources")
The _meta field is part of the standard MCP specification. FastMCP servers include tags and other metadata within a _fastmcp namespace (e.g., _meta._fastmcp.tags) to avoid conflicts with user-defined metadata. This behavior can be controlled with the server’s include_fastmcp_meta setting - when disabled, the _fastmcp namespace won’t be included. Other MCP server implementations may not provide this metadata structure.
Read from a resource template by providing the URI with parameters:
Copy
async with client: # Read a resource generated from a template # For example, a template like "weather://{{city}}/current" weather_content = await client.read_resource("weather://london/current") # Access the generated content print(weather_content[0].text) # Assuming text JSON response
async with client: content = await client.read_resource("resource://config/settings.json") for item in content: if hasattr(item, 'text'): print(f"Text content: {item.text}") print(f"MIME type: {item.mimeType}")
async with client: content = await client.read_resource("resource://images/logo.png") for item in content: if hasattr(item, 'blob'): print(f"Binary content: {len(item.blob)} bytes") print(f"MIME type: {item.mimeType}") # Save to file with open("downloaded_logo.png", "wb") as f: f.write(item.blob)
Resource URIs and their formats depend on the specific MCP server implementation. Check the server’s documentation for available resources and their URI patterns.