Skip to content

Support persisting MCP tools in system index #3874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

zane-neo
Copy link
Collaborator

@zane-neo zane-neo commented May 26, 2025

Description

Support persisting MCP tools in system index in register API and adding new API, below are the new APIs specification:
Update MCP tools

POST /_plugins/_ml/mcp/tools/_update
{
  "type": "PPLTool",
  "name": "My_TransferQuestionToPPLAndExecuteTool", //name is mandatory.
  "description": "Use this tool to convert natural language into PPL queries and execute them. Use this tool after you know the index name; otherwise, call IndexRoutingTool first. The input parameters are: {index: IndexName, question: UserQuestion}",
  "parameters": {
    "model_id": "${new_model_id}",
    "model_type": "FINETUNE"
  },
  "attributes": {
    "input_schema": {
      "type": "object",
      "properties": {
        "question": {
          "type": "string",
          "description": "The user's natural language question that needs to be converted to PPL."
        },
        "index": {
          "type": "string",
          "description": "The index on which the generated PPL query will be executed."
        }
      }
    }
  }
}

Sample response

{
    "3OVC3xeVSzmd60pbnlEeRw": {
        "updated": true
    }
}

List MCP tools

GET /_plugins/_ml/mcp/tools/_list

Sample response

{
    "tools": [
        {
            "type": "ListIndexTool",
            "name": "MyListIndexTool1",
            "description": "This is my first list index tool",
            "attributes": {
                "input_schema": {
                    "additionalProperties": false,
                    "type": "object",
                    "properties": {
                        "indices": {
                            "description": "A comma-separated list of OpenSearch index names. For example: [\"index1\", \"index2\"]. Use [] (an empty array) to list all indices in the cluster.",
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "create_time": 1748421099398
        }
    ]
}

Related Issues

#3841

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

import lombok.extern.log4j.Log4j2;

/**
* This class represents a tool that can be registered with OpenSearch. It contains information about the tool's name,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can make it clear by mentioning openSearch MCP Server.

Also can we use a better name for RegisterMcpTool. This sounds like an action(function) rather than a class's name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed to McpToolRegsiterInput for this and McpToolUpdateInput for UpdateMcpTool.

Instant lastUpdateTime
) {
super(name, type, description, parameters, attributes, createdTime, lastUpdateTime);
if (type == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check for type first and then call the super method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

super invocation should be in the first line of a constructor which is a java syntax limitation.

private static final String TYPE_NOT_SHOWN_EXCEPTION_MESSAGE = "type field required";
private Instant createdTime;
private Instant lastUpdatedTime;
public static final String TYPE_NOT_SHOWN_EXCEPTION_MESSAGE = "type field required";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move this variable to the RegisterBaseTool file if we are not using it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

private Instant createdTime;
private Instant lastUpdatedTime;
public static final String TYPE_NOT_SHOWN_EXCEPTION_MESSAGE = "type field required";
public static final String NAME_NOT_SHOWN_EXCEPTION_MESSAGE = "name field required";
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, can we move to the update file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,74 @@
package org.opensearch.ml.common.transport.mcpserver.requests.update;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the license header?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,45 @@
package org.opensearch.ml.common.transport.mcpserver.responses.list;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add license header?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@zane-neo zane-neo force-pushed the persist-mcp-tools branch from a60f924 to 1f6f359 Compare May 29, 2025 06:20
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env May 29, 2025 06:21 — with GitHub Actions Error
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env May 29, 2025 06:21 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env May 29, 2025 06:21 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env May 29, 2025 06:21 — with GitHub Actions Error
import org.opensearch.action.ActionType;
import org.opensearch.ml.common.transport.mcpserver.responses.remove.MLMcpToolsRemoveNodesResponse;

public class MLMcpToolsRemoveAction extends ActionType<MLMcpToolsRemoveNodesResponse> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that delete? Can we be consistent with other apis as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean to rename the class or rename the API? In first release we named the API like below:

POST /_plugins/_ml/mcp/tools/_remove
[
 "WebSearchTool", "ListIndexTool"
]

@zane-neo zane-neo force-pushed the persist-mcp-tools branch from 1f6f359 to 606a7c1 Compare June 3, 2025 03:01
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 03:02 — with GitHub Actions Error
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 03:02 — with GitHub Actions Error
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 03:02 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 03:02 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 06:23 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 06:23 — with GitHub Actions Error
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 06:23 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 06:23 — with GitHub Actions Error
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 08:36 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 08:36 — with GitHub Actions Failure
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 08:36 — with GitHub Actions Error
@zane-neo zane-neo had a problem deploying to ml-commons-cicd-env June 3, 2025 08:36 — with GitHub Actions Error
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.

4 participants