Skip to content

Immutable transform wrapping for providers#2913

Merged
jlowin merged 5 commits intomainfrom
feature/wrap-transform-phase-a
Jan 19, 2026
Merged

Immutable transform wrapping for providers#2913
jlowin merged 5 commits intomainfrom
feature/wrap-transform-phase-a

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Jan 18, 2026

Providers can now be wrapped with transforms immutably via wrap_transform(), enabling the same provider instance to be used in multiple aggregators with different namespaces.

db = DatabaseProvider()

# Same provider, different namespaces - no mutation
server1.add_provider(db, namespace="db1")  
server2.add_provider(db, namespace="db2")

Key changes:

  • Provider.wrap_transform(transform) returns a new _WrappedProvider that layers the transform on top without mutating the original
  • AggregateProvider simplified to a plain .providers list, using wrap_transform(Namespace(...)) for namespacing
  • FastMCP instances are auto-wrapped in FastMCPProvider when added to an aggregator (prevents accidentally bypassing middleware)
  • FastMCP now inherits from AggregateProvider, removing duplicate aggregation logic

@marvin-context-protocol marvin-context-protocol Bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. server Related to FastMCP server implementation or server-side functionality. provider Related to the FastMCP Provider class breaking change Breaks backward compatibility. Requires minor version bump. Critical for maintainer attention. labels Jan 18, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8c61ace12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/fastmcp/server/server.py Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 18, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

AggregateProvider is now exposed publicly and enhanced to support adding providers via add_provider(provider, *, namespace: str = ""), with internal storage renamed from _providers to providers and optional initial providers. Provider gained wrap_transform(transform) to produce an immutable wrapped provider implemented by a new internal _WrappedProvider class that delegates to an inner provider and composes transforms. FastMCP now inherits from AggregateProvider, uses add_provider for mounts/namespace handling, and delegates aggregation/list/get/task logic to the aggregate provider implementations.

Possibly related PRs

  • PR 2653: Adds immutable provider-wrapping and namespace application semantics that overlap with wrap_transform and the _WrappedProvider implementation.
  • PR 2663: Implements wrapped provider classes and modifies provider aggregation/export surface, directly touching _WrappedProvider and AggregateProvider exposure.
  • PR 2635: Refactors server mounting to use provider abstractions and add_provider with namespace support, affecting FastMCP mounting and lifespan wiring.
🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is comprehensive and well-structured, covering key changes with code examples. However, the Contributors Checklist items are not checked off as required by the template. Complete all checklist items in the Contributors Checklist section by checking the boxes to indicate compliance with repository requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 79.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: introducing immutable transform wrapping for providers via the new wrap_transform() method.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Apply tool renames before namespace so they're scoped to the mounted
provider only. This prevents renames from leaking to other providers'
tools when mounting without a namespace.

Order is now: rename → namespace (so foo → bar with namespace="x" → x_bar)
@jlowin jlowin merged commit ed0587d into main Jan 19, 2026
11 checks passed
@jlowin jlowin deleted the feature/wrap-transform-phase-a branch January 19, 2026 00:37
@jlowin jlowin removed the breaking change Breaks backward compatibility. Requires minor version bump. Critical for maintainer attention. label Jan 20, 2026
gfortaine pushed a commit to gfortaine/fastmcp that referenced this pull request Jan 30, 2026
gfortaine pushed a commit to gfortaine/fastmcp that referenced this pull request Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality. For issues and smaller PR improvements. provider Related to the FastMCP Provider class server Related to FastMCP server implementation or server-side functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant