Skip to content

Conversation

@fishl3j
Copy link
Contributor

@fishl3j fishl3j commented Jan 26, 2026

When registering tools via Mcptool, preset parameters (e.g., agent_id, session_id, or other context-bound values injected at runtime) are not excluded from the JSON schema generated for LLM consumption. As a result, these parameters appear in the tool’s description sent to the LLM — causing the LLM to attempt setting them explicitly in its tool call arguments.
This leads to:

  • ❌ Unexpected overwriting of runtime-injected preset values
  • ❌ Inconsistent behavior vs. io.agentscope.core.tool.Toolkit#registerToolMethod, which correctly omits preset parameters from the exposed schema

fish[3] added 2 commits January 26, 2026 17:26
- Modify McpTool.convertMcpSchemaToParameters to accept excludeParams parameter
- Update McpClientManager to pass preset parameter exclusions to McpTool
- Add defensive copying of required list to prevent UnsupportedOperationException
- Include comprehensive tests for parameter exclusion functionality
- Update existing tests to adapt new interface
- Fix code formatting issues
- Create defensive copy of properties map to prevent mutation of original schema
- Simplify parameter exclusion logic using properties.keySet().removeAll()
- Improve code clarity and maintainability
- Maintain backward compatibility
@fishl3j fishl3j requested a review from a team January 26, 2026 09:26
@gemini-code-assist
Copy link

Summary of Changes

Hello @xingmengxian, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where preset, runtime-injected parameters were incorrectly exposed in the JSON schema for tools registered with Mcptool. By introducing a mechanism to explicitly exclude these parameters from the schema, the change ensures that Large Language Models receive an accurate representation of available tool arguments, preventing erroneous parameter attempts and aligning behavior with other tool registration methods.

Highlights

  • Parameter Exclusion for LLM Tools: Implemented functionality to exclude preset parameters from the JSON schema generated for LLM consumption when registering tools via Mcptool. This prevents LLMs from attempting to set context-bound parameters, resolving issues of unexpected overwriting and inconsistent behavior.
  • Updated Schema Conversion Logic: The convertMcpSchemaToParameters method in McpTool now accepts a set of parameter names to exclude. It modifies the generated schema by removing these parameters from both the properties and required fields.
  • Integration in McpClientManager: The McpClientManager has been updated to identify preset parameters for each tool and pass their keys to the convertMcpSchemaToParameters method, ensuring that only relevant parameters are exposed to the LLM.
  • Comprehensive Test Coverage: New unit tests have been added to McpToolTest to validate the parameter exclusion logic under various scenarios, including cases with parameters to exclude, empty exclusion sets, null exclusion sets, and non-existent parameters.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly implements the exclusion of preset parameters from the tool schema sent to the LLM. The changes in McpClientManager and McpTool are logical and well-executed. The new method signature in McpTool and the associated filtering logic are sound. The accompanying tests in McpToolTest are comprehensive, covering various scenarios including null and empty exclusion sets. I've added one suggestion to improve the robustness of the new tests by also checking collection sizes. Overall, this is a solid contribution that effectively resolves the stated issue.

Comment on lines +467 to +475
assertTrue(resultProperties.containsKey("param1"));
assertFalse(resultProperties.containsKey("param2"));
assertFalse(resultProperties.containsKey("param3"));

// Check that excluded required fields are removed
List<String> resultRequired = (List<String>) result.get("required");
assertTrue(resultRequired.contains("param1"));
assertFalse(resultRequired.contains("param2"));
assertFalse(resultRequired.contains("param3"));

Choose a reason for hiding this comment

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

medium

The assertions for checking excluded parameters can be made more robust and concise. By also checking the size of the collections, you can be sure that no extra parameters are leaking through and that the collections have the exact expected size. Then, you only need to assert the presence of the expected parameter(s).

A similar improvement can be applied to the other new tests (testConvertMcpSchemaToParameters_WithExcludeParams_EmptyExcludes, ..._NullExcludes, and ..._NonExistentParams) by asserting the expected size of the collections.

Suggested change
assertTrue(resultProperties.containsKey("param1"));
assertFalse(resultProperties.containsKey("param2"));
assertFalse(resultProperties.containsKey("param3"));
// Check that excluded required fields are removed
List<String> resultRequired = (List<String>) result.get("required");
assertTrue(resultRequired.contains("param1"));
assertFalse(resultRequired.contains("param2"));
assertFalse(resultRequired.contains("param3"));
assertEquals(1, resultProperties.size());
assertTrue(resultProperties.containsKey("param1"));
// Check that excluded required fields are removed
List<String> resultRequired = (List<String>) result.get("required");
assertEquals(1, resultRequired.size());
assertTrue(resultRequired.contains("param1"));

@codecov
Copy link

codecov bot commented Jan 26, 2026

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.

1 participant