You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(custom-tools): allow required parameters after optional ones - #1472
Custom tools fail to register when an optional parameter precedes a required one. For example, limit=10 followed by required action raises ValueError: non-default argument follows default argument while building the handler, before FastMCP can register it.
Expose custom parameters as keyword-only, matching the handler's **kwargs calling convention and MCP's named arguments. This permits either declaration order while preserving types, requiredness, defaults, and the original parameter order.
Type of Change
Bug fix (non-breaking change that fixes an issue)
Test update
Changes Made
Use inspect.Parameter.KEYWORD_ONLY for custom tool parameters; retain the existing context parameter.
Add regression tests through global registration and both decorators, covering optional-first and required-first definitions, typed defaults, and rejection of missing required arguments.
Compatibility / Package Source
Branched from official beta, commit 142ea0a.
Python 3.12.14, locked FastMCP 3.0.2 and Pydantic 2.12.5.
Server-only change; no Unity APIs or package versions changed.
Testing/Screenshots/Recordings
Python tests: 1577 passed, 18 skipped.
Regression demonstrated on unchanged beta: optional-first case fails; required-first case passes. Both pass after the fix.
Standalone real FastMCP registration smoke: the custom tool is listed, action is required, limit retains integer default 10, and context is excluded from the public schema.
git diff --check passes.
Unity compile check attempted but unavailable in this environment (/dev/fd/63 error); Unity Editor tests were not run. This change only affects Python handler signatures.
Documentation Updates
No tool/resource declarations or public parameter schemas added or removed.
Related Issues
Independently reproduced registration failure; no matching issue or existing fix found in the searched PRs.
Summary by CodeRabbit
Bug Fixes
Custom tool parameters now bind consistently regardless of the order in which required and optional parameters are provided. Optional values retain their defaults, while missing required values raise an error.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID: eef482e0-35ae-49ba-b8d1-0ff22ece50de
📥 Commits
Reviewing files that changed from the base of the PR and between 142ea0a and becf678.
📒 Files selected for processing (2)
Server/src/services/custom_tool_service.py
Server/tests/test_custom_tool_parameter_order.py
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Generated custom-tool parameters are now keyword-only. Tests cover parameter ordering, annotations, default binding, and missing required arguments.
Changes: Custom tool parameter binding
Layer / File(s)
Summary
Signature and binding tests Server/src/services/custom_tool_service.py, Server/tests/test_custom_tool_parameter_order.py
_build_signature marks tool parameters as keyword-only while ctx remains positional-or-keyword. Tests cover required and optional parameter orders, annotations, the limit default, and a TypeError when action is omitted.
This fixes custom-tool registration when an optional parameter comes before a required one. No concrete merge-blocking risk was found, and the change is server-only.
Pre-merge checks: 4 · 1
Failed checks (1 warning)
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks (4 passed)
Check name
Status
Explanation
Title check
The title clearly identifies the main fix: allowing required custom-tool parameters after optional parameters.
Description check
The description is complete and directly matches the changes. It explains the bug, implementation, regression tests, compatibility details, test results, unavailable Unity checks, and documentation st…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
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
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.
Description
Custom tools fail to register when an optional parameter precedes a required one. For example,
limit=10followed by requiredactionraisesValueError: non-default argument follows default argumentwhile building the handler, before FastMCP can register it.Expose custom parameters as keyword-only, matching the handler's
**kwargscalling convention and MCP's named arguments. This permits either declaration order while preserving types, requiredness, defaults, and the original parameter order.Type of Change
Changes Made
inspect.Parameter.KEYWORD_ONLYfor custom tool parameters; retain the existing context parameter.Compatibility / Package Source
beta, commit142ea0a.Testing/Screenshots/Recordings
actionis required,limitretains integer default 10, and context is excluded from the public schema.git diff --checkpasses./dev/fd/63error); Unity Editor tests were not run. This change only affects Python handler signatures.Documentation Updates
No tool/resource declarations or public parameter schemas added or removed.
Related Issues
Independently reproduced registration failure; no matching issue or existing fix found in the searched PRs.
Summary by CodeRabbit