Skip to content

Refactor and API Redesign #46

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

Merged
merged 32 commits into from
Apr 10, 2025

Conversation

shahar4499
Copy link
Contributor

@shahar4499 shahar4499 commented Apr 9, 2025

Complete API Redesign

This PR introduces a complete refactor of the FastAPI-MCP API.

We changed the approach from relying on FastMCP, to wrapping the lower-level server, which inherently fixes a lot of the problems and limitations we had in the library.

What's Changed

New Class-Based API

  • Replaced the function-based API with a new FastApiMCP class for better usability, and for laying the ground for extension and composability
  • Explicit separation between MCP instance creation and mounting with mcp = FastApiMCP(app) followed by mcp.mount()

Breaking Changes

  • Removed function-based API (add_mcp_server, create_mcp_server, etc.)
  • Removed custom tool support via @mcp.tool() decorator. This is inherent to not using FastMCP anymore, which is what provided this feature. If the community needs a way to add custom MCP tools alongside the existing API, we will provide a way to do so.
  • Updated minimum MCP dependency to v1.6.0

FastAPI-Native Approach for Transport

Thanks @johschmidt42 ! This fixes #28

  • Flexible routing options for placing your MCP server on any FastAPI app or APIRouter
  • A stabler transport using a FastAPI-native approach instead of mounting a whole ASGI app

Enhanced Deployment Options

  • Added support for deploying MCP servers separately from your API service

Bug Fixes and Improved Code Quality

Testing

  • Added a more comprehensive test suite
  • Increased test coverage to 92%

Examples

See the new examples directory for:

  • Simple integration with a single app
  • Separate deployment of API and MCP servers
  • Full schema description options
  • Adding endpoints after MCP server creation

Copy link

codecov bot commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 92.19360% with 100 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
fastapi_mcp/transport/sse.py 22.03% 46 Missing ⚠️
fastapi_mcp/server.py 84.67% 19 Missing ⚠️
fastapi_mcp/openapi/convert.py 90.44% 13 Missing ⚠️
tests/test_openapi_conversion.py 91.66% 13 Missing ⚠️
fastapi_mcp/openapi/utils.py 93.67% 5 Missing ⚠️
fastapi_mcp/utils/testing.py 92.30% 2 Missing ⚠️
tests/fixtures/example_data.py 93.54% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@shahar4499 shahar4499 changed the title [DRAFT] Refactor Refactor and API Redesign Apr 10, 2025
@shahar4499 shahar4499 merged commit ba9897e into main Apr 10, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add FastAPI endpoints (POST) instead of mounting When endpoints are declared after calling add_mcp_server, they are not registered by the MCP server
1 participant