Skip to content

Dynamic servers #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
guidodecaso opened this issue May 23, 2025 · 5 comments
Open

Dynamic servers #572

guidodecaso opened this issue May 23, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@guidodecaso
Copy link

Enhancement Description

In the official Python SDK you can use @mcp.list_tools() and @mcp.call_tool() to create a server that servers a dynamic list of tools. One use case is a server that reads a JWT from a header or even URL segment and then serves a different set of tools based on the user permissions as per the JWT claims.

I have not found a way to do this with FastMCP 2.0. I understand the idea of FastMCP 2.0 is to serve tools based on annotating code, but the lack of support for dynamic tools is keeping me locked into the official Python SDK.

Use Case

No response

Proposed Implementation

@guidodecaso guidodecaso added the enhancement New feature or request label May 23, 2025
@jlowin
Copy link
Owner

jlowin commented May 23, 2025

Are you referring to this PR? modelcontextprotocol/python-sdk#728 It's under active debate in the low-level repo. I am not sure that global enable/disable of tools is the right way to handle this. We are pursuing a more dynamic approach.

@jlowin jlowin closed this as completed May 23, 2025
@guidodecaso
Copy link
Author

Thanks @jlowin, but it's not the same. That PR is about disabling tools that were defined by "@mcp.tool" annotating functions. What I mean is having capabilities to dynamically define the tools in runtime.

An example usecase would be an MCP wrapper for a "legacy" integration marketplace. For ex MuleSoft, etc.. Flow:

  1. MCP server receives a JWT that indicates a connector id
  2. When listing the tools, the MCP server connects to an integration marketplace and fetches the available endpoints for such connector id (as obtained from the JWT claims)
  3. When calling a tool, the MCP server delegates the actual execution to the integration marketplace

@jlowin
Copy link
Owner

jlowin commented May 23, 2025

Ah ok this is similar to #443 but will need more work to fully support a dynamic server. However I like the enhancement now that I understand it better. Unless I'm mistaken you can not do this in the official SDK though?

@jlowin jlowin reopened this May 23, 2025
@guidodecaso
Copy link
Author

I was reading #443 just now and that seems to be about tools that return a stream of results. So maybe I'm a bit confused?

Servers with a dynamically-generated list of tools are available in the official SDK when you use Server, and not with FastMCP 1.0. See https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/servers/simple-tool/mcp_simple_tool/server.py#L42

In there, the list of tools is just returning always the same one tool. But you can imagine how you can easily make that method retrieve the tools from a DB, or an external vendor, etc.

@orhanrauf
Copy link

+1 for this feature. Is there a recommended way to intercept the @mcp.list_tools() and @mcp.call_tool() with middleware or similar and put logic in front? We have exactly this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants