Skip to content

Commit 12946ec

Browse files
authored
Fix Docker install and require the 'stdio' CLI parameter (#97)
* Require the stdio CLI parameter when running as a container. This is to future-proof the addition of the http protocol that will require the http parameter. * Refactor Docker file do make it build cache friendly * Fix OTel configuration so that it doesn't pollute stdout that's used to communicate with the client * Build a multi-arch (amd64 and arm64) using npm run build-docker-image * Update README and CONTRIBUTING to include instructions for the Docker image
1 parent bf0a04b commit 12946ec

File tree

8 files changed

+124
-323
lines changed

8 files changed

+124
-323
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
dist
22
node_modules
33
yarn.lock
4+
.env
5+
.idea
6+
.vscode

Dockerfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
# Copyright Elasticsearch B.V. and contributors
2+
# SPDX-License-Identifier: Apache-2.0
13
FROM cgr.dev/chainguard/wolfi-base:latest
24

35
RUN apk --no-cache add nodejs npm
46

57
WORKDIR /app
6-
COPY . ./
7-
RUN npm install && npm run build
88

9-
ENTRYPOINT ["npm", "start"]
9+
# Install dependencies (Docker build cache friendly)
10+
COPY package.json package-lock.json tsconfig.json ./
11+
RUN touch index.ts && npm install
12+
13+
COPY *.ts run-docker.sh ./
14+
RUN npm run build
15+
16+
# Future-proof the CLI and require the "stdio" argument
17+
ENV RUNNING_IN_CONTAINER="true"
18+
19+
ENTRYPOINT ["./run-docker.sh"]

README.md

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Elasticsearch MCP Server
22

3-
[![smithery badge](https://smithery.ai/badge/@elastic/mcp-server-elasticsearch)](https://smithery.ai/server/@elastic/mcp-server-elasticsearch)
4-
53
This repository contains experimental features intended for research and evaluation and are not production-ready.
64

75
Connect to your Elasticsearch data directly from any MCP Client (like Claude Desktop) using the Model Context Protocol (MCP).
@@ -23,6 +21,7 @@ This server connects agents to your Elasticsearch data using the Model Context P
2321

2422
* An Elasticsearch instance
2523
* Elasticsearch authentication credentials (API key or username/password)
24+
* Docker (or an OCI runtime)
2625
* MCP Client (e.g. Claude Desktop)
2726

2827
## Demo
@@ -31,18 +30,36 @@ This server connects agents to your Elasticsearch data using the Model Context P
3130

3231
## Installation & Setup
3332

34-
### Installing via Smithery
33+
### Using Docker
3534

36-
To install Elasticsearch MCP Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@elastic/mcp-server-elasticsearch):
35+
1. **Configure MCP Client**
36+
* Open your MCP Client. See the [list of MCP Clients](https://modelcontextprotocol.io/clients), here we are configuring Claude Desktop.
37+
* Go to **Settings > Developer > MCP Servers**
38+
* Click `Edit Config` and add a new MCP Server with the following configuration:
3739

38-
```bash
39-
npx -y @smithery/cli install @elastic/mcp-server-elasticsearch --client claude
40-
```
40+
```json
41+
{
42+
"mcpServers": {
43+
"elasticsearch-mcp-server": {
44+
"command": "docker",
45+
"args": [
46+
"run", "--rm", "-i",
47+
"-e", "ES_URL=<your-elasticsearch-url>",
48+
"-e", "ES_API_KEY=<your-api-key>",
49+
"docker.elastic.co/mcp/elasticsearch", "stdio"
50+
]
51+
}
52+
}
53+
}
54+
```
4155

42-
### Using the Published NPM Package
56+
2. **Start a Conversation**
57+
* Open a new conversation in your MCP Client
58+
* The MCP server should connect automatically
59+
* You can now ask questions about your Elasticsearch data
4360

44-
> [!TIP]
45-
> The easiest way to use Elasticsearch MCP Server is through the published npm package.
61+
62+
### Using the Published NPM Package
4663

4764
1. **Configure MCP Client**
4865
* Open your MCP Client. See the [list of MCP Clients](https://modelcontextprotocol.io/clients), here we are configuring Claude Desktop.
@@ -59,8 +76,9 @@ npx -y @smithery/cli install @elastic/mcp-server-elasticsearch --client claude
5976
"@elastic/mcp-server-elasticsearch"
6077
],
6178
"env": {
62-
"ES_URL": "your-elasticsearch-url",
63-
"ES_API_KEY": "your-api-key"
79+
"ES_URL": "<your-elasticsearch-url>",
80+
"ES_API_KEY": "<your-api-key>",
81+
"OTEL_LOG_LEVEL": "none"
6482
}
6583
}
6684
}
@@ -79,16 +97,16 @@ The Elasticsearch MCP Server supports configuration options to connect to your E
7997
> [!NOTE]
8098
> You must provide either an API key or both username and password for authentication.
8199
82-
| Environment Variable | Description | Required |
83-
|---------------------|-------------|----------|
84-
| `ES_URL` | Your Elasticsearch instance URL | Yes |
85-
| `ES_API_KEY` | Elasticsearch API key for authentication | No |
86-
| `ES_USERNAME` | Elasticsearch username for basic authentication | No |
87-
| `ES_PASSWORD` | Elasticsearch password for basic authentication | No |
88-
| `ES_CA_CERT` | Path to custom CA certificate for Elasticsearch SSL/TLS | No |
89-
| `ES_SSL_SKIP_VERIFY` | Set to '1' or 'true' to skip SSL certificate verification | No |
90-
| `ES_PATH_PREFIX` | Path prefix for Elasticsearch instance exposed at a non-root path | No |
91-
| `ES_VERSION` | Server assumes Elasticsearch 9.x. Set to `8` target Elasticsearch 8.x | No |
100+
| Environment Variable | Description | Required |
101+
|----------------------|-----------------------------------------------------------------------|----------|
102+
| `ES_URL` | Your Elasticsearch instance URL | Yes |
103+
| `ES_API_KEY` | Elasticsearch API key for authentication | No |
104+
| `ES_USERNAME` | Elasticsearch username for basic authentication | No |
105+
| `ES_PASSWORD` | Elasticsearch password for basic authentication | No |
106+
| `ES_CA_CERT` | Path to custom CA certificate for Elasticsearch SSL/TLS | No |
107+
| `ES_SSL_SKIP_VERIFY` | Set to '1' or 'true' to skip SSL certificate verification | No |
108+
| `ES_PATH_PREFIX` | Path prefix for Elasticsearch instance exposed at a non-root path | No |
109+
| `ES_VERSION` | Server assumes Elasticsearch 9.x. Set to `8` target Elasticsearch 8.x | No |
92110

93111
### Developing Locally
94112

@@ -150,23 +168,6 @@ The Elasticsearch MCP Server supports configuration options to connect to your E
150168
🔍 MCP Inspector is up and running at http://localhost:5173 🚀
151169
```
152170

153-
#### Docker image
154-
155-
A `Dockerfile` is available if you would like to build and run the server in a container. To build, run:
156-
157-
```sh
158-
docker build -t mcp-server-elasticsearch .
159-
```
160-
161-
And to run, rather than using the `npx` command above or a custom `node` or `npm` command, run:
162-
163-
```sh
164-
docker run -i \
165-
-e ES_URL=<url> \
166-
-e ES_API_KEY=<key> \
167-
mcp-server-elasticsearch
168-
```
169-
170171
## Contributing
171172

172173
We welcome contributions from the community! For details on how to contribute, please see [Contributing Guidelines](/docs/CONTRIBUTING.md).

docs/CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ Please note that this project follows the [Elastic's Open Source Community Code
2828
npm run build
2929
```
3030

31+
To build the Docker image, run:
32+
33+
```sh
34+
npm run build-docker-image
35+
```
36+
37+
This builds a multi-architecture image for amd64 and arm64. If you don't have a configuration that allows multi-architecture builds, simply run `docker build -t mcp/elasticsearch` .
38+
3139
## Start Elasticsearch
3240

3341
You can use either:

index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env node
2-
31
/*
42
* Copyright Elasticsearch B.V. and contributors
53
* SPDX-License-Identifier: Apache-2.0
@@ -502,6 +500,16 @@ const config: ElasticsearchConfig = {
502500
}
503501

504502
async function main (): Promise<void> {
503+
// If we're running in a container (see Dockerfile), future-proof the command-line
504+
// by requiring the stdio protocol (http will come later)
505+
if (process.env.RUNNING_IN_CONTAINER === "true") {
506+
if (process.argv.length != 3 || process.argv[2] !== "stdio" ) {
507+
console.log("Missing protocol argument.");
508+
console.log("Usage: npm start stdio");
509+
process.exit(1);
510+
}
511+
}
512+
505513
const transport = new StdioServerTransport()
506514
const server = await createElasticsearchMcpServer(config)
507515

0 commit comments

Comments
 (0)