Skip to content

Comments

Update MCP Tools Handling and Fix Data Loss Bugs#502

Merged
chathuranga-jayanath-99 merged 7 commits intowso2:mi-ext-alpha-releasefrom
chathuranga-jayanath-99:mcp-bug-fixes
Feb 19, 2026
Merged

Update MCP Tools Handling and Fix Data Loss Bugs#502
chathuranga-jayanath-99 merged 7 commits intowso2:mi-ext-alpha-releasefrom
chathuranga-jayanath-99:mcp-bug-fixes

Conversation

@chathuranga-jayanath-99
Copy link
Contributor

@chathuranga-jayanath-99 chathuranga-jayanath-99 commented Feb 19, 2026

Purpose

This PR includes the following improvements and fixes:

  • Preserve MCP Tools Data: Fixed an issue where MCP tools data was lost when updating the AI Agent connector operation.
  • Empty Connections Handling: Resolved errors that indicated when MCP connections were empty.
  • Support Name and Description for each MCP tool: Updated request and response handling to include both name and description for each MCP tool, as the UI now sends both fields.
  • Maintain Selected Tools: Ensured that already selected tools are sent along with the available tools when adding tools from a connection.
  • Handle Adding Tools for Already Added Connection: Adding tools for an already configured connection is handled similar to an update operation

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • 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.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1
#### Log Improvement Suggestion No: 2
#### Log Improvement Suggestion No: 3
#### Log Improvement Suggestion No: 4
#### Log Improvement Suggestion No: 5
#### Log Improvement Suggestion No: 6
#### Log Improvement Suggestion No: 7
#### Log Improvement Suggestion No: 8

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 effectively range) may be null/empty, but the implementation dereferences range.getStart() and uses connectionName.equals(...), which will throw NPE for missing fields. Add explicit validation/early return (e.g., empty response with an error message) when documentUri, range, or connectionName are not provided, and handle the case where connections is 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.

…already exists

If MCP tools are added for an already configured connection, treat it similarly to an update operation.
@chathuranga-jayanath-99 chathuranga-jayanath-99 merged commit 7b380f1 into wso2:mi-ext-alpha-release Feb 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants