Skip to content

fix(custom-tools): allow required parameters after optional ones - #1472

Merged
Scriptwonder merged 3 commits into
CoplayDev:betafrom
Morrow588:fix/custom-tool-parameter-order
Oct 17, 2026
Merged

Scriptwonder merged 3 commits into
CoplayDev:betafrom
Morrow588:fix/custom-tool-parameter-order

Conversation

@Morrow588

@Morrow588 Morrow588 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

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.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: scriptwonder

Merge Risk: ⚪ Minimal · up to 4657a

Merge Risk: ⚪ Minimal · up to 4657a

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: Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the main fix: allowing required custom-tool parameters after optional parameters.
Description check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Scriptwonder
Scriptwonder merged commit c7e1d4a into CoplayDev:beta Oct 17, 2026
4 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

3 participants