Skip to content

Commit a50baf0

Browse files
committed
feat: add option to skip SSL verification
1 parent f927d72 commit a50baf0

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ The Elasticsearch MCP Server supports configuration options to connect to your E
7777
| `ES_USERNAME` | Elasticsearch username for basic authentication | No |
7878
| `ES_PASSWORD` | Elasticsearch password for basic authentication | No |
7979
| `ES_CA_CERT` | Path to custom CA certificate for Elasticsearch SSL/TLS | No |
80+
| `ES_SSL_SKIP_VERIFY` | Set to '1' or 'true' to skip SSL certificate verification | No |
8081
| `ES_PATH_PREFIX` | Path prefix for Elasticsearch instance exposed at a non-root path | No |
8182

8283

index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ const ConfigSchema = z
6565
.string()
6666
.optional()
6767
.describe("Path to custom CA certificate for Elasticsearch"),
68-
68+
69+
sslSkipVerify: z
70+
.boolean()
71+
.optional()
72+
.describe("Skip SSL certificate verification"),
73+
6974
pathPrefix: z
7075
.string()
7176
.optional()
@@ -104,7 +109,7 @@ export async function createElasticsearchMcpServer(
104109
config: ElasticsearchConfig
105110
) {
106111
const validatedConfig = ConfigSchema.parse(config);
107-
const { url, apiKey, username, password, caCert, pathPrefix } = validatedConfig;
112+
const { url, apiKey, username, password, caCert, sslSkipVerify, pathPrefix } = validatedConfig;
108113

109114
const clientOptions: ClientOptions = {
110115
node: url,
@@ -127,10 +132,11 @@ export async function createElasticsearchMcpServer(
127132
}
128133

129134
// Set up SSL/TLS certificate if provided
135+
clientOptions.tls = {};
130136
if (caCert) {
131137
try {
132138
const ca = fs.readFileSync(caCert);
133-
clientOptions.tls = { ca };
139+
clientOptions.tls.ca = ca;
134140
} catch (error) {
135141
console.error(
136142
`Failed to read certificate file: ${
@@ -140,6 +146,11 @@ export async function createElasticsearchMcpServer(
140146
}
141147
}
142148

149+
// Skip verification if requested
150+
if (sslSkipVerify) {
151+
clientOptions.tls.rejectUnauthorized = false;
152+
}
153+
143154
const esClient = new Client(clientOptions);
144155

145156
const server = new McpServer({
@@ -456,6 +467,7 @@ const config: ElasticsearchConfig = {
456467
username: process.env.ES_USERNAME || "",
457468
password: process.env.ES_PASSWORD || "",
458469
caCert: process.env.ES_CA_CERT || "",
470+
sslSkipVerify: process.env.ES_SSL_SKIP_VERIFY === "1" || process.env.ES_SSL_SKIP_VERIFY === "true",
459471
pathPrefix: process.env.ES_PATH_PREFIX || "",
460472
};
461473

0 commit comments

Comments
 (0)