Skip to content

Commit 8a7b94e

Browse files
committed
feat: allow es8 server version
#50
1 parent 3139229 commit 8a7b94e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

index.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const ConfigSchema = z
4040
.string()
4141
.optional()
4242
.describe("Path to custom CA certificate for Elasticsearch"),
43+
44+
version: z
45+
.string()
46+
.optional()
47+
.transform((val) => (["8", "9"].includes(val || "") ? val : "9"))
48+
.describe("Elasticsearch version (8, or 9)"),
4349
})
4450
.refine(
4551
(data) => {
@@ -74,7 +80,7 @@ export async function createElasticsearchMcpServer(
7480
config: ElasticsearchConfig
7581
) {
7682
const validatedConfig = ConfigSchema.parse(config);
77-
const { url, apiKey, username, password, caCert } = validatedConfig;
83+
const { url, apiKey, username, password, caCert, version } = validatedConfig;
7884

7985
const clientOptions: ClientOptions = {
8086
node: url,
@@ -101,6 +107,16 @@ export async function createElasticsearchMcpServer(
101107
}
102108
}
103109

110+
// Add version-specific configuration
111+
if (version === "8") {
112+
clientOptions.maxRetries = 5;
113+
clientOptions.requestTimeout = 30000;
114+
clientOptions.headers = {
115+
accept: "application/vnd.elasticsearch+json;compatible-with=8",
116+
"content-type": "application/vnd.elasticsearch+json;compatible-with=8",
117+
};
118+
}
119+
104120
const esClient = new Client(clientOptions);
105121

106122
const server = new McpServer({
@@ -119,11 +135,11 @@ export async function createElasticsearchMcpServer(
119135
.min(1, "Index pattern is required")
120136
.describe("Index pattern of Elasticsearch indices to list"),
121137
},
122-
async ( {indexPattern} ) => {
138+
async ({ indexPattern }) => {
123139
try {
124-
const response = await esClient.cat.indices({
125-
index: indexPattern,
126-
format: "json"
140+
const response = await esClient.cat.indices({
141+
index: indexPattern,
142+
format: "json",
127143
});
128144

129145
const indicesInfo = response.map((index) => ({
@@ -417,6 +433,7 @@ const config: ElasticsearchConfig = {
417433
username: process.env.ES_USERNAME || "",
418434
password: process.env.ES_PASSWORD || "",
419435
caCert: process.env.ES_CA_CERT || "",
436+
version: process.env.ES_VERSION || "",
420437
};
421438

422439
async function main() {

0 commit comments

Comments
 (0)