fix: ensure tool parameters are properly handled by reloading JSON#2698
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. DetailsInstructions 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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| 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.
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_toolusesawait, 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