Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Copy Markdown
Contributor Author

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:

  1. 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.

  2. Variable Naming: Use descriptive variable names instead of single characters (s, session, etc.) to improve readability.

  3. Function Parameter Order: Ensure that function parameters are ordered consistently within their definitions.

  4. Asynchronous Function Usage: Since call_tool uses await, make sure all asynchronous operations (like json.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.

Expand Down