Skip to main content

OpenSearch MCP Server

A minimal Model Context Protocol (MCP) server for OpenSearch exposing 4 tools over stdio and sse server.

Available tools

  • ListIndexTool: Lists all indices in OpenSearch.
  • IndexMappingTool: Retrieves index mapping and setting information for an index in OpenSearch.
  • SearchIndexTool: Searches an index using a query written in query domain-specific language (DSL) in OpenSearch.
  • GetShardsTool: Gets information about shards in OpenSearch.

More tools coming soon. Click here

User Guide

Installation

Install from PyPI:

pip install test-opensearch-mcp

Configuration

Authentication Methods:

  • Basic Authentication
export OPENSEARCH_URL="<your_opensearch_domain_url>"
export OPENSEARCH_USERNAME="<your_opensearch_domain_username>"
export OPENSEARCH_PASSWORD="<your_opensearch_domain_password>"
  • IAM Role Authentication
export OPENSEARCH_URL="<your_opensearch_domain_url>"
export AWS_REGION="<your_aws_region>"
export AWS_ACCESS_KEY="<your_aws_access_key>"
export AWS_SECRET_ACCESS_KEY="<your_aws_secret_access_key>"
export AWS_SESSION_TOKEN="<your_aws_session_token>"

Running the Server

# Stdio Server
python -m mcp_server_opensearch

# SSE Server
python -m mcp_server_opensearch --transport sse

Claude Desktop Integration

{
    "mcpServers": {
        "opensearch-mcp-server": {
            "command": "uvx",
            "args": [
                "test-opensearch-mcp"
            ],
            "env": {
                // Required
                "OPENSEARCH_URL": "<your_opensearch_domain_url>",

                // For Basic Authentication
                "OPENSEARCH_USERNAME": "<your_opensearch_domain_username>",
                "OPENSEARCH_PASSWORD": "<your_opensearch_domain_password>",

                // For IAM Role Authentication
                "AWS_REGION": "<your_aws_region>",
                "AWS_ACCESS_KEY": "<your_aws_access_key>",
                "AWS_SECRET_ACCESS_KEY": "<your_aws_secret_access_key>",
                "AWS_SESSION_TOKEN": "<your_aws_session_token>"
            }
        }
    }
}
  • Using the Installed Package (via pip):
{
    "mcpServers": {
        "opensearch-mcp-server": {
            "command": "python",  // Or full path to python with PyPI package installed
            "args": [
                "-m",
                "mcp_server_opensearch"
            ],
            "env": {
                // Required
                "OPENSEARCH_URL": "<your_opensearch_domain_url>",

                // For Basic Authentication
                "OPENSEARCH_USERNAME": "<your_opensearch_domain_username>",
                "OPENSEARCH_PASSWORD": "<your_opensearch_domain_password>",

                // For IAM Role Authentication
                "AWS_REGION": "<your_aws_region>",
                "AWS_ACCESS_KEY": "<your_aws_access_key>",
                "AWS_SECRET_ACCESS_KEY": "<your_aws_secret_access_key>",
                "AWS_SESSION_TOKEN": "<your_aws_session_token>"
            }
        }
    }
}

LangChain Integration

The OpenSearch MCP server can be easily integrated with LangChain using the SSE server transport

Prerequisites

  1. Install required packages
pip install langchain langchain-mcp-adapters langchain-openai
  1. Set up OpenAI API key
export OPENAI_API_KEY="<your-openai-key>"
  1. Ensure OpenSearch MCP server is running in SSE mode
python -m mcp_server_opensearch --transport sse

Example Integration Script

import asyncio
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_openai import ChatOpenAI
from langchain.agents import AgentType, initialize_agent

# Initialize LLM (can use any LangChain-compatible LLM)
model = ChatOpenAI(model="gpt-4o")

async def main():
    # Connect to MCP server and create agent
    async with MultiServerMCPClient({
        "opensearch-mcp-server": {
            "transport": "sse",
            "url": "http://localhost:9900/sse",  # SSE server endpoint
            "headers": {
                "Authorization": "Bearer secret-token",
            }
        }
    }) as client:
        tools = client.get_tools()
        agent = initialize_agent(
            tools=tools,
            llm=model,
            agent=AgentType.OPENAI_FUNCTIONS,
            verbose=True,  # Enables detailed output of the agent's thought process
        )

        # Example query
        await agent.ainvoke({"input": "List all indices"})

if __name__ == "__main__":
    asyncio.run(main())

Notes:

  • The script is compatible with any LLM that integrates with LangChain and supports tool calling
  • Make sure the OpenSearch MCP server is running before executing the script
  • Configure authentication and environment variables as needed

Development

Interested in contributing? Check out our:

Metadata

Release files for opensearch-mcp-py 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opensearch-mcp-py 0.0.1
File Size Uploaded
opensearch_mcp_py-0.0.1.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opensearch-mcp-py 0.0.1
File Interpreter ABI Platform
opensearch_mcp_py-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.5 kB

Release files / opensearch_mcp_py-0.0.1.tar.gz

Download URL opensearch_mcp_py-0.0.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e5045db7f6fb0570532f7dd868c9fd39895146b3d8e2575f1cdfe7a85865af46
BLAKE2b-256 checksum
How to use checksums
ec29ac6e73ed5705cc4c7f56af5bd33da43db7bd8fe16120c6b27bb1afc2f004
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Release files / opensearch_mcp_py-0.0.1-py3-none-any.whl

Download URL opensearch_mcp_py-0.0.1-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f06dd4a6b4f67eb4f994840d53677575f3d2170b9f83d8759ca0bdbbcab25b90
BLAKE2b-256 checksum
How to use checksums
4bf3840feeb89cfac32ffb35cd32878713bc7480191133bcd05a74255c5b3534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page