Skip to content

Commit 4ada9b1

Browse files
committed
[Example app] Elasticsearch MCP server
1 parent d30b609 commit 4ada9b1

File tree

6 files changed

+470
-0
lines changed

6 files changed

+470
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.12.0
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Elasticsearch MCP Server
2+
3+
Connect to your Elasticsearch data directly from any MCP Client (like Claude Desktop) using the Model Context Protocol (MCP).
4+
5+
This server connects agents to your Elasticsearch data using the Model Context Protocol (MCP). It allows you to interact with your Elasticsearch indices through natural language conversations.
6+
7+
## Features
8+
9+
- **List Indices**: View all available Elasticsearch indices
10+
- **Get Mappings**: Inspect field mappings for specific indices
11+
- **Search**: Execute Elasticsearch queries using full Query DSL capabilities with automatic highlighting
12+
13+
## Prerequisites
14+
15+
- Node.js (v22+)
16+
- An Elasticsearch instance
17+
- Elasticsearch API key with appropriate permissions
18+
- Claude Desktop App (free version is sufficient)
19+
20+
## Setup Guide
21+
22+
Make sure you use a supported Node.js version:
23+
24+
```
25+
nvm use
26+
```
27+
28+
### 1. Install Dependencies
29+
30+
```bash
31+
npm install
32+
```
33+
34+
### 2. Build the Project
35+
36+
```bash
37+
npm run build
38+
```
39+
40+
41+
### 3. Configure Claude Desktop App
42+
43+
1. Open Claude Desktop App
44+
2. Go to Settings > Developer > MCP Servers
45+
3. Click `Edit Config` and add a new MCP Server with the following configuration to your `claude_desktop_config.json`:
46+
47+
```json
48+
{
49+
"mcpServers": {
50+
"Elasticsearch MCP Server": {
51+
"command": "npx",
52+
"args": [
53+
"-y",
54+
"node@22",
55+
"/path/to/your/project/dist/index.js"
56+
],
57+
"env": {
58+
"ES_URL": "...",
59+
"ES_API_KEY": "..."
60+
}
61+
}
62+
}
63+
}
64+
```
65+
66+
Replace `/path/to/your/elasticsearch-mcp/dist/index.js` with the actual path to the built JavaScript file, and fill in your Elasticsearch URL and API key.
67+
68+
### 4. Start a Conversation
69+
70+
1. Open a new conversation in Claude Desktop App
71+
2. The MCP server should connect automatically
72+
3. You can now ask Claude questions about your Elasticsearch data
73+
74+
## Example Questions
75+
76+
- "What indices do I have in my Elasticsearch cluster?"
77+
- "Show me the field mappings for the 'products' index"
78+
- "Find all orders over $500 from last month"
79+
- "Which products received the most 5-star reviews?"
80+
81+
## How It Works
82+
83+
When you ask Claude a question about your data:
84+
85+
1. Claude analyzes your request and determines which Elasticsearch operations are needed
86+
2. The MCP server carries out these operations (listing indices, fetching mappings, performing searches)
87+
3. Claude processes the results and presents them in a user-friendly format
88+
89+
## Troubleshooting
90+
91+
- If the server isn't connecting, check that the path in your MCP configuration is correct
92+
- Ensure your Elasticsearch URL is accessible from your machine
93+
- Verify that your API key has the necessary permissions
94+
- Check the terminal output for any error messages
95+
96+
You can also use the inspector tool to debug your MCP server:
97+
98+
```bash
99+
npm run inspector
100+
```
101+
102+
## Security Best Practices
103+
104+
You can create a dedicated Elasticsearch API key with minimal permissions for Claude's access to your data:
105+
106+
```
107+
POST /_security/api_key
108+
{
109+
"name": "claude-mcp-access",
110+
"role_descriptors": {
111+
"claude_role": {
112+
"cluster": ["monitor"],
113+
"indices": [
114+
{
115+
"names": ["index-1", "index-2", "index-pattern-*"],
116+
"privileges": ["read", "view_index_metadata"]
117+
}
118+
]
119+
}
120+
}
121+
}
122+
```

0 commit comments

Comments
 (0)