Update MCP Tools Handling and Fix Data Loss Bugs#502
Conversation
Input sent from UI contains a list of objects with fields name and description
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/SynapseLanguageService.java
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/SynapseLanguageService.java
Show resolved
Hide resolved
.../main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/AIConnectorHandler.java
Show resolved
Hide resolved
.../main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/AIConnectorHandler.java
Show resolved
Hide resolved
...e/lemminx/customservice/synapse/syntaxTree/factory/mediators/ai/AIAgentConnectorFactory.java
Show resolved
Hide resolved
...e/lemminx/customservice/synapse/syntaxTree/factory/mediators/ai/AIAgentConnectorFactory.java
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
There was a problem hiding this comment.
Pull request overview
This PR updates the AI Agent / MCP integration to preserve MCP connection/tool data through edit flows, handle empty MCP connections, and align server-side request/response shapes with the UI’s updated MCP tool payload (name + description) while keeping already-selected tools visible.
Changes:
- Allow
<mcpConnections>to be empty in the AI Agent XSD and render MCP connection keys in generated connector XML. - Extend AI Agent syntax tree model to include MCP connections and parse
<mcpConnections>/<mcpConfigKey>from XML. - Update MCP tools APIs and XML generation to carry tool descriptions and return already-selected tools for a given MCP connection.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/schemas/440/mediators/ai/aiAgent.xsd | Allows zero <mcpConfigKey> entries to support empty <mcpConnections>. |
| org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/440/templates/AIConnector.mustache | Emits MCP connection keys and renders MCP tools with type="mcp" + mcpConnection. |
| org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java | Adds helper to locate a DOM node by LSP position. |
| org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/syntaxTree/pojo/connector/ai/MCPConnections.java | Introduces syntax-tree POJO for MCP connection keys. |
| org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/syntaxTree/pojo/connector/ai/AIAgent.java | Adds mcpConnections field to AI Agent model. |
| org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/syntaxTree/factory/mediators/ai/AIAgentConnectorFactory.java | Parses <mcpConnections> and MCP <tool type="mcp"> attributes into the syntax tree. |
| org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/pojo/MCPToolResponse.java | Adds selectedTools to return tools already present in the document. |
| org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/pojo/MCPToolRequest.java | Adds documentUri + range so the server can compute selected tools in-context. |
| org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/AIConnectorHandler.java | Updates tool XML handling for MCP (name+description), and computes selectedTools in fetch. |
| org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/SynapseLanguageService.java | Wires new MCPToolRequest fields into the server call. |
Comments suppressed due to low confidence (1)
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/AIConnectorHandler.java:1396
- The Javadoc says
connectionName(and effectivelyrange) may be null/empty, but the implementation dereferencesrange.getStart()and usesconnectionName.equals(...), which will throw NPE for missing fields. Add explicit validation/early return (e.g., empty response with an error message) whendocumentUri,range, orconnectionNameare not provided, and handle the case whereconnectionsis null/empty without throwing.
public MCPToolResponse fetchMcpTools(String documentUri, Range range, List<Connection> connections,
String connectionName) {
MCPToolResponse response = new MCPToolResponse();
try {
DOMNode node = Utils.getDOMNode(documentUri, range.getStart());
List<String> existingToolsForConnection = getExistingToolsForConnection(node, connectionName);
Connection connection = connections.stream()
.filter(c -> connectionName.equals(c.getName()))
.findFirst()
.orElseThrow(() ->
new IllegalArgumentException("Connection not found: " + connectionName)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java
Outdated
Show resolved
Hide resolved
.../main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/AIConnectorHandler.java
Outdated
Show resolved
Hide resolved
.../main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/AIConnectorHandler.java
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/SynapseLanguageService.java
Show resolved
Hide resolved
…already exists If MCP tools are added for an already configured connection, treat it similarly to an update operation.
7b380f1
into
wso2:mi-ext-alpha-release
Purpose
This PR includes the following improvements and fixes: