Skip to content

Commit 3ef75a2

Browse files
Handle MCP tools addition as an update operation when the connection already exists
If MCP tools are added for an already configured connection, treat it similarly to an update operation.
1 parent 86113c5 commit 3ef75a2

File tree

1 file changed

+1
-41
lines changed

1 file changed

+1
-41
lines changed

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/AIConnectorHandler.java

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private SynapseConfigResponse addAIAgentTool(String documentUri, Range range, St
387387
DOMNode mcpMediatorNode = node.getParentNode();
388388

389389
// Build updated <tools> XML
390-
String updatedToolsXml = buildMergedToolsXml(document, node, connectionName, mcpToolsSelection);
390+
String updatedToolsXml = buildUpdatedToolsXml(document, node, connectionName, mcpToolsSelection);
391391
TextEdit edit = createToolsTextEdit(document, node, mcpMediatorNode, updatedToolsXml, documentUri);
392392
agentEditResponse.addTextEdit(edit);
393393

@@ -1117,46 +1117,6 @@ private SynapseConfigResponse modifyAgentTool(String documentUri, Range range, S
11171117
return agentEditResponse;
11181118
}
11191119

1120-
/**
1121-
* Builds a merged `<tools>` XML fragment by preserving existing tool entries and adding new tools
1122-
* for the specified MCP connection.
1123-
*
1124-
* <p>For each existing tool node, the original XML is preserved. If an existing tool belongs to the
1125-
* `targetConnection`, its name is recorded so duplicates are not added. Any tool name present in
1126-
* `selectedTools` but not already present for the `targetConnection` will be created and appended.</p>
1127-
*
1128-
* @param document the DOMDocument representing the current XML document (used to extract existing tool XML)
1129-
* @param toolsNode the DOMNode representing the parent `<tools>` element; may be null
1130-
* @param targetConnection the name of the MCP connection to which selected tools should be associated
1131-
* @param selectedTools list of MCP tools selected, each represented as a map with a "name" key and a
1132-
* "description" key
1133-
* @return the rendered XML string for the merged `<tools>` block
1134-
*/
1135-
private String buildMergedToolsXml(DOMDocument document, DOMNode toolsNode, String targetConnection,
1136-
List<Map<String, Object>> selectedTools) {
1137-
1138-
List<ExistingTool> existingTools = extractExistingTools(document, toolsNode);
1139-
List<String> finalXMLs = new ArrayList<>();
1140-
Set<String> existingNamesForConnection = new HashSet<>();
1141-
1142-
for (ExistingTool tool : existingTools) {
1143-
finalXMLs.add(tool.xml);
1144-
if (targetConnection.equals(tool.connection)) {
1145-
existingNamesForConnection.add(tool.name);
1146-
}
1147-
}
1148-
1149-
for (Map<String, Object> toolMap : selectedTools) {
1150-
String toolName = (String) toolMap.get(Constant.NAME);
1151-
String toolDescription = (String) toolMap.get(Constant.DESCRIPTION);
1152-
if (!existingNamesForConnection.contains(toolName)) {
1153-
String newToolXml = createNewMCPToolXml(toolName, toolDescription, targetConnection);
1154-
finalXMLs.add(newToolXml.stripTrailing());
1155-
}
1156-
}
1157-
return generateToolsXmlFromStrings(finalXMLs);
1158-
}
1159-
11601120
/**
11611121
* Builds an updated `<tools>` XML fragment for the MCP agent.
11621122
* <p>

0 commit comments

Comments
 (0)