Skip to main content
The embedded() method simplifies including resources in tool responses, reducing code duplication and making it easier to reference resources from within tools.

Basic usage

Use server.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

1

Define resources separately

Define resources as standalone entities, then reference them in tools. This promotes reusability.
2

Use descriptive URIs

Choose clear, hierarchical URI schemes that make the resource purpose obvious.
3

Cache expensive operations

If resource loading is expensive, implement caching in the load function.
4

Document resource structure

Provide clear descriptions for resource templates to help users understand what they contain.

Next steps

Resources

Learn more about defining resources

Tools

Back to tool documentation