-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ensure tool parameters are properly handled by reloading JSON #2698
Conversation
--bug=1053980 --user=刘瑞斌 【应用】MCP节点的工具参数引用参数时,对话过程中参数值发生变化,MCP节点没有获取最新的参数值 https://www.tapd.cn/57709429/s/1676830
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -18,7 +18,8 @@ def save_context(self, details, workflow_manage): | |||
|
|||
def execute(self, mcp_servers, mcp_server, mcp_tool, tool_params, **kwargs) -> NodeResult: | |||
servers = json.loads(mcp_servers) | |||
params = self.handle_variables(tool_params) | |||
params = json.loads(json.dumps(tool_params)) | |||
params = self.handle_variables(params) | |||
|
|||
async def call_tool(s, session, t, a): | |||
async with MultiServerMCPClient(s) as client: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code is generally well-written and follows standard Python conventions, but there are a few improvements and suggestions to enhance clarity and performance:
-
Unnecessary JSON Conversion: The line
params = json.loads(json.dumps(tool_params))
does not add significant value because it converts the input to a string and then back to an object. This can introduce additional processing time. -
Variable Naming: Use descriptive variable names instead of single characters (
s
,session
, etc.) to improve readability. -
Function Parameter Order: Ensure that function parameters are ordered consistently within their definitions.
-
Asynchronous Function Usage: Since
call_tool
usesawait
, make sure all asynchronous operations (likejson.loads
) are awaited properly.
Here's a revised version of the code with these improvements:
@@ -18,7 +18,7 @@ def save_context(self, details, workflow_manage):
async def execute(
self,
mcp_servers_json_str: str,
- tool_params_dict: dict,
+ tool_params_json_str: str,
**kwargs,
) -> NodeResult:
try:
# Load MCP server list from JSON string
servers = json.loads(mcp_servers_json_str)
Additional Recommendations:
- Error Handling: Consider adding error handling around JSON parsing and other operations to manage unexpected inputs gracefully.
- Logging: Implement logging to track the execution flow and any errors encountered during operation.
These changes should help ensure better understanding and maintainability of the code.
fix: ensure tool parameters are properly handled by reloading JSON --bug=1053980 --user=刘瑞斌 【应用】MCP节点的工具参数引用参数时,对话过程中参数值发生变化,MCP节点没有获取最新的参数值 https://www.tapd.cn/57709429/s/1676830