From a50baf09af60f42c8cde6513166ea4237c4621ff Mon Sep 17 00:00:00 2001 From: Werner Robitza Date: Wed, 4 Jun 2025 21:31:58 +0200 Subject: [PATCH 1/2] feat: add option to skip SSL verification --- README.md | 1 + index.ts | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9df4a5a..f0edeea 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ The Elasticsearch MCP Server supports configuration options to connect to your E | `ES_USERNAME` | Elasticsearch username for basic authentication | No | | `ES_PASSWORD` | Elasticsearch password for basic authentication | No | | `ES_CA_CERT` | Path to custom CA certificate for Elasticsearch SSL/TLS | No | +| `ES_SSL_SKIP_VERIFY` | Set to '1' or 'true' to skip SSL certificate verification | No | | `ES_PATH_PREFIX` | Path prefix for Elasticsearch instance exposed at a non-root path | No | diff --git a/index.ts b/index.ts index 94ec3c1..1d3b86c 100644 --- a/index.ts +++ b/index.ts @@ -65,7 +65,12 @@ const ConfigSchema = z .string() .optional() .describe("Path to custom CA certificate for Elasticsearch"), - + + sslSkipVerify: z + .boolean() + .optional() + .describe("Skip SSL certificate verification"), + pathPrefix: z .string() .optional() @@ -104,7 +109,7 @@ export async function createElasticsearchMcpServer( config: ElasticsearchConfig ) { const validatedConfig = ConfigSchema.parse(config); - const { url, apiKey, username, password, caCert, pathPrefix } = validatedConfig; + const { url, apiKey, username, password, caCert, sslSkipVerify, pathPrefix } = validatedConfig; const clientOptions: ClientOptions = { node: url, @@ -127,10 +132,11 @@ export async function createElasticsearchMcpServer( } // Set up SSL/TLS certificate if provided + clientOptions.tls = {}; if (caCert) { try { const ca = fs.readFileSync(caCert); - clientOptions.tls = { ca }; + clientOptions.tls.ca = ca; } catch (error) { console.error( `Failed to read certificate file: ${ @@ -140,6 +146,11 @@ export async function createElasticsearchMcpServer( } } + // Skip verification if requested + if (sslSkipVerify) { + clientOptions.tls.rejectUnauthorized = false; + } + const esClient = new Client(clientOptions); const server = new McpServer({ @@ -456,6 +467,7 @@ const config: ElasticsearchConfig = { username: process.env.ES_USERNAME || "", password: process.env.ES_PASSWORD || "", caCert: process.env.ES_CA_CERT || "", + sslSkipVerify: process.env.ES_SSL_SKIP_VERIFY === "1" || process.env.ES_SSL_SKIP_VERIFY === "true", pathPrefix: process.env.ES_PATH_PREFIX || "", }; From 96d2886f67f44ca97d5cfc86e54fd1f00df128ec Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Thu, 12 Jun 2025 12:50:02 -0500 Subject: [PATCH 2/2] Update index.ts --- index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index b9972a2..644ac0e 100644 --- a/index.ts +++ b/index.ts @@ -400,8 +400,18 @@ export async function createElasticsearchMcpServer( }, showing ${result.hits.hits.length} from position ${from}`, }; + // Check if there are any aggregations in the result and include them + const aggregationsFragment = result.aggregations + ? { + type: "text" as const, + text: `Aggregations: ${JSON.stringify(result.aggregations, null, 2)}`, + } + : null; + return { - content: [metadataFragment, ...contentFragments], + content: aggregationsFragment + ? [metadataFragment, aggregationsFragment, ...contentFragments] + : [metadataFragment, ...contentFragments], }; } catch (error) { console.error( @@ -519,4 +529,4 @@ main().catch((error) => { error instanceof Error ? error.message : String(error) ); process.exit(1); -}); \ No newline at end of file +});