fix(mcp): Use Field() for optional params to fix MCP tool validation#889
Conversation
Co-Authored-By: AJ Steers <aj@airbyte.io>
Original prompt from AJ Steers |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. Testing This PyAirbyte VersionYou can test this version of PyAirbyte using the following: # Run PyAirbyte CLI from this branch:
uvx --from 'git+https://github.com/airbytehq/PyAirbyte.git@devin/1764726000-fix-mcp-optional-params' pyairbyte --help
# Install PyAirbyte from this branch for development:
pip install 'git+https://github.com/airbytehq/PyAirbyte.git@devin/1764726000-fix-mcp-optional-params'Helpful ResourcesPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
Community SupportQuestions? Join the #pyairbyte channel in our Slack workspace. |
📝 WalkthroughWalkthroughThis PR refactors parameter annotations in cloud operations tool functions by moving textual descriptions from inline strings within Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ 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). (6)
🔇 Additional comments (4)
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. Comment |
Summary
Fixes a bug where optional parameters in MCP list tools were incorrectly marked as required in the tool schema. The issue was that using
Annotated[type, "description"] = Nonedoesn't properly register the default value with FastMCP/Pydantic - it needs to useField(description=..., default=None)inside the Annotated type hint.Affected tools:
list_deployed_cloud_source_connectorslist_deployed_cloud_destination_connectorslist_deployed_cloud_connectionslist_cloud_workspacesBefore: Calling these tools without
name_containsandmax_items_limitwould fail with:After: These parameters are properly optional as intended.
Review & Testing Checklist for Human
list_deployed_cloud_source_connectorsvia MCP without providingname_containsormax_items_limitto verify the fix worksAnnotated[..., "string"] = Nonepatterns in the MCP code that may have been missedworkspace_idparameter usesField()correctly)Notes
e8b14943-1b39-4ea5-8d08-4792a74090deSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.