embedded() method simplifies including resources in tool responses, reducing code duplication and making it easier to reference resources from within tools.
Basic usage
Useserver.embedded() to include a resource in a tool’s response:
With resource templates
Embedded resources work seamlessly with resource templates:Multiple embedded resources
Include multiple resources in a single response:Dynamic resource URIs
Construct resource URIs dynamically based on tool parameters:With text and images
Combine embedded resources with text and images:Error handling
Handle errors when resources don’t exist:Best practices
Define resources separately
Define resources as standalone entities, then reference them in tools. This promotes reusability.
Cache expensive operations
If resource loading is expensive, implement caching in the load function.
Next steps
Resources
Learn more about defining resources
Tools
Back to tool documentation