Skip to content

Commit 361dff9

Browse files
MCP Server and MCP Connector documentation
Signed-off-by: rithin-pullela-aws <[email protected]>
1 parent 5ab4593 commit 361dff9

File tree

9 files changed

+257
-202
lines changed

9 files changed

+257
-202
lines changed

_ml-commons-plugin/agents-tools/mcp/mcp-connector.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nav_order: 10
1212

1313
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.
1414

15-
Currently, OpenSearch only supports MCP servers that use the Server-Sent Events (SSE) protocol. Standard Input/Output (`stdio`) protocol is not supported.
15+
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.
1616
{: .note}
1717

1818
The following example demonstrates using MCP tools in agentic workflows.
@@ -47,7 +47,9 @@ Ensure you have a running MCP server that is accessible from your OpenSearch clu
4747

4848
## Step 1: Create an MCP connector
4949

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

5254
```json
5355
POST /_plugins/_ml/connectors/_create
@@ -70,15 +72,39 @@ POST /_plugins/_ml/connectors/_create
7072
```
7173
{% include copy-curl.html %}
7274

75+
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:
76+
77+
```json
78+
POST /_plugins/_ml/connectors/_create
79+
{
80+
"name": "My MCP Connector (Streamable HTTP)",
81+
"description": "Connects to the external MCP server using Streamable HTTP",
82+
"version": 1,
83+
"protocol": "mcp_streamable_http",
84+
"url": "https://my-mcp-server.domain.com",
85+
"credential": {
86+
"mcp_server_key": "THE_MCP_SERVER_API_KEY"
87+
},
88+
"parameters": {
89+
"endpoint": "/_plugins/_ml/mcp"
90+
},
91+
"headers": {
92+
"Authorization": "Bearer ${credential.mcp_server_key}"
93+
}
94+
}
95+
```
96+
{% include copy-curl.html %}
97+
7398
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).
7499

75100
| Parameter | Data type | Required | Description |
76101
|:----------|:---------|:------------|
77-
| `protocol` | String | Yes | Specify `mcp_sse` to use the SSE protocol (the only supported protocol type for MCP). |
102+
| `protocol` | String | Yes | Specify `mcp_sse` for SSE or `mcp_streamable_http` for Streamable HTTP. |
78103
| `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`). |
79104
| `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. |
80105
| `parameters` | Object | No | Contains configuration parameters for the MCP connector. |
81-
| `parameters.sse_endpoint` | String | No | The SSE endpoint path for the MCP server. Default is `/sse`. |
106+
| `parameters.sse_endpoint` | String | No | Only for SSE: The SSE endpoint path for the MCP server. Default is `/sse`. |
107+
| `parameters.endpoint` | String | No | Only for Streamable HTTP: The MCP server endpoint path. Default is `/mcp`. |
82108
| `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}"`). |
83109

84110
The response contains the connector ID:

_ml-commons-plugin/api/mcp-server-apis/index.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,17 @@ redirect_from:
1111

1212
# MCP server APIs
1313
**Introduced 3.0**
14-
{: .label .label-purple }
1514

16-
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/).
17-
{: .warning}
1815

19-
[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/).
16+
[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/).
2017

21-
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.
22-
{: .note}
18+
The MCP server in MLCommons 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)
19+
{: .note }
2320

2421
ML Commons supports the following MCP APIs:
2522

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

_ml-commons-plugin/api/mcp-server-apis/list-mcp-tools.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ nav_order: 30
88

99
# List MCP Tools API
1010
**Introduced 3.1**
11-
{: .label .label-purple }
12-
13-
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/).
14-
{: .warning}
1511

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

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
---
2+
layout: default
3+
title: MCP Streamable HTTP Server
4+
parent: MCP server APIs
5+
grand_parent: ML Commons APIs
6+
nav_order: 50
7+
---
8+
9+
# MCP Streamable HTTP Server
10+
**Introduced 3.3**
11+
{: .label .label-purple }
12+
13+
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/clients to connect to OpenSearch and discover and call available tools.
14+
15+
This server does not open a persistent SSE connection with the client; all communication happens over stateless HTTP calls.
16+
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 with POST-based communication.
17+
18+
19+
To learn more about the transport, see the [official MCP documentation](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports)
20+
{: .note }
21+
22+
## Prerequisites
23+
- Enable the MCP server setting.
24+
- Optionally register tools so you can see and call them via the MCP server.
25+
26+
### Enable the MCP server
27+
```json
28+
PUT /_cluster/settings
29+
{
30+
"persistent": {
31+
"plugins.ml_commons.mcp_server_enabled": "true"
32+
}
33+
}
34+
```
35+
{% include copy-curl.html %}
36+
37+
### (Optional) Register tools
38+
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/).
39+
40+
## Usage
41+
You can connect to the MCP server using any client that supports the Streamable HTTP transport. Below are two approaches:
42+
43+
### Using an MCP client
44+
The following example uses `fastmcp` to initialize a connection, list tools, and call a tool:
45+
46+
```python
47+
import asyncio, logging
48+
from fastmcp import Client
49+
50+
51+
async def main():
52+
async with Client("http://localhost:9200/_plugins/_ml/mcp") as client:
53+
for t in await client.list_tools():
54+
print(t.name)
55+
r = await client.call_tool("ListIndexTool", {})
56+
print("result: ", r)
57+
58+
asyncio.run(main())
59+
```
60+
61+
### Manual invocation (for debugging)
62+
While not required for normal usage, you can manually invoke the MCP server using JSON-RPC calls over HTTP. The sequence below mirrors typical MCP client behavior.
63+
64+
#### 1. Initialize connection
65+
Example request:
66+
67+
```json
68+
POST /_plugins/_ml/mcp
69+
{
70+
"jsonrpc": "2.0",
71+
"id": 1,
72+
"method": "initialize",
73+
"params": {
74+
"protocolVersion": "2025-03-26",
75+
"capabilities": {
76+
"roots": {
77+
"listChanged": true
78+
},
79+
"sampling": {}
80+
},
81+
"clientInfo": {
82+
"name": "test-client",
83+
"version": "1.0.0"
84+
}
85+
}
86+
}
87+
```
88+
{% include copy-curl.html %}
89+
90+
Example response:
91+
92+
```json
93+
200 OK
94+
{
95+
"jsonrpc": "2.0",
96+
"id": 1,
97+
"result": {
98+
"protocolVersion": "2025-03-26",
99+
"capabilities": {
100+
"logging": {},
101+
"prompts": {
102+
"listChanged": false
103+
},
104+
"resources": {
105+
"subscribe": false,
106+
"listChanged": false
107+
},
108+
"tools": {
109+
"listChanged": true
110+
}
111+
},
112+
"serverInfo": {
113+
"name": "OpenSearch-MCP-Stateless-Server",
114+
"version": "0.1.0"
115+
},
116+
"instructions": "OpenSearch MCP Stateless Server - provides access to ML tools without sessions"
117+
}
118+
}
119+
```
120+
121+
#### 2. Send initialization complete notification
122+
Example request:
123+
124+
```json
125+
POST /_plugins/_ml/mcp
126+
{
127+
"jsonrpc": "2.0",
128+
"method": "notifications/initialized",
129+
"params": {}
130+
}
131+
```
132+
{% include copy-curl.html %}
133+
134+
Example response:
135+
136+
```json
137+
202 Accepted
138+
```
139+
140+
#### 3. List available tools
141+
Use this to discover tools. See also [List MCP tools]({{site.url}}{{site.baseurl}}/ml-commons-plugin/api/mcp-server-apis/list-mcp-tools/).
142+
143+
Example request:
144+
145+
```json
146+
POST /_plugins/_ml/mcp
147+
{
148+
"jsonrpc": "2.0",
149+
"id": 2,
150+
"method": "tools/list",
151+
"params": {}
152+
}
153+
```
154+
{% include copy-curl.html %}
155+
156+
Example response:
157+
158+
```json
159+
200 OK
160+
{
161+
"jsonrpc": "2.0",
162+
"id": 2,
163+
"result": {
164+
"tools": [
165+
{
166+
"name": "ListIndexTool",
167+
"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)",
168+
"inputSchema": {
169+
"type": "object",
170+
"properties": {
171+
"indices": {
172+
"type": "array",
173+
"items": {
174+
"type": "string"
175+
},
176+
"description": "OpenSearch index name list, separated by comma. for example: [\"index1\", \"index2\"], use empty array [] to list all indices in the cluster"
177+
}
178+
},
179+
"additionalProperties": false
180+
}
181+
}
182+
]
183+
}
184+
}
185+
```
186+
187+
#### 4. Call a tool
188+
Example request:
189+
190+
```json
191+
POST /_plugins/_ml/mcp
192+
{
193+
"jsonrpc": "2.0",
194+
"id": 3,
195+
"method": "tools/call",
196+
"params": {
197+
"name": "ListIndexTool",
198+
"arguments": {
199+
"indices": []
200+
}
201+
}
202+
}
203+
```
204+
{% include copy-curl.html %}
205+
206+
Example response:
207+
208+
```json
209+
200 OK
210+
{
211+
"jsonrpc": "2.0",
212+
"id": 3,
213+
"result": {
214+
"content": [
215+
{
216+
"type": "text",
217+
"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"
218+
}
219+
],
220+
"isError": false
221+
}
222+
}
223+
```

_ml-commons-plugin/api/mcp-server-apis/register-mcp-tools.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ nav_order: 10
88

99
# Register MCP Tools API
1010
**Introduced 3.0**
11-
{: .label .label-purple }
12-
13-
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/).
14-
{: .warning}
1511

1612
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/).
1713

_ml-commons-plugin/api/mcp-server-apis/remove-mcp-tools.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ nav_order: 40
88

99
# Remove MCP Tools API
1010
**Introduced 3.0**
11-
{: .label .label-purple }
1211

13-
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/).
14-
{: .warning}
1512

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

0 commit comments

Comments
 (0)