Skip to content

Improve ambiguity handling in argument processing - #43

Open
3dgiordano wants to merge 4 commits into
developmentfrom
ARG-AMBIGUITY
Open

Improve ambiguity handling in argument processing#43
3dgiordano wants to merge 4 commits into
developmentfrom
ARG-AMBIGUITY

Conversation

@3dgiordano

Copy link
Copy Markdown
Collaborator

This pull request introduces a standardized approach for handling tool arguments across multiple managers and patches the MCP argument model to improve payload handling. The main change is the addition of a normalize_action_args utility, which ensures consistent parsing of action and argument data, and updates all tool managers to use a single arguments parameter. This makes the codebase more robust against variations in client payloads and simplifies argument handling logic.

Core infrastructure improvements:

  • Added normalize_action_args and validation utilities to tools/utils.py to standardize and simplify argument parsing for all tool endpoints. This function supports multiple payload formats and ensures all managers receive arguments in a consistent (action, args) tuple.
  • Patched mcp.server.fastmcp.utilities.func_metadata.ArgModelBase in main.py to ensure tools with an arguments parameter always receive the full payload, even if the client omits the arguments wrapper. This increases compatibility with different client payload styles.

Tool manager refactoring:

  • Updated all tool manager register endpoints (ai_scriptless_manager.py, device_manager.py, execution_manager.py, help_manager.py, user_manager.py) to accept a single arguments parameter instead of separate action and args, and to use normalize_action_args for argument extraction. [1] [2] [3] [4] [5]
  • Updated imports in all affected managers to include normalize_action_args. [1] [2] [3] [4] [5]

API and documentation consistency:

  • Refactored ai_scriptless_manager.py to rename parameters from arguments to cmd_arguments for clarity, and updated all related docstrings and dispatch logic to match the new naming and argument handling convention. [1] [2] [3] [4] [5]

These changes collectively make the argument handling more robust and maintainable, reducing the risk of errors from inconsistent payloads and simplifying the interface for future tool development.

@diego-ferrand

Copy link
Copy Markdown
Collaborator

Looks like tools/tool_manager.py -> tools function is missing migration to new arguments

async def tools( action: str = Field(description="The action id to execute"), args: Dict[str, Any] = Field(description="Dictionary with parameters", default=None), ctx: Context = Field(description="Context object providing access to MCP capabilities") ) -> BaseResult:

Comment thread tools/utils.py
return action, args


def validate_required_args(action: str, args: Optional[Dict[str, Any]], required: list[str]) -> Optional[BaseResult]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is new but never used. Is it dead code?

return await ai_scriptless_manager.add_command(
args.get("test_id", ""),
args.get("command_id", ""),
args.get("arguments"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im guessing we are completely dropping arguments as a key, we could keep a safeguard for backwards compatible by doing args.get("cmd_arguments") or args.get("arguments")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applied, this is aligned to the docstring, it's not programmatic, it's the declaration of the docstring arguments

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applied, this is aligned to the docstring, it's not programmatic, it's the declaration of the docstring arguments

args.get("test_id", ""),
args.get("step_path", ""),
args.get("arguments", {}),
args.get("cmd_arguments", {}),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment in add_command section.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applied, this is aligned to the docstring, it's not programmatic, it's the declaration of the docstring arguments

Comment thread tools/utils.py
icon_data = base64.standard_b64encode(icon_path.read_bytes()).decode()
return f"data:image/png;base64,{icon_data}"

def normalize_action_args(arguments: Optional[Dict[str, Any]] = None) -> tuple[str, Dict[str, Any]]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we include some tests for this logic?

ctx: Context = Field(description="Context object providing access to MCP capabilities")
) -> BaseResult:
action, args = normalize_action_args(arguments)
if args is None:

@diego-ferrand diego-ferrand Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalize_action_args never returns None and will default to {}, this is now dead code and should be removed on all managers.

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.

2 participants