Skip to content

Replace FastMCP.as_proxy() with create_proxy() function#2829

Merged
jlowin merged 6 commits intomainfrom
refactor/create-proxy-function
Jan 10, 2026
Merged

Replace FastMCP.as_proxy() with create_proxy() function#2829
jlowin merged 6 commits intomainfrom
refactor/create-proxy-function

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Jan 10, 2026

FastMCP.as_proxy() was a classmethod that always returned FastMCPProxy, not Self. A standalone function better reflects what it actually does and simplifies the API.

from fastmcp.server import create_proxy

# Create a proxy to any MCP server
proxy = create_proxy("http://example.com/mcp")
proxy = create_proxy(client)
proxy = create_proxy(other_fastmcp_server)

FastMCP.as_proxy() is deprecated but continues to work, forwarding to create_proxy().

Also adds a new "Mounting External Servers" section to the docs showing how to mount npm/uvx packages and remote servers.

The classmethod always returned FastMCPProxy (not Self), so a standalone
function is more honest about what it does. Deprecates as_proxy() with
a warning that forwards to the new function.

New API:
- create_proxy() from fastmcp.server (most users)
- create_proxy_provider() from fastmcp.server.providers.proxy (advanced)
@marvin-context-protocol marvin-context-protocol Bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. breaking change Breaks backward compatibility. Requires minor version bump. Critical for maintainer attention. server Related to FastMCP server implementation or server-side functionality. labels Jan 10, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 10, 2026

Warning

Rate limit exceeded

@jlowin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7c7064e and 3a24d2b.

📒 Files selected for processing (3)
  • docs/servers/providers/proxy.mdx
  • docs/servers/server.mdx
  • src/fastmcp/server/server.py

Walkthrough

This PR adds a top-level factory function create_proxy(...) in fastmcp.server that centralizes proxy construction and returns a FastMCPProxy. A new helper _create_client_factory(...) (in fastmcp.server.providers.proxy) selects session strategies based on target type. The existing FastMCP.as_proxy(...) is retained but now delegates to create_proxy(...) (with deprecation warnings). Numerous docs and examples were updated to reference create_proxy(...), and create_proxy was exported from fastmcp.server.__init__.

Possibly related PRs

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the motivation and usage of the new create_proxy() function, but does not follow the required template with contributor and review checklists. Add the Contributors Checklist and Review Checklist sections from the repository template to document compliance with development workflow and testing requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 69.23% 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 describes the main change: introducing a new create_proxy() function to replace FastMCP.as_proxy().

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


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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
docs/servers/providers/proxy.mdx (1)

196-197: Optional: Minor formatting consideration.

Line 197 appears to be a blank line added after the import statement. While this doesn't affect functionality, verify that the extra whitespace is intentional for readability or if it's an artifact.

src/fastmcp/server/providers/proxy.py (2)

607-610: Consider using warning level for context mixing message.

The message about context mixing in concurrent scenarios is logged at info level, but this describes a potential issue that users should be aware of. Consider using logger.warning() instead to make it more prominent.

💡 Suggested change
-            logger.info(
+            logger.warning(
                 "Proxy detected connected client - reusing existing session for all requests. "
                 "This may cause context mixing in concurrent scenarios."
             )

622-629: Consider more specific type handling instead of cast(Any, ...).

The cast(Any, target) on line 624 bypasses type safety completely. While the logic is correct (all remaining types are valid for ProxyClient), this cast is overly broad and could hide future type issues.

Consider using a more specific cast or a # type: ignore[arg-type] comment with explanation.

♻️ Suggested alternative
     else:
         # target is not a Client, so it's compatible with ProxyClient.__init__
-        base_client = ProxyClient(cast(Any, target))
+        base_client = ProxyClient(target)  # type: ignore[arg-type]

         def proxy_client_factory() -> Client:
             return base_client.new()
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 401b315 and d9876ee.

⛔ Files ignored due to path filters (4)
  • tests/server/providers/proxy/__init__.py is excluded by none and included by none
  • tests/server/providers/proxy/test_proxy_client.py is excluded by none and included by none
  • tests/server/providers/proxy/test_proxy_server.py is excluded by none and included by none
  • tests/server/providers/proxy/test_stateful_proxy_client.py is excluded by none and included by none
📒 Files selected for processing (12)
  • docs/development/v3-notes/v3-features.mdx
  • docs/integrations/claude-desktop.mdx
  • docs/servers/providers/mounting.mdx
  • docs/servers/providers/overview.mdx
  • docs/servers/providers/proxy.mdx
  • docs/servers/server.mdx
  • src/fastmcp/cli/run.py
  • src/fastmcp/client/transports.py
  • src/fastmcp/mcp_config.py
  • src/fastmcp/server/__init__.py
  • src/fastmcp/server/providers/proxy.py
  • src/fastmcp/server/server.py
🧰 Additional context used
📓 Path-based instructions (4)
docs/**/*.mdx

📄 CodeRabbit inference engine (docs/.cursor/rules/mintlify.mdc)

docs/**/*.mdx: Use clear, direct language appropriate for technical audiences
Write in second person ('you') for instructions and procedures in MDX documentation
Use active voice over passive voice in MDX technical documentation
Employ present tense for current states and future tense for outcomes in MDX documentation
Maintain consistent terminology throughout all MDX documentation
Keep sentences concise while providing necessary context in MDX documentation
Use parallel structure in lists, headings, and procedures in MDX documentation
Lead with the most important information using inverted pyramid structure in MDX documentation
Use progressive disclosure in MDX documentation: present basic concepts before advanced ones
Break complex procedures into numbered steps in MDX documentation
Include prerequisites and context before instructions in MDX documentation
Provide expected outcomes for each major step in MDX documentation
End sections with next steps or related information in MDX documentation
Use descriptive, keyword-rich headings for navigation and SEO in MDX documentation
Focus on user goals and outcomes rather than system features in MDX documentation
Anticipate common questions and address them proactively in MDX documentation
Include troubleshooting for likely failure points in MDX documentation
Provide multiple pathways (beginner vs advanced) but offer an opinionated path to avoid overwhelming users in MDX documentation
Always include complete, runnable code examples that users can copy and execute in MDX documentation
Show proper error handling and edge case management in MDX code examples
Use realistic data instead of placeholder values in MDX code examples
Include expected outputs and results for verification in MDX code examples
Test all code examples thoroughly before publishing in MDX documentation
Specify language and include filename when relevant in MDX code examples
Add explanatory comments for complex logic in MDX code examples
Document all API...

Files:

  • docs/development/v3-notes/v3-features.mdx
  • docs/servers/providers/overview.mdx
  • docs/servers/providers/mounting.mdx
  • docs/servers/server.mdx
  • docs/servers/providers/proxy.mdx
  • docs/integrations/claude-desktop.mdx
docs/**/*.{md,mdx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Documentation uses Mintlify framework. Files must be in docs.json to be included. Never modify docs/python-sdk/** (auto-generated)

Files:

  • docs/development/v3-notes/v3-features.mdx
  • docs/servers/providers/overview.mdx
  • docs/servers/providers/mounting.mdx
  • docs/servers/server.mdx
  • docs/servers/providers/proxy.mdx
  • docs/integrations/claude-desktop.mdx
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

docs/**/*.{md,mdx}: Code examples in documentation must explain before showing code and make blocks fully runnable (include imports)
Documentation structure: Headers form navigation guide with logical H2/H3 hierarchy. Content should be user-focused with sections motivating features (why) before mechanics (how). Use prose over code comments for important information
Never use 'This isn't...' or 'not just...' constructions in writing - state what something IS directly. Avoid defensive writing patterns

Files:

  • docs/development/v3-notes/v3-features.mdx
  • docs/servers/providers/overview.mdx
  • docs/servers/providers/mounting.mdx
  • docs/servers/server.mdx
  • docs/servers/providers/proxy.mdx
  • docs/integrations/claude-desktop.mdx
src/fastmcp/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/fastmcp/**/*.py: Python ≥ 3.10 with full type annotations required
Prioritize readable, understandable code - clarity over cleverness. Avoid obfuscated or confusing patterns even if shorter
Follow existing patterns and maintain consistency in code implementation
Be intentional about re-exports - don't blindly re-export everything to parent namespaces. Core types defining a module's purpose should be exported. Specialized features can live in submodules. Only re-export to fastmcp.* for most fundamental types
Never use bare except - be specific with exception types

Files:

  • src/fastmcp/cli/run.py
  • src/fastmcp/server/providers/proxy.py
  • src/fastmcp/server/__init__.py
  • src/fastmcp/client/transports.py
  • src/fastmcp/mcp_config.py
  • src/fastmcp/server/server.py
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: jlowin/fastmcp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-25T15:53:07.656Z
Learning: Applies to tests/**/*.py : Pass FastMCP servers directly to clients for testing without network complexity; only use HTTP transport when explicitly testing network features
📚 Learning: 2025-12-25T15:53:07.656Z
Learnt from: CR
Repo: jlowin/fastmcp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-25T15:53:07.656Z
Learning: Applies to tests/**/*.py : Pass FastMCP servers directly to clients for testing without network complexity; only use HTTP transport when explicitly testing network features

Applied to files:

  • docs/development/v3-notes/v3-features.mdx
  • src/fastmcp/cli/run.py
  • docs/servers/server.mdx
  • docs/servers/providers/proxy.mdx
  • src/fastmcp/server/providers/proxy.py
  • docs/integrations/claude-desktop.mdx
  • src/fastmcp/server/__init__.py
  • src/fastmcp/client/transports.py
  • src/fastmcp/mcp_config.py
📚 Learning: 2025-12-25T15:53:07.656Z
Learnt from: CR
Repo: jlowin/fastmcp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-25T15:53:07.656Z
Learning: Applies to src/fastmcp/**/*.py : Be intentional about re-exports - don't blindly re-export everything to parent namespaces. Core types defining a module's purpose should be exported. Specialized features can live in submodules. Only re-export to fastmcp.* for most fundamental types

Applied to files:

  • src/fastmcp/cli/run.py
  • docs/integrations/claude-desktop.mdx
  • src/fastmcp/server/__init__.py
  • src/fastmcp/client/transports.py
  • src/fastmcp/mcp_config.py
  • src/fastmcp/server/server.py
📚 Learning: 2025-12-25T15:53:07.656Z
Learnt from: CR
Repo: jlowin/fastmcp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-25T15:53:07.656Z
Learning: Applies to src/fastmcp/**/*.py : Python ≥ 3.10 with full type annotations required

Applied to files:

  • src/fastmcp/cli/run.py
  • src/fastmcp/server/providers/proxy.py
  • src/fastmcp/server/__init__.py
  • src/fastmcp/mcp_config.py
📚 Learning: 2025-12-25T15:53:07.656Z
Learnt from: CR
Repo: jlowin/fastmcp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-25T15:53:07.656Z
Learning: Applies to src/fastmcp/**/*.py : Follow existing patterns and maintain consistency in code implementation

Applied to files:

  • src/fastmcp/mcp_config.py
🧬 Code graph analysis (3)
src/fastmcp/cli/run.py (1)
src/fastmcp/server/server.py (2)
  • FastMCP (194-2573)
  • create_proxy (2581-2630)
src/fastmcp/server/providers/proxy.py (3)
src/fastmcp/client/transports.py (1)
  • ClientTransport (85-127)
src/fastmcp/client/client.py (3)
  • Client (129-1722)
  • is_connected (393-395)
  • new (397-423)
src/fastmcp/server/server.py (1)
  • FastMCP (194-2573)
src/fastmcp/client/transports.py (1)
src/fastmcp/server/server.py (2)
  • FastMCP (194-2573)
  • create_proxy (2581-2630)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: label-issue-or-pr
  • GitHub Check: Run tests: Python 3.10 on windows-latest
  • GitHub Check: Run tests: Python 3.10 on ubuntu-latest
  • GitHub Check: Run tests with lowest-direct dependencies
  • GitHub Check: Run tests: Python 3.13 on ubuntu-latest
🔇 Additional comments (26)
docs/servers/providers/overview.mdx (1)

40-40: LGTM - Documentation updated correctly.

The ProxyProvider usage documentation now correctly references create_proxy(client) instead of the deprecated FastMCP.as_proxy(client), aligning with the new API.

docs/development/v3-notes/v3-features.mdx (1)

49-56: LGTM - ProxyProvider documentation updated correctly.

The documentation now accurately reflects the new create_proxy() API, including updated imports and usage examples. The example is complete and runnable as required by the MDX guidelines.

src/fastmcp/server/__init__.py (1)

2-2: LGTM - Appropriate re-export of core functionality.

The create_proxy function is correctly re-exported at the fastmcp.server package level. This is appropriate since it's replacing the previous FastMCP.as_proxy() classmethod and is positioned as the primary API for proxy creation.

Based on learnings, this re-export is justified as core functionality for the server module.

Also applies to: 6-6

src/fastmcp/cli/run.py (3)

15-15: LGTM - Import updated correctly.

The import now includes create_proxy from fastmcp.server.server. While the public API re-exports this in fastmcp.server.__init__, importing directly from the implementation module is consistent with the existing pattern for FastMCP on the same line.


48-48: LGTM - Correctly migrated to new API.

The proxy creation now uses create_proxy(client) instead of the deprecated FastMCP.as_proxy(client).


60-60: LGTM - Correctly migrated to new API.

The MCP config proxy creation now uses create_proxy(mcp_config) instead of the deprecated FastMCP.as_proxy(mcp_config).

docs/servers/providers/mounting.mdx (1)

148-152: LGTM - Clear deprecation notice with migration path.

The deprecation warning clearly communicates that the as_proxy parameter is deprecated and directs users to the new create_proxy() function from fastmcp.server. The explanation of the new default behavior is clear and follows MDX documentation guidelines.

src/fastmcp/mcp_config.py (2)

102-102: LGTM: Import update aligns with new API.

The import correctly references create_proxy from fastmcp.server, consistent with the module-level function introduced in this PR.


109-115: LGTM: Proxy creation correctly migrated to new API.

The usage correctly transitions from FastMCP.as_proxy(backend=client, ...) to create_proxy(client, ...), passing the client as the first positional argument and preserving all configuration parameters.

docs/servers/server.mdx (3)

291-291: LGTM: Documentation correctly references the new API.

The text accurately describes the new create_proxy function for proxying MCP servers.


298-299: LGTM: Imports correctly updated for new API.

The example imports Client and create_proxy from their correct modules, aligning with the new proxy creation pattern.


302-302: LGTM: Example correctly demonstrates new API usage.

The example properly shows create_proxy(backend, name="ProxyServer") with the backend passed as a positional argument.

docs/integrations/claude-desktop.mdx (2)

266-272: LGTM: Basic proxy example correctly demonstrates new API.

The example clearly shows create_proxy accepting a URL string directly, which is a convenient pattern supported by the new function signature.


283-294: LGTM: Authenticated proxy example correctly demonstrates client-based proxy creation.

The example properly shows creating an authenticated client and passing it to create_proxy, demonstrating the recommended pattern for authenticated remote proxies.

src/fastmcp/client/transports.py (2)

46-46: LGTM: Import correctly adds create_proxy alongside FastMCP.

The import appropriately includes both FastMCP (still needed for FastMCPTransport) and the new create_proxy function.


1038-1044: LGTM: Proxy creation correctly updated in MCPConfigTransport.

The method properly migrates to create_proxy(client, ...), passing the ProxyClient as the first positional argument and preserving all configuration parameters for tool transformations and tag filtering.

docs/servers/providers/proxy.mdx (3)

39-53: LGTM: Quick Start section accurately demonstrates new proxy creation API.

The section correctly shows the new pattern:

  • Importing create_proxy from fastmcp.server
  • Importing ProxyClient from fastmcp.server.providers.proxy
  • Creating a proxy with create_proxy(ProxyClient(...), name="...")

The example is clear and follows best practices.


269-306: LGTM: New Advanced Usage section provides valuable patterns.

The section appropriately documents advanced patterns:

  1. Direct FastMCPProxy usage with custom client_factory for fine-grained session control
  2. Using create_proxy_provider() to add proxied components to existing servers

Both examples have correct imports and demonstrate legitimate use cases. The section helps users understand when to use lower-level APIs versus the convenience function.


65-254: LGTM: All examples consistently demonstrate the new API.

Throughout the document, examples correctly show create_proxy usage with various target types:

  • ProxyClient instances for isolated sessions
  • Connected Client instances for shared sessions
  • URL strings for direct remote connections
  • Configuration dicts for multi-server proxies

The consistency and variety of examples effectively demonstrate the flexibility of the new API.

src/fastmcp/server/server.py (4)

27-27: LGTM - Type import addition.

The overload import is correctly added to support type annotations for the new create_proxy() function.


281-282: LGTM - Deprecation messaging updated.

The updated deprecation messages correctly guide users to the new create_proxy() API.

Also applies to: 308-308


2547-2564: LGTM - Proper deprecation of as_proxy().

The classmethod is correctly deprecated with clear messaging and delegates to the new create_proxy() function while maintaining backward compatibility.


2581-2630: LGTM - Well-designed module-level factory function.

The create_proxy() function provides a clean, well-documented API for proxy creation. The implementation correctly delegates to the internal _create_client_factory() helper, maintaining good separation of concerns.

src/fastmcp/server/providers/proxy.py (3)

56-56: LGTM - Type import addition.

The ClientTransport import is correctly placed under TYPE_CHECKING to support type annotations without runtime overhead.


632-679: LGTM - Well-designed public factory function.

The create_proxy_provider() function provides a clean API for creating proxy providers. The implementation correctly delegates to _create_client_factory() and includes comprehensive documentation with examples.


694-714: LGTM - Documentation properly updated.

The FastMCPProxy docstring and examples correctly guide users to the new create_proxy() function while still documenting direct construction for advanced scenarios.

@marvin-context-protocol
Copy link
Copy Markdown
Contributor

Test Failure Analysis

Summary: Tests are failing due to a merge conflict with . The PR removes the cast import, but when merged with main, it encounters code from PR #2828 that uses cast().

Root Cause: This PR branch was created before PR #2828 ("Add composable lifespans") was merged to main. When GitHub Actions tests this PR, it creates a merge with main that combines:

  • This PR's removal of the cast import from typing (line 27 in src/fastmcp/server/server.py)
  • Main's new code from Add composable lifespans #2828 that uses cast() at line 289

This creates a NameError: name 'cast' is not defined when FastMCP() is instantiated.

Suggested Solution: Rebase this PR branch on the latest main to incorporate the changes from #2828. The rebase should automatically resolve the conflict since:

  1. PR Add composable lifespans #2828 changed lines 285-289 to add cast() usage
  2. This PR changes the same lines 285-289 to remove the conditional and use lifespan or default_lifespan

The rebased version will keep this PR's simpler lifespan or default_lifespan approach and won't need cast at all.

Detailed Analysis

Error Log Excerpt

ERROR collecting tests/tools/test_tool_future_annotations.py
tests/tools/test_tool_future_annotations.py:13: in <module>
    fastmcp_server = FastMCP()
src/fastmcp/server/server.py:289: in __init__
    self._lifespan = cast(LifespanCallable[LifespanResultT], default_lifespan)
E   NameError: name 'cast' is not defined

Code Comparison

main branch (line 27):

from typing import TYPE_CHECKING, Any, Generic, Literal, cast, overload

main branch (lines 285-289):

# Handle Lifespan instances (they're callable) or regular lifespan functions
if lifespan is not None:
    self._lifespan: LifespanCallable[LifespanResultT] = lifespan
else:
    self._lifespan = cast(LifespanCallable[LifespanResultT], default_lifespan)

This PR branch (line 27):

from typing import TYPE_CHECKING, Any, Generic, Literal, overload  # cast removed

This PR branch (lines 284-289):

self._lifespan: LifespanCallable[LifespanResultT] = lifespan or default_lifespan
self._lifespan_result: LifespanResultT | None = None
self._lifespan_result_set: bool = False
self._started: asyncio.Event = asyncio.Event()

Merged result (what CI tests):

# Line 27: cast import removed (from this PR)
from typing import TYPE_CHECKING, Any, Generic, Literal, overload

# Lines 285-289: Uses cast() from main, but cast not imported!
if lifespan is not None:
    self._lifespan: LifespanCallable[LifespanResultT] = lifespan
else:
    self._lifespan = cast(LifespanCallable[LifespanResultT], default_lifespan)
Related Files
  • src/fastmcp/server/server.py:27 - Import statement where cast was removed
  • src/fastmcp/server/server.py:289 - Location where cast() is called in merged code

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/servers/providers/proxy.mdx (1)

150-159: Add import statement for completeness.

The code example lacks the required import for ProxyClient. As per coding guidelines, code blocks should be fully runnable with imports included.

Proposed fix
 Selectively disable forwarding:

 ```python
+from fastmcp.server.providers.proxy import ProxyClient
+
 backend = ProxyClient(
     "backend_server.py",
     sampling_handler=None,  # Disable LLM sampling
     log_handler=None        # Disable log forwarding
 )
</details>

</blockquote></details>

</blockquote></details>
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9876ee and 7c7064e.

⛔ Files ignored due to path filters (1)
  • tests/server/providers/proxy/test_proxy_server.py is excluded by none and included by none
📒 Files selected for processing (4)
  • docs/servers/providers/mounting.mdx
  • docs/servers/providers/proxy.mdx
  • src/fastmcp/server/providers/proxy.py
  • src/fastmcp/server/server.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/servers/providers/mounting.mdx
🧰 Additional context used
📓 Path-based instructions (4)
src/fastmcp/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/fastmcp/**/*.py: Python ≥ 3.10 with full type annotations required
Prioritize readable, understandable code - clarity over cleverness. Avoid obfuscated or confusing patterns even if shorter
Follow existing patterns and maintain consistency in code implementation
Be intentional about re-exports - don't blindly re-export everything to parent namespaces. Core types defining a module's purpose should be exported. Specialized features can live in submodules. Only re-export to fastmcp.* for most fundamental types
Never use bare except - be specific with exception types

Files:

  • src/fastmcp/server/server.py
  • src/fastmcp/server/providers/proxy.py
docs/**/*.mdx

📄 CodeRabbit inference engine (docs/.cursor/rules/mintlify.mdc)

docs/**/*.mdx: Use clear, direct language appropriate for technical audiences
Write in second person ('you') for instructions and procedures in MDX documentation
Use active voice over passive voice in MDX technical documentation
Employ present tense for current states and future tense for outcomes in MDX documentation
Maintain consistent terminology throughout all MDX documentation
Keep sentences concise while providing necessary context in MDX documentation
Use parallel structure in lists, headings, and procedures in MDX documentation
Lead with the most important information using inverted pyramid structure in MDX documentation
Use progressive disclosure in MDX documentation: present basic concepts before advanced ones
Break complex procedures into numbered steps in MDX documentation
Include prerequisites and context before instructions in MDX documentation
Provide expected outcomes for each major step in MDX documentation
End sections with next steps or related information in MDX documentation
Use descriptive, keyword-rich headings for navigation and SEO in MDX documentation
Focus on user goals and outcomes rather than system features in MDX documentation
Anticipate common questions and address them proactively in MDX documentation
Include troubleshooting for likely failure points in MDX documentation
Provide multiple pathways (beginner vs advanced) but offer an opinionated path to avoid overwhelming users in MDX documentation
Always include complete, runnable code examples that users can copy and execute in MDX documentation
Show proper error handling and edge case management in MDX code examples
Use realistic data instead of placeholder values in MDX code examples
Include expected outputs and results for verification in MDX code examples
Test all code examples thoroughly before publishing in MDX documentation
Specify language and include filename when relevant in MDX code examples
Add explanatory comments for complex logic in MDX code examples
Document all API...

Files:

  • docs/servers/providers/proxy.mdx
docs/**/*.{md,mdx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Documentation uses Mintlify framework. Files must be in docs.json to be included. Never modify docs/python-sdk/** (auto-generated)

Files:

  • docs/servers/providers/proxy.mdx
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

docs/**/*.{md,mdx}: Code examples in documentation must explain before showing code and make blocks fully runnable (include imports)
Documentation structure: Headers form navigation guide with logical H2/H3 hierarchy. Content should be user-focused with sections motivating features (why) before mechanics (how). Use prose over code comments for important information
Never use 'This isn't...' or 'not just...' constructions in writing - state what something IS directly. Avoid defensive writing patterns

Files:

  • docs/servers/providers/proxy.mdx
🧠 Learnings (3)
📚 Learning: 2025-12-25T15:53:07.656Z
Learnt from: CR
Repo: jlowin/fastmcp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-25T15:53:07.656Z
Learning: Applies to src/fastmcp/**/*.py : Be intentional about re-exports - don't blindly re-export everything to parent namespaces. Core types defining a module's purpose should be exported. Specialized features can live in submodules. Only re-export to fastmcp.* for most fundamental types

Applied to files:

  • src/fastmcp/server/server.py
📚 Learning: 2025-12-25T15:53:07.656Z
Learnt from: CR
Repo: jlowin/fastmcp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-25T15:53:07.656Z
Learning: Applies to tests/**/*.py : Pass FastMCP servers directly to clients for testing without network complexity; only use HTTP transport when explicitly testing network features

Applied to files:

  • src/fastmcp/server/server.py
  • docs/servers/providers/proxy.mdx
  • src/fastmcp/server/providers/proxy.py
📚 Learning: 2025-12-25T15:53:07.656Z
Learnt from: CR
Repo: jlowin/fastmcp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-25T15:53:07.656Z
Learning: Applies to src/fastmcp/**/*.py : Python ≥ 3.10 with full type annotations required

Applied to files:

  • src/fastmcp/server/providers/proxy.py
🧬 Code graph analysis (1)
src/fastmcp/server/server.py (1)
src/fastmcp/server/providers/proxy.py (2)
  • FastMCPProxy (637-679)
  • _create_client_factory (584-629)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run tests: Python 3.13 on ubuntu-latest
  • GitHub Check: Run tests: Python 3.10 on ubuntu-latest
  • GitHub Check: Run tests: Python 3.10 on windows-latest
  • GitHub Check: Run tests with lowest-direct dependencies
🔇 Additional comments (11)
src/fastmcp/server/providers/proxy.py (3)

53-56: LGTM!

The TYPE_CHECKING import for ClientTransport is correctly added to support the type annotation in _create_client_factory without causing a runtime import cycle.


645-665: LGTM!

The updated docstrings correctly guide users toward create_proxy() as the recommended approach while documenting FastMCPProxy for advanced use cases requiring explicit session control.


584-629: Well-structured factory helper with appropriate session strategies.

The three-way branching logic correctly handles:

  1. Connected clients → session reuse with appropriate warning
  2. Disconnected clients → fresh sessions via client.new()
  3. Other targets → ProxyClient wrapper with fresh sessions

The closures properly capture client references, type annotations are comprehensive, and the is_connected() check is implemented correctly in the Client class.

src/fastmcp/server/server.py (4)

2281-2282: LGTM!

The docstring correctly directs users to use create_proxy() explicitly before mounting when they need proxy behavior.


2304-2311: LGTM!

The deprecation warning message is consistent with the docstring and provides clear migration guidance.


2547-2564: LGTM!

The deprecation implementation follows the codebase's established pattern:

  • Conditional warning based on fastmcp.settings.deprecation_warnings
  • Correct stacklevel=2 for classmethod context
  • Clean delegation to create_proxy() maintaining backward compatibility

2624-2629: LGTM!

The local import correctly avoids circular dependencies, and the implementation cleanly delegates to _create_client_factory before constructing the proxy.

docs/servers/providers/proxy.mdx (4)

39-49: LGTM!

The Quick Start example is clear, concise, and demonstrates the recommended create_proxy() usage with the correct import path.


91-122: LGTM!

The session isolation documentation clearly explains both the default fresh-session behavior and the shared-session scenario with appropriate warnings.


261-298: LGTM!

The Advanced Usage section is well-structured:

  • Correctly shows the import path for FastMCPProxy and ProxyClient
  • The new "Adding Proxied Components" subsection provides a practical example of the mounting pattern
  • Follows the progressive disclosure principle from the coding guidelines

124-148: LGTM!

The feature forwarding documentation clearly explains what MCP features are automatically proxied and provides a concise example.

Comment thread src/fastmcp/server/server.py
@jlowin jlowin merged commit 3163e61 into main Jan 10, 2026
11 checks passed
@jlowin jlowin deleted the refactor/create-proxy-function branch January 10, 2026 16:39
@jlowin jlowin removed the breaking change Breaks backward compatibility. Requires minor version bump. Critical for maintainer attention. label Jan 20, 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. 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