fastmcp/docs/servers/transforms
Jeremiah Lowin f9ed06176a
fix: route ResourcesAsTools/PromptsAsTools through server middleware (#3495)
* fix: enforce auth/visibility in ResourcesAsTools and PromptsAsTools for non-FastMCP providers

🤖 Co-authored-by: Claude <noreply@anthropic.com>

* fix: honor stdio auth bypass and correct transform ordering in provider wrappers

Co-authored-by: Claude <noreply@anthropic.com>

* fix: move context/dependencies imports into function to break circular import

* fix: route ResourcesAsTools/PromptsAsTools through ctx.fastmcp

Instead of manually reimplementing auth, visibility, and session
transforms in the transform layer, tool functions now call
ctx.fastmcp.read_resource() / ctx.fastmcp.render_prompt() which
routes through the server's full middleware chain. This matches
the pattern CodeMode uses with ctx.fastmcp.call_tool().

The isinstance(provider, FastMCP) branching is removed entirely.

* feat: add _scope parameter for provider-scoped listing

AggregateProvider can now filter which child providers to query when
listing components. ResourcesAsTools and PromptsAsTools use this to
scope listings to their configured provider while still routing
through ctx.fastmcp for full middleware coverage.

The scope matching walks wrapped providers, so a
WrappedProvider(Namespace, inner=MyProvider) matches if MyProvider
is in the scope list.

* test: add coverage for ResourcesAsTools scoped to a sub-server

* fix: delegate to super() when _scope is None, add AggregateProvider to scope matching

* simplify: remove _scope machinery, route everything through ctx.fastmcp

Reverts the _scope parameter from Provider/AggregateProvider/Server.
ResourcesAsTools and PromptsAsTools now simply route through
ctx.fastmcp for all operations. Apply to a FastMCP server instance
for proper auth/visibility/middleware coverage.

Tests rewritten to use FastMCP server directly instead of raw providers.

* warn when ResourcesAsTools/PromptsAsTools is applied to a non-FastMCP provider

* docs: explain that ResourcesAsTools/PromptsAsTools should wrap a FastMCP server

* raise TypeError instead of warning when applied to non-FastMCP provider

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-15 16:35:54 -04:00
..
code-mode.mdx Add ListTools, search limit, and catalog size annotation to CodeMode (#3359) 2026-03-02 18:00:21 -05:00
namespace.mdx Restructure docs: move transforms to dedicated section (#2956) 2026-01-20 00:38:35 -05:00
namespacing.mdx Restructure docs: move transforms to dedicated section (#2956) 2026-01-20 00:38:35 -05:00
prompts-as-tools.mdx fix: route ResourcesAsTools/PromptsAsTools through server middleware (#3495) 2026-03-15 16:35:54 -04:00
resources-as-tools.mdx fix: route ResourcesAsTools/PromptsAsTools through server middleware (#3495) 2026-03-15 16:35:54 -04:00
tool-search.mdx Use transforms= kwarg in docs examples 2026-02-27 21:28:34 -05:00
tool-transformation.mdx docs: add context-aware tool factory example (#3264) 2026-02-22 11:24:22 -05:00
transforms.mdx Accept transforms as FastMCP init kwarg 2026-02-27 21:28:34 -05:00