You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An Elasticsearch MCP (Model Context Protocol) server built on [github.com/mark3labs/mcp-go](https://github.com/mark3labs/mcp-go), providing seamless integration with Elasticsearch 7, 8, and 9 versions.
7
+
An Elasticsearch MCP (Model Context Protocol) server built on [github.com/modelcontextprotocol/go-sdk](https://github.com/modelcontextprotocol/go-sdk), providing seamless integration with Elasticsearch 7, 8, and 9 versions.
8
8
9
9
## Features
10
10
11
-
- 🔗 **Multi-Protocol Support**: Supports both stdio and Streamable HTTPprotocols
- ⚠️ **Warning**: Deprecated, use HTTP protocol instead
214
+
115
215
## Usage Examples
116
216
117
-
### Stdio Mode (Default)
217
+
### Stdio Mode (Default for native builds)
118
218
```bash
119
219
export ES_ADDRESSES=http://localhost:9200
120
220
export MCP_PROTOCOL=stdio
121
221
./mcp-elasticsearch
122
222
```
123
223
124
-
### Streamable HTTP Mode
224
+
### Streamable HTTP Mode (Default for Docker)
125
225
```bash
126
226
export ES_ADDRESSES=http://localhost:9200
127
227
export MCP_PROTOCOL=http
128
228
export MCP_PORT=8080
129
229
./mcp-elasticsearch
130
230
```
131
231
232
+
### SSE Mode (Deprecated - Not Recommended)
233
+
⚠️ **WARNING**: SSE protocol is deprecated and not recommended for production use. Use Streamable HTTP instead.
234
+
235
+
```bash
236
+
export ES_ADDRESSES=http://localhost:9200
237
+
export MCP_PROTOCOL=sse
238
+
export MCP_PORT=8080
239
+
./mcp-elasticsearch
240
+
```
241
+
132
242
### Using with Elastic Cloud
133
243
```bash
134
244
export ES_CLOUD_ID=your_cloud_id
@@ -138,12 +248,12 @@ export ES_VERSION=8
138
248
./mcp-elasticsearch
139
249
```
140
250
141
-
142
251
## Development
143
252
144
253
### Prerequisites
145
-
- Go 1.21 or higher
254
+
- Go 1.23 or higher
146
255
- Access to an Elasticsearch cluster
256
+
- Docker (optional, for containerized development)
147
257
148
258
### Building
149
259
```bash
@@ -156,6 +266,11 @@ go build -o mcp-elasticsearch main.go
156
266
go test ./...
157
267
```
158
268
269
+
### Building Docker Image
270
+
```bash
271
+
docker build -t mcp-elasticsearch .
272
+
```
273
+
159
274
## Tool Usage Examples
160
275
161
276
### Get Cluster Information
@@ -193,7 +308,7 @@ go test ./...
193
308
"arguments": {
194
309
"index": "my-index",
195
310
"id": "doc1",
196
-
"document": {
311
+
"body": {
197
312
"title": "Hello World",
198
313
"content": "This is a test document",
199
314
"timestamp": "2024-01-01T00:00:00Z"
@@ -202,26 +317,74 @@ go test ./...
202
317
}
203
318
```
204
319
205
-
### Search Documents
320
+
### Advanced Search with Sorting and Field Selection
206
321
```json
207
322
{
208
323
"tool": "es_search",
209
324
"arguments": {
210
325
"index": "my-index",
211
326
"query": {
212
-
"match": {
213
-
"title": "Hello"
327
+
"bool": {
328
+
"must": [
329
+
{"match": {"title": "Hello"}}
330
+
],
331
+
"filter": [
332
+
{"range": {"timestamp": {"gte": "2024-01-01"}}}
333
+
]
214
334
}
215
335
},
216
-
"size": 10
336
+
"sort": [
337
+
{"timestamp": {"order": "desc"}},
338
+
{"_score": {"order": "desc"}}
339
+
],
340
+
"_source": ["title", "content", "timestamp"],
341
+
"size": 20,
342
+
"from": 0
217
343
}
218
344
}
219
345
```
220
346
347
+
## Health Monitoring
348
+
349
+
When running in HTTP mode, the server provides multiple endpoints:
350
+
351
+
### Health Check Endpoint
352
+
```bash
353
+
# Check server health (publicly accessible)
354
+
curl http://localhost:8080/health
355
+
356
+
# Response
357
+
{"status":"healthy","server":"elasticsearch-mcp"}
358
+
```
359
+
360
+
### MCP Protocol Endpoint
361
+
```bash
362
+
# MCP communication endpoint (requires MCP client)
363
+
# URL: http://localhost:8080/mcp
364
+
# This endpoint handles MCP protocol messages and tool calls
365
+
# Not directly accessible via simple HTTP GET requests
366
+
```
367
+
368
+
### Important Notes
369
+
- **Health endpoint** (`/health`): Simple HTTP GET for monitoring
370
+
- **MCP endpoint** (`/mcp`): For MCP protocol communication only
371
+
- **SSE endpoint** (`/sse`): Deprecated, avoid using
372
+
221
373
## Error Handling
222
374
223
375
All errors are reported within the MCP tool results with `isError: true`, allowing LLMs to see and handle errors appropriately. Protocol-level errors are reserved for exceptional conditions like missing tools or server failures.
224
376
377
+
## Troubleshooting
378
+
379
+
### Container Issues
380
+
- **Container exits immediately**: Ensure you're using HTTP protocol for Docker containers
381
+
- **Cannot connect to Elasticsearch**: Use `host.docker.internal:9200` instead of `localhost:9200` in Docker
382
+
- **Permission denied**: Check Docker daemon permissions and image access
383
+
384
+
### Network Issues
385
+
- **Connection refused**: Verify Elasticsearch is running and accessible
386
+
- **SSL errors**: Set `ES_INSECURE_SKIP_VERIFY=true` for testing with self-signed certificates
387
+
225
388
## Contributing
226
389
227
390
1. Fork the repository
@@ -234,9 +397,12 @@ All errors are reported within the MCP tool results with `isError: true`, allowi
234
397
235
398
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
236
399
237
-
238
400
## Acknowledgments
239
401
240
-
-[Mark3Labs MCP-Go](https://github.com/mark3labs/mcp-go) - MCP implementation for Go
402
+
- [Official MCP Go SDK](https://github.com/modelcontextprotocol/go-sdk) - Official MCP implementation for Go
241
403
- [Elastic](https://github.com/elastic/go-elasticsearch) - Official Elasticsearch Go client
0 commit comments