Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
34 changes: 30 additions & 4 deletions _ml-commons-plugin/agents-tools/mcp/mcp-connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

OpenSearch supports agentic workflows using [agents]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/agents/). While OpenSearch provides built-in tools for running complex queries, [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) enables integration with external tools and data sources. MCP is an open protocol standard that provides a standardized way for AI models to connect to external data sources and tools, acting as a "universal adapter" for remote MCP server tools.

Currently, OpenSearch only supports MCP servers that use the Server-Sent Events (SSE) protocol. Standard Input/Output (`stdio`) protocol is not supported.
OpenSearch supports MCP servers that use either the Server-Sent Events (SSE) protocol or the Streamable HTTP protocol. Standard Input/Output (`stdio`) protocol is not supported.

Check failure on line 15 in _ml-commons-plugin/agents-tools/mcp/mcp-connector.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_ml-commons-plugin/agents-tools/mcp/mcp-connector.md", "range": {"start": {"line": 15, "column": 94}}}, "severity": "ERROR"}
{: .note}

The following example demonstrates using MCP tools in agentic workflows.
Expand Down Expand Up @@ -47,7 +47,9 @@

## Step 1: Create an MCP connector

An MCP connector stores connection details and credentials for your MCP server. To create an MCP connector, send the following request:
An MCP connector stores connection details and credentials for your MCP server. You can connect using either SSE or Streamable HTTP.

Check failure on line 50 in _ml-commons-plugin/agents-tools/mcp/mcp-connector.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_ml-commons-plugin/agents-tools/mcp/mcp-connector.md", "range": {"start": {"line": 50, "column": 117}}}, "severity": "ERROR"}

To create an MCP connector using SSE, send the following request:

```json
POST /_plugins/_ml/connectors/_create
Expand All @@ -70,15 +72,39 @@
```
{% include copy-curl.html %}

To create an MCP connector using Streamable HTTP, set `protocol` to `mcp_streamable_http`. Optionally, set `parameters.endpoint` to override the default endpoint (`/_plugins/_ml/mcp`). No SSE-specific endpoint is required:

```json
POST /_plugins/_ml/connectors/_create
{
"name": "My MCP Connector (Streamable HTTP)",
"description": "Connects to the external MCP server using Streamable HTTP",
"version": 1,
"protocol": "mcp_streamable_http",
"url": "https://my-mcp-server.domain.com",
"credential": {
"mcp_server_key": "THE_MCP_SERVER_API_KEY"
},
"parameters": {
"endpoint": "/_plugins/_ml/mcp"
},
"headers": {
"Authorization": "Bearer ${credential.mcp_server_key}"
}
}
```
{% include copy-curl.html %}

The following table describes the connector parameters. For more information about standard connector parameters, see [Configuration parameters]({{site.url}}{{site.baseurl}}/ml-commons-plugin/remote-models/blueprints/#configuration-parameters).

| Parameter | Data type | Required | Description |
|:----------|:---------|:------------|
| `protocol` | String | Yes | Specify `mcp_sse` to use the SSE protocol (the only supported protocol type for MCP). |
| `protocol` | String | Yes | Specify `mcp_sse` for SSE or `mcp_streamable_http` for Streamable HTTP. |
| `url` | String | Yes | The complete base URL of the MCP server, including protocol, hostname, and port, if not using the default port (for example, `https://my-mcp-server.com:8443`). |
| `credential` | Object | Yes | Contains sensitive authentication information such as API keys or tokens. Values stored in this object can be securely referenced in the `headers` section using the `${credential.*}` syntax. |
| `parameters` | Object | No | Contains configuration parameters for the MCP connector. |
| `parameters.sse_endpoint` | String | No | The SSE endpoint path for the MCP server. Default is `/sse`. |
| `parameters.sse_endpoint` | String | No | Applicable for SSE only. The SSE endpoint path for the MCP server. Default is `/sse`. |
| `parameters.endpoint` | String | No | Applicable for Streamable HTTP only. The MCP server endpoint path. Default is `/mcp`. |
| `headers` | Object | No | The HTTP headers to include with requests to the MCP server. For authentication headers, use the `${credential.*}` syntax to reference values from the `credential` object (for example, `"Authorization": "Bearer ${credential.mcp_server_key}"`). |

The response contains the connector ID:
Expand Down
22 changes: 13 additions & 9 deletions _ml-commons-plugin/api/mcp-server-apis/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@
nav_order: 40
redirect_from:
- /ml-commons-plugin/api/mcp-server-apis/
- /ml-commons-plugin/api/mcp-server-apis/sse-message/
- /ml-commons-plugin/api/mcp-server-apis/sse-session/
---

# MCP server APIs
**Introduced 3.0**
{: .label .label-purple }

This is an experimental feature and is not recommended for use in a production environment. For updates on the progress of the feature or if you want to leave feedback, join the discussion on the [OpenSearch forum](https://forum.opensearch.org/).
{: .warning}
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) defines how an agent can discover and execute tools. The MCP server in OpenSearch allows agents to connect and use available [tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/tools/).

[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is a protocol that defines how an agent can discover and execute tools. The MCP server allows external agents to connect to and use [tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/tools/) available in OpenSearch. For a list of supported tools, see [Tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/tools/).

The default HTTP transport method does not support streaming. You must install the [`transport-reactor-netty4`]({{site.url}}{{site.baseurl}}/install-and-configure/configuring-opensearch/network-settings/#selecting-the-transport) HTTP transport plugin and use it as the default HTTP transport layer. Both the `transport-reactor-netty4` plugin and the MCP server feature are experimental.
{: .note}
The MCP server in ML Commons uses the Streamable HTTP transport protocol to communicate with the clients. For details about the transport, see the [official MCP documentation](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports)

Check failure on line 19 in _ml-commons-plugin/api/mcp-server-apis/index.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_ml-commons-plugin/api/mcp-server-apis/index.md", "range": {"start": {"line": 19, "column": 39}}}, "severity": "ERROR"}
{: .note }

ML Commons supports the following MCP APIs:

- [Register MCP tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/register-mcp-tools/)
- [Update MCP tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/update-mcp-tools/)
- [List MCP tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/list-mcp-tools/)
- [Remove MCP tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/remove-mcp-tools/)
- [MCP SSE session]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/sse-session/)
- [MCP SSE message]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/sse-message/)
- [MCP Streamable HTTP Server]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/mcp-server/)

Check failure on line 28 in _ml-commons-plugin/api/mcp-server-apis/index.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_ml-commons-plugin/api/mcp-server-apis/index.md", "range": {"start": {"line": 28, "column": 8}}}, "severity": "ERROR"}

## Removed APIs

The following experimental APIs were removed in OpenSearch 3.3 in favor of the Streamable HTTP transport:

Check failure on line 32 in _ml-commons-plugin/api/mcp-server-apis/index.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_ml-commons-plugin/api/mcp-server-apis/index.md", "range": {"start": {"line": 32, "column": 80}}}, "severity": "ERROR"}

- MCP SSE Message API
- MCP SSE Session API
4 changes: 0 additions & 4 deletions _ml-commons-plugin/api/mcp-server-apis/list-mcp-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ nav_order: 30

# List MCP Tools API
**Introduced 3.1**
{: .label .label-purple }

This is an experimental feature and is not recommended for use in a production environment. For updates on the progress of the feature or if you want to leave feedback, join the discussion on the [OpenSearch forum](https://forum.opensearch.org/).
{: .warning}

Use this API to list all Model Context Protocol (MCP)-based tools by name.

Expand Down
229 changes: 229 additions & 0 deletions _ml-commons-plugin/api/mcp-server-apis/mcp-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
---
layout: default
title: MCP Streamable HTTP Server
parent: MCP server APIs
grand_parent: ML Commons APIs
nav_order: 50
---

# MCP Streamable HTTP Server API

Check failure on line 9 in _ml-commons-plugin/api/mcp-server-apis/mcp-server.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_ml-commons-plugin/api/mcp-server-apis/mcp-server.md", "range": {"start": {"line": 9, "column": 7}}}, "severity": "ERROR"}

Check failure on line 9 in _ml-commons-plugin/api/mcp-server-apis/mcp-server.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.HeadingCapitalization] 'MCP Streamable HTTP Server API' is a heading and should be in sentence case. Raw Output: {"message": "[OpenSearch.HeadingCapitalization] 'MCP Streamable HTTP Server API' is a heading and should be in sentence case.", "location": {"path": "_ml-commons-plugin/api/mcp-server-apis/mcp-server.md", "range": {"start": {"line": 9, "column": 3}}}, "severity": "ERROR"}
**Introduced 3.3**
{: .label .label-purple }

The MCP server is exposed via the `/_plugins/_ml/mcp` endpoint and implements the Streamable HTTP transport defined by the Model Context Protocol (MCP). It allows agents or clients to connect to OpenSearch and discover or invoke available tools.

Check failure on line 13 in _ml-commons-plugin/api/mcp-server-apis/mcp-server.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_ml-commons-plugin/api/mcp-server-apis/mcp-server.md", "range": {"start": {"line": 13, "column": 83}}}, "severity": "ERROR"}

Check warning on line 13 in _ml-commons-plugin/api/mcp-server-apis/mcp-server.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.LatinismsSubstitution] Use 'using, through, by accessing, or by choosing' instead of 'via'. Raw Output: {"message": "[OpenSearch.LatinismsSubstitution] Use 'using, through, by accessing, or by choosing' instead of 'via'.", "location": {"path": "_ml-commons-plugin/api/mcp-server-apis/mcp-server.md", "range": {"start": {"line": 13, "column": 27}}}, "severity": "WARNING"}

This server does not open a persistent SSE connection with the client; all communication happens over stateless HTTP calls.
If a client sends a `GET` request (typically, to establish an SSE connection), the server returns a `405 Method Not Allowed` response, allowing the client to continue using `POST` communication.


To learn more about the transport, see the [official MCP documentation](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports).
{: .note }

## Prerequisites

Before you can connect to the MCP server endpoint, enable the MCP server functionality in your cluster:

```json
PUT /_cluster/settings
{
"persistent": {
"plugins.ml_commons.mcp_server_enabled": "true"
}
}
```
{% include copy-curl.html %}

Optionally, you can register tools so clients can discover and call them. See [Register MCP tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/register-mcp-tools/).

## Connecting to the MCP server

You can connect to the MCP server using any client that supports the Streamable HTTP transport.

Check failure on line 40 in _ml-commons-plugin/api/mcp-server-apis/mcp-server.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Streamable. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_ml-commons-plugin/api/mcp-server-apis/mcp-server.md", "range": {"start": {"line": 40, "column": 70}}}, "severity": "ERROR"}

### Connecting using an MCP client

The following example uses `fastmcp` to initialize a connection, list tools, and call a tool:

```python
import asyncio, logging
from fastmcp import Client


async def main():
async with Client("http://localhost:9200/_plugins/_ml/mcp") as client:
for t in await client.list_tools():
print(t.name)
r = await client.call_tool("ListIndexTool", {})
print("result: ", r)

asyncio.run(main())
```
{% include copy.html %}

### Invoking the MCP server manually (for debugging)

While not required for normal usage, you can manually invoke the MCP server using JSON-RPC calls over HTTP. The following example presents typical MCP client behavior.

#### Step 1: Initialize a connection

Send an `initialize` method with your client information and capabilities. Note the `protocolVersion` must match the MCP specification version:

```json
POST /_plugins/_ml/mcp
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {
"roots": {
"listChanged": true
},
"sampling": {}
},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}
```
{% include copy-curl.html %}

The server responds with its capabilities and server information. The `tools.listChanged` indicates that the server supports dynamic tool discovery:

```json
200 OK
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2025-03-26",
"capabilities": {
"logging": {},
"prompts": {
"listChanged": false
},
"resources": {
"subscribe": false,
"listChanged": false
},
"tools": {
"listChanged": true
}
},
"serverInfo": {
"name": "OpenSearch-MCP-Stateless-Server",
"version": "0.1.0"
},
"instructions": "OpenSearch MCP Stateless Server - provides access to ML tools without sessions"
}
}
```

#### Step 2: Send an initialization complete notification

Send a notification to indicate that initialization is complete. This notification does not expect a response payload:

```json
POST /_plugins/_ml/mcp
{
"jsonrpc": "2.0",
"method": "notifications/initialized",
"params": {}
}
```
{% include copy-curl.html %}

The server acknowledges the notification with a `202 Accepted` status:

```json
202 Accepted
```

#### Step 3: List available tools

Use the `tools/list` method to discover available tools:

```json
POST /_plugins/_ml/mcp
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}
```
{% include copy-curl.html %}

For a dedicated API, see [List MCP tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/list-mcp-tools/).

The server returns an array of available tools with their names, descriptions, and input schemas. Notice how each tool includes a detailed `inputSchema` that describes the expected parameters:

```json
200 OK
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "ListIndexTool",
"description": "This tool returns information about indices in the OpenSearch cluster along with the index `health`, `status`, `index`, `uuid`, `pri`, `rep`, `docs.count`, `docs.deleted`, `store.size`, `pri.store. size `, `pri.store.size`, `pri.store`. Optional arguments: 1. `indices`, a comma-delimited list of one or more indices to get information from (default is an empty list meaning all indices). Use only valid index names. 2. `local`, whether to return information from the local node only instead of the cluster manager node (Default is false)",
"inputSchema": {
"type": "object",
"properties": {
"indices": {
"type": "array",
"items": {
"type": "string"
},
"description": "OpenSearch index name list, separated by comma. for example: [\"index1\", \"index2\"], use empty array [] to list all indices in the cluster"
}
},
"additionalProperties": false
}
}
]
}
}
```

#### Step 4: Call a tool

Use the `tools/call` method to invoke a specific tool. Provide the tool name and arguments that match the tool's input schema:

```json
POST /_plugins/_ml/mcp
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "ListIndexTool",
"arguments": {
"indices": []
}
}
}
```
{% include copy-curl.html %}

The server executes the tool and returns the result in the `content` array. The `isError` field indicates whether the tool execution was successful:

```json
200 OK
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": "row,health,status,index,uuid,pri(number of primary shards),rep(number of replica shards),docs.count(number of available documents),docs.deleted(number of deleted documents),store.size(store size of primary and replica shards),pri.store.size(store size of primary shards)\n1,green,open,.plugins-ml-config,nKyzDAupTGCwuybs9S_iBA,1,0,1,0,3.9kb,3.9kb\n2,green,open,.plugins-ml-mcp-tools,k1QwQKmXSeqRexmB2JDJiw,1,0,1,0,5kb,5kb\n"
}
],
"isError": false
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ nav_order: 10

# Register MCP Tools API
**Introduced 3.0**
{: .label .label-purple }

This is an experimental feature and is not recommended for use in a production environment. For updates on the progress of the feature or if you want to leave feedback, join the discussion on the [OpenSearch forum](https://forum.opensearch.org/).
{: .warning}

Use this API to register one or more Model Context Protocol (MCP)-based tools. For more information about supported tools, see [Tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/tools/index/).

Expand Down
3 changes: 0 additions & 3 deletions _ml-commons-plugin/api/mcp-server-apis/remove-mcp-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ nav_order: 40

# Remove MCP Tools API
**Introduced 3.0**
{: .label .label-purple }

This is an experimental feature and is not recommended for use in a production environment. For updates on the progress of the feature or if you want to leave feedback, join the discussion on the [OpenSearch forum](https://forum.opensearch.org/).
{: .warning}

Use this API to delete one or more Model Context Protocol (MCP)-based tools by name.

Expand Down
Loading
Loading