fastapi_mcp icon indicating copy to clipboard operation
fastapi_mcp copied to clipboard

Binding an Existing MCP server with FastAPI

Open bandaru-manideep opened this issue 9 months ago • 3 comments

The code base i see here actually creates a mcp server app from fast api app by mounting and then each api endpoint can be exposed as an mcp tool which can be invoked using the endpoints, but if an mcp server is already running with some existing tools created, how can we create a FastAPIMCP app.

Let me know if the solution already exists , if not please guide me through

bandaru-manideep avatar Apr 14 '25 17:04 bandaru-manideep

Hi @bandaru-manideep ! Not sure I understand the use-case. If an MCP server is already running, why do you want to bind it to a FastAPI?

If you want to mount it to an existing FastAPI URL for having only one URL, you can use app.mount() from the FastAPI app, or something like this. You can also have two (or more) MCP servers running, one based on your FastAPI and another being your existing one...

shira-ayal avatar Apr 15 '25 15:04 shira-ayal

MCP Servers can support stdio or sse right , if sse then we can simply call the tools via http endpoints but if an stdio supported server is developed , we have to either create a wrapper around it which can make the tools as endpoints to use with any agent or working on creating a fast api app again and then mount it, i was focusing on this point. Can we have any FastAPI wrapper that can solve this

bandaru-manideep avatar Apr 16 '25 11:04 bandaru-manideep

I think there might be a confusion - the MCP tool is called and forwards the request to the FastAPI, which then returns an answer, that is forwarded to the MCP server and returned to the AI agent. The library is meant to be used to turn a FastAPI into an MCP server, and not the other way around.

If there is a specific issue or bug, I suggest you open a new issue describing the exact usage that failed. Closing as I believe this is not exactly relevant to this project. If I am mistaken, I welcome you to join our Slack Community where we will be able to discuss this in further depth 😄

shira-ayal avatar Apr 22 '25 15:04 shira-ayal