Skip to content

Commit b735ae0

Browse files
committed
format by deno
1 parent b3d1f29 commit b735ae0

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

index.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import morgan from "morgan";
1010
import { z } from "zod";
1111
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1212
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
13-
import { Client, estypes, ClientOptions } from "@elastic/elasticsearch";
13+
import { Client, ClientOptions, estypes } from "@elastic/elasticsearch";
1414
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
1515
import fs from "fs";
1616

@@ -74,13 +74,13 @@ const ConfigSchema = z
7474
message:
7575
"Either ES_API_KEY or both ES_USERNAME and ES_PASSWORD must be provided, or no auth for local development",
7676
path: ["username", "password"],
77-
}
77+
},
7878
);
7979

8080
type ElasticsearchConfig = z.infer<typeof ConfigSchema>;
8181

8282
export async function createElasticsearchMcpServer(
83-
config: ElasticsearchConfig
83+
config: ElasticsearchConfig,
8484
) {
8585
const validatedConfig = ConfigSchema.parse(config);
8686
const { url, apiKey, username, password, caCert } = validatedConfig;
@@ -105,7 +105,7 @@ export async function createElasticsearchMcpServer(
105105
console.error(
106106
`Failed to read certificate file: ${
107107
error instanceof Error ? error.message : String(error)
108-
}`
108+
}`,
109109
);
110110
}
111111
}
@@ -149,7 +149,7 @@ export async function createElasticsearchMcpServer(
149149
console.error(
150150
`Failed to list indices: ${
151151
error instanceof Error ? error.message : String(error)
152-
}`
152+
}`,
153153
);
154154
return {
155155
content: [
@@ -162,7 +162,7 @@ export async function createElasticsearchMcpServer(
162162
],
163163
};
164164
}
165-
}
165+
},
166166
);
167167

168168
// Tool 2: Get mappings for an index
@@ -190,19 +190,21 @@ export async function createElasticsearchMcpServer(
190190
},
191191
{
192192
type: "text" as const,
193-
text: `Mappings for index ${index}: ${JSON.stringify(
194-
mappingResponse[index]?.mappings || {},
195-
null,
196-
2
197-
)}`,
193+
text: `Mappings for index ${index}: ${
194+
JSON.stringify(
195+
mappingResponse[index]?.mappings || {},
196+
null,
197+
2,
198+
)
199+
}`,
198200
},
199201
],
200202
};
201203
} catch (error) {
202204
console.error(
203205
`Failed to get mappings: ${
204206
error instanceof Error ? error.message : String(error)
205-
}`
207+
}`,
206208
);
207209
return {
208210
content: [
@@ -215,7 +217,7 @@ export async function createElasticsearchMcpServer(
215217
],
216218
};
217219
}
218-
}
220+
},
219221
);
220222

221223
// Tool 3: Search an index with simplified parameters
@@ -242,10 +244,10 @@ export async function createElasticsearchMcpServer(
242244
},
243245
{
244246
message: "queryBody must be a valid Elasticsearch query DSL object",
245-
}
247+
},
246248
)
247249
.describe(
248-
"Complete Elasticsearch query DSL object that can include query, size, from, sort, etc."
250+
"Complete Elasticsearch query DSL object that can include query, size, from, sort, etc.",
249251
),
250252
},
251253
async ({ index, queryBody }) => {
@@ -266,9 +268,11 @@ export async function createElasticsearchMcpServer(
266268
if (indexMappings.properties) {
267269
const textFields: Record<string, estypes.SearchHighlightField> = {};
268270

269-
for (const [fieldName, fieldData] of Object.entries(
270-
indexMappings.properties
271-
)) {
271+
for (
272+
const [fieldName, fieldData] of Object.entries(
273+
indexMappings.properties,
274+
)
275+
) {
272276
if (fieldData.type === "text" || "dense_vector" in fieldData) {
273277
textFields[fieldName] = {};
274278
}
@@ -294,9 +298,11 @@ export async function createElasticsearchMcpServer(
294298

295299
for (const [field, highlights] of Object.entries(highlightedFields)) {
296300
if (highlights && highlights.length > 0) {
297-
content += `${field} (highlighted): ${highlights.join(
298-
" ... "
299-
)}\n`;
301+
content += `${field} (highlighted): ${
302+
highlights.join(
303+
" ... ",
304+
)
305+
}\n`;
300306
}
301307
}
302308

@@ -328,7 +334,7 @@ export async function createElasticsearchMcpServer(
328334
console.error(
329335
`Search failed: ${
330336
error instanceof Error ? error.message : String(error)
331-
}`
337+
}`,
332338
);
333339
return {
334340
content: [
@@ -341,7 +347,7 @@ export async function createElasticsearchMcpServer(
341347
],
342348
};
343349
}
344-
}
350+
},
345351
);
346352

347353
// Tool 4: Get shard information
@@ -392,7 +398,7 @@ export async function createElasticsearchMcpServer(
392398
console.error(
393399
`Failed to get shard information: ${
394400
error instanceof Error ? error.message : String(error)
395-
}`
401+
}`,
396402
);
397403
return {
398404
content: [
@@ -405,7 +411,7 @@ export async function createElasticsearchMcpServer(
405411
],
406412
};
407413
}
408-
}
414+
},
409415
);
410416

411417
return server;
@@ -426,10 +432,10 @@ async function create_sse_server(server: any) {
426432
// Use morgan to log every request
427433
app.use(morgan("combined"));
428434

429-
const transports: {[sessionId: string]: SSEServerTransport} = {};
435+
const transports: { [sessionId: string]: SSEServerTransport } = {};
430436

431437
app.get("/sse", async (_: Request, res: Response) => {
432-
const transport = new SSEServerTransport('/messages', res);
438+
const transport = new SSEServerTransport("/messages", res);
433439
transports[transport.sessionId] = transport;
434440
res.on("close", () => {
435441
delete transports[transport.sessionId];
@@ -443,7 +449,7 @@ async function create_sse_server(server: any) {
443449
if (transport) {
444450
await transport.handlePostMessage(req, res);
445451
} else {
446-
res.status(400).send('No transport found for sessionId');
452+
res.status(400).send("No transport found for sessionId");
447453
}
448454
});
449455

@@ -479,7 +485,7 @@ async function main() {
479485
main().catch((error) => {
480486
console.error(
481487
"Server error:",
482-
error instanceof Error ? error.message : String(error)
488+
error instanceof Error ? error.message : String(error),
483489
);
484490
process.exit(1);
485491
});

0 commit comments

Comments
 (0)