feat: add custom tools support via add_tool() and custom_tools parameter#289
Open
nachogarcia wants to merge 1 commit intotadata-org:mainfrom
Open
feat: add custom tools support via add_tool() and custom_tools parameter#289nachogarcia wants to merge 1 commit intotadata-org:mainfrom
nachogarcia wants to merge 1 commit intotadata-org:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Adds a public API for registering custom MCP tools that don't map to FastAPI endpoints. This enables use cases like wrapping SSE streams, returning instructions, or bridging protocol gaps — without monkey-patching internal methods.
New API
Handler signature:
Handlers receive the same
HTTPRequestInfo(auth headers, cookies, etc.) that auto-generated tools get, plus the MCPServerinstance for access torequest_context.What changed
fastapi_mcp/server.py: Added_custom_handlersdict,custom_toolsconstructor param,add_tool()method, and a dispatch branch inhandle_call_toolthat routes to custom handlers before falling through to_execute_api_toolfastapi_mcp/__init__.py: ExportedHTTPRequestInfoso consumers can type-hint handlerstests/test_custom_tools.py: 7 new tests covering listing, calling, request info forwarding, server instance access, constructor param, OpenAPI tool coexistence, and error handling~30 lines of new production code. No breaking changes — all existing behavior is preserved.
Issue ticket number and link (if applicable)
Closes #75
Checklist before requesting a review