mcp-meilisearch 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -49
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -100
- package/dist/plugin.d.ts +49 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +96 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -68
- package/dist/standalone.d.ts +2 -2
- package/dist/standalone.d.ts.map +1 -1
- package/dist/standalone.js +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,50 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Options for the MCP Vite plugin
|
|
4
|
-
*/
|
|
5
|
-
export interface MCPPluginOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The URL of the Meilisearch instance
|
|
8
|
-
* @required
|
|
9
|
-
* @example "http://localhost:7700"
|
|
10
|
-
*/
|
|
11
|
-
meilisearchHost: string;
|
|
12
|
-
/**
|
|
13
|
-
* The API key for authenticating with Meilisearch
|
|
14
|
-
* @required
|
|
15
|
-
*/
|
|
16
|
-
meilisearchApiKey: string;
|
|
17
|
-
/**
|
|
18
|
-
* Transport type for MCP server ("http" | "stdio")
|
|
19
|
-
* @default "http"
|
|
20
|
-
*/
|
|
21
|
-
transport?: "http" | "stdio";
|
|
22
|
-
/**
|
|
23
|
-
* HTTP port for MCP server
|
|
24
|
-
* @default 8080
|
|
25
|
-
*/
|
|
26
|
-
httpPort?: number;
|
|
27
|
-
/**
|
|
28
|
-
* MCP endpoint path
|
|
29
|
-
* @default "/mcp"
|
|
30
|
-
*/
|
|
31
|
-
mcpEndpoint?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Session timeout in milliseconds
|
|
34
|
-
* @default 3600000 (1 hour)
|
|
35
|
-
*/
|
|
36
|
-
sessionTimeout?: number;
|
|
37
|
-
/**
|
|
38
|
-
* Session cleanup interval in milliseconds
|
|
39
|
-
* @default 60000 (1 minute)
|
|
40
|
-
*/
|
|
41
|
-
sessionCleanupInterval?: number;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Creates a Vite plugin that integrates with the MCP server
|
|
45
|
-
* @param options Configuration options for the MCP server
|
|
46
|
-
* @returns A Vite plugin
|
|
47
|
-
*/
|
|
48
|
-
export declare function mcpPlugin(options?: MCPPluginOptions): Plugin;
|
|
49
|
-
export default mcpPlugin;
|
|
1
|
+
export { mcpPlugin } from "./plugin.js";
|
|
2
|
+
export { mcpStandalone } from "./standalone.js";
|
|
50
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,100 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { configHandler } from "./utils/config-handler.js";
|
|
4
|
-
import { createErrorResponse } from "./utils/error-handler.js";
|
|
5
|
-
/**
|
|
6
|
-
* Creates a Vite plugin that integrates with the MCP server
|
|
7
|
-
* @param options Configuration options for the MCP server
|
|
8
|
-
* @returns A Vite plugin
|
|
9
|
-
*/
|
|
10
|
-
export function mcpPlugin(options = {
|
|
11
|
-
meilisearchApiKey: "",
|
|
12
|
-
meilisearchHost: "http://localhost:7700",
|
|
13
|
-
}) {
|
|
14
|
-
configHandler.setMeilisearchHost(options.meilisearchHost);
|
|
15
|
-
configHandler.setMeilisearchApiKey(options.meilisearchApiKey);
|
|
16
|
-
const pluginId = `mcp-plugin-${randomUUID().slice(0, 8)}`;
|
|
17
|
-
let mcpServerInstance = null;
|
|
18
|
-
const transport = options.transport || "http";
|
|
19
|
-
return {
|
|
20
|
-
name: "vite:mcp-plugin",
|
|
21
|
-
configureServer(server) {
|
|
22
|
-
server.config.env.VITE_MCP_PLUGIN_ID = pluginId;
|
|
23
|
-
server.middlewares.use((req, res, next) => {
|
|
24
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
25
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
26
|
-
res.setHeader("Access-Control-Allow-Headers", `Origin, X-Requested-With, Content-Type, Accept, mcp-session-id`);
|
|
27
|
-
if (req.method === "OPTIONS") {
|
|
28
|
-
res.statusCode = 200;
|
|
29
|
-
res.end();
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
next();
|
|
33
|
-
});
|
|
34
|
-
server.middlewares.use(async (req, res, next) => {
|
|
35
|
-
const mcpEndpoint = options.mcpEndpoint || "/mcp";
|
|
36
|
-
const url = req.url || "/";
|
|
37
|
-
if (url.startsWith(mcpEndpoint)) {
|
|
38
|
-
if (!mcpServerInstance) {
|
|
39
|
-
console.error("MCP server not initialized yet");
|
|
40
|
-
res.statusCode = 503;
|
|
41
|
-
res.setHeader("Content-Type", "application/json");
|
|
42
|
-
res.end(JSON.stringify(createErrorResponse("MCP server not initialized yet")));
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (req.method === "GET") {
|
|
46
|
-
await mcpServerInstance.handleGetRequest(req, res);
|
|
47
|
-
}
|
|
48
|
-
else if (req.method === "POST") {
|
|
49
|
-
let body = "";
|
|
50
|
-
req.on("data", (chunk) => {
|
|
51
|
-
body += chunk.toString();
|
|
52
|
-
});
|
|
53
|
-
req.on("end", async () => {
|
|
54
|
-
try {
|
|
55
|
-
const jsonBody = JSON.parse(body);
|
|
56
|
-
await mcpServerInstance.handlePostRequest(req, res, jsonBody);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
console.error("Error parsing request body:", error);
|
|
60
|
-
res.statusCode = 400;
|
|
61
|
-
res.end(JSON.stringify(createErrorResponse("Invalid JSON body")));
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
next();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
next();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
// Start the MCP server when Vite server is ready
|
|
74
|
-
server.httpServer?.on("listening", async () => {
|
|
75
|
-
console.log(`Vite server is ready, initializing MCP server with ${transport} transport`);
|
|
76
|
-
try {
|
|
77
|
-
const serverInstances = await initServer(transport, options);
|
|
78
|
-
mcpServerInstance = serverInstances.mcpServer;
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
console.error("Failed to initialize MCP server:", error);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
closeBundle() {
|
|
86
|
-
if (mcpServerInstance) {
|
|
87
|
-
try {
|
|
88
|
-
console.log("Shutting down MCP server...");
|
|
89
|
-
if (typeof mcpServerInstance.shutdown === "function") {
|
|
90
|
-
mcpServerInstance.shutdown();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
console.error("Error shutting down MCP server:", error);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
export default mcpPlugin;
|
|
1
|
+
export { mcpPlugin } from "./plugin.js";
|
|
2
|
+
export { mcpStandalone } from "./standalone.js";
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the MCP Vite plugin
|
|
4
|
+
*/
|
|
5
|
+
export interface MCPPluginOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The URL of the Meilisearch instance
|
|
8
|
+
* @required
|
|
9
|
+
* @example "http://localhost:7700"
|
|
10
|
+
*/
|
|
11
|
+
meilisearchHost: string;
|
|
12
|
+
/**
|
|
13
|
+
* The API key for authenticating with Meilisearch
|
|
14
|
+
* @required
|
|
15
|
+
*/
|
|
16
|
+
meilisearchApiKey: string;
|
|
17
|
+
/**
|
|
18
|
+
* Transport type for MCP server ("http" | "stdio")
|
|
19
|
+
* @default "http"
|
|
20
|
+
*/
|
|
21
|
+
transport?: "http" | "stdio";
|
|
22
|
+
/**
|
|
23
|
+
* HTTP port for MCP server
|
|
24
|
+
* @default 8080
|
|
25
|
+
*/
|
|
26
|
+
httpPort?: number;
|
|
27
|
+
/**
|
|
28
|
+
* MCP endpoint path
|
|
29
|
+
* @default "/mcp"
|
|
30
|
+
*/
|
|
31
|
+
mcpEndpoint?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Session timeout in milliseconds
|
|
34
|
+
* @default 3600000 (1 hour)
|
|
35
|
+
*/
|
|
36
|
+
sessionTimeout?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Session cleanup interval in milliseconds
|
|
39
|
+
* @default 60000 (1 minute)
|
|
40
|
+
*/
|
|
41
|
+
sessionCleanupInterval?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a Vite plugin that integrates with the MCP server
|
|
45
|
+
* @param options Configuration options for the MCP server
|
|
46
|
+
* @returns A Vite plugin
|
|
47
|
+
*/
|
|
48
|
+
export declare function mcpPlugin(options?: MCPPluginOptions): Plugin;
|
|
49
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAK9B;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,OAAO,GAAE,gBAGR,GACA,MAAM,CAoGR"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { initServer } from "./server.js";
|
|
2
|
+
import { configHandler } from "./utils/config-handler.js";
|
|
3
|
+
import { createErrorResponse } from "./utils/error-handler.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Vite plugin that integrates with the MCP server
|
|
6
|
+
* @param options Configuration options for the MCP server
|
|
7
|
+
* @returns A Vite plugin
|
|
8
|
+
*/
|
|
9
|
+
export function mcpPlugin(options = {
|
|
10
|
+
meilisearchApiKey: "",
|
|
11
|
+
meilisearchHost: "http://localhost:7700",
|
|
12
|
+
}) {
|
|
13
|
+
configHandler.setMeilisearchHost(options.meilisearchHost);
|
|
14
|
+
configHandler.setMeilisearchApiKey(options.meilisearchApiKey);
|
|
15
|
+
let mcpServerInstance = null;
|
|
16
|
+
const transport = options.transport || "http";
|
|
17
|
+
return {
|
|
18
|
+
name: "vite:mcp-plugin",
|
|
19
|
+
configureServer(server) {
|
|
20
|
+
server.middlewares.use((req, res, next) => {
|
|
21
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
22
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
23
|
+
res.setHeader("Access-Control-Allow-Headers", `Origin, X-Requested-With, Content-Type, Accept, mcp-session-id`);
|
|
24
|
+
if (req.method === "OPTIONS") {
|
|
25
|
+
res.statusCode = 200;
|
|
26
|
+
res.end();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
next();
|
|
30
|
+
});
|
|
31
|
+
server.middlewares.use(async (req, res, next) => {
|
|
32
|
+
const mcpEndpoint = options.mcpEndpoint || "/mcp";
|
|
33
|
+
const url = req.url || "/";
|
|
34
|
+
if (url.startsWith(mcpEndpoint)) {
|
|
35
|
+
if (!mcpServerInstance) {
|
|
36
|
+
console.error("MCP server not initialized yet");
|
|
37
|
+
res.statusCode = 503;
|
|
38
|
+
res.setHeader("Content-Type", "application/json");
|
|
39
|
+
res.end(JSON.stringify(createErrorResponse("MCP server not initialized yet")));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (req.method === "GET") {
|
|
43
|
+
await mcpServerInstance.handleGetRequest(req, res);
|
|
44
|
+
}
|
|
45
|
+
else if (req.method === "POST") {
|
|
46
|
+
let body = "";
|
|
47
|
+
req.on("data", (chunk) => {
|
|
48
|
+
body += chunk.toString();
|
|
49
|
+
});
|
|
50
|
+
req.on("end", async () => {
|
|
51
|
+
try {
|
|
52
|
+
const jsonBody = JSON.parse(body);
|
|
53
|
+
await mcpServerInstance.handlePostRequest(req, res, jsonBody);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error("Error parsing request body:", error);
|
|
57
|
+
res.statusCode = 400;
|
|
58
|
+
res.end(JSON.stringify(createErrorResponse("Invalid JSON body")));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
next();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
next();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
// Start the MCP server when Vite server is ready
|
|
71
|
+
server.httpServer?.on("listening", async () => {
|
|
72
|
+
console.log(`Vite server is ready, initializing MCP server with ${transport} transport`);
|
|
73
|
+
try {
|
|
74
|
+
const serverInstances = await initServer(transport, options);
|
|
75
|
+
mcpServerInstance = serverInstances.mcpServer;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error("Failed to initialize MCP server:", error);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
closeBundle() {
|
|
83
|
+
if (mcpServerInstance) {
|
|
84
|
+
try {
|
|
85
|
+
console.log("Shutting down MCP server...");
|
|
86
|
+
if (typeof mcpServerInstance.shutdown === "function") {
|
|
87
|
+
mcpServerInstance.shutdown();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error("Error shutting down MCP server:", error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
package/dist/server.d.ts
CHANGED
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAgBvD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE;;GAEG;AACH,UAAU,YAAY;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAgBvD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE;;GAEG;AACH,UAAU,YAAY;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,UAAU,eAAe;IACvB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB;AAiBD;;GAEG;AACH,cAAM,SAAS;IACb,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAoB;IAE3D,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,eAAe,CAA+B;IACtD,OAAO,CAAC,QAAQ,CAAuC;IAEvD;;;;OAIG;gBACS,MAAM,EAAE,SAAS,EAAE,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM;IAQjE;;;;OAIG;IACG,gBAAgB,CACpB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,IAAI,CAAC;IA+BhB;;;;;OAKG;IACG,iBAAiB,CACrB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,IAAI,CAAC;IAkChB;;OAEG;IACH,QAAQ,IAAI,IAAI;IAsBhB;;;;;OAKG;YACW,uBAAuB;IA6CrC;;OAEG;IACH,OAAO,CAAC,+BAA+B;IAWvC;;OAEG;YACW,gBAAgB;IAmB9B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAKxB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAO7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;OAEG;IACH,OAAO,CAAC,sBAAsB;CA4B/B;AAoFD;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GACrB,WAAW,OAAO,GAAG,MAAM,EAC3B,SAAS,OAAO,CAAC,YAAY,CAAC,KAC7B,OAAO,CAAC,eAAe,CAezB,CAAC"}
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { createServer as createViteServer } from "vite";
|
|
3
2
|
import { InitializeRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
3
|
import registerTaskTools from "./tools/task-tools.js";
|
|
5
4
|
import registerIndexTools from "./tools/index-tools.js";
|
|
@@ -241,7 +240,7 @@ class MCPServer {
|
|
|
241
240
|
}
|
|
242
241
|
}
|
|
243
242
|
// Remove expired sessions
|
|
244
|
-
if (expiredIds.length
|
|
243
|
+
if (expiredIds.length) {
|
|
245
244
|
console.log(`Cleaning up ${expiredIds.length} expired sessions`);
|
|
246
245
|
for (const sessionId of expiredIds) {
|
|
247
246
|
try {
|
|
@@ -279,73 +278,8 @@ const initServerHTTPTransport = async (customConfig) => {
|
|
|
279
278
|
registerSystemTools(serverInstance);
|
|
280
279
|
registerTaskTools(serverInstance);
|
|
281
280
|
const server = new MCPServer(serverInstance, config);
|
|
282
|
-
const isPluginMode = process.env.VITE_MCP_PLUGIN_ID !== undefined;
|
|
283
281
|
let vite;
|
|
284
|
-
|
|
285
|
-
vite = await createViteServer({
|
|
286
|
-
server: {
|
|
287
|
-
port: config.httpPort,
|
|
288
|
-
middlewareMode: true,
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
// Add CORS middleware
|
|
292
|
-
vite.middlewares.use((req, res, next) => {
|
|
293
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
294
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
295
|
-
res.setHeader("Access-Control-Allow-Headers", `Origin, X-Requested-With, Content-Type, Accept, ${server["SESSION_ID_HEADER_NAME"]}`);
|
|
296
|
-
if (req.method === "OPTIONS") {
|
|
297
|
-
res.statusCode = 200;
|
|
298
|
-
res.end();
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
next();
|
|
302
|
-
});
|
|
303
|
-
vite.middlewares.use(async (req, res, next) => {
|
|
304
|
-
const url = req.url || "/";
|
|
305
|
-
if (url.startsWith(config.mcpEndpoint)) {
|
|
306
|
-
if (req.method === "GET") {
|
|
307
|
-
await server.handleGetRequest(req, res);
|
|
308
|
-
}
|
|
309
|
-
else if (req.method === "POST") {
|
|
310
|
-
let body = "";
|
|
311
|
-
req.on("data", (chunk) => {
|
|
312
|
-
body += chunk.toString();
|
|
313
|
-
});
|
|
314
|
-
req.on("end", async () => {
|
|
315
|
-
try {
|
|
316
|
-
const jsonBody = JSON.parse(body);
|
|
317
|
-
await server.handlePostRequest(req, res, jsonBody);
|
|
318
|
-
}
|
|
319
|
-
catch (error) {
|
|
320
|
-
console.error("Error parsing request body:", error);
|
|
321
|
-
res.statusCode = 400;
|
|
322
|
-
res.end(JSON.stringify(createErrorResponse("Invalid JSON body")));
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
next();
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
next();
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
console.log("Meilisearch MCP Server is running on Vite HTTP transport (standalone mode):", `http://localhost:${config.httpPort}${config.mcpEndpoint}`);
|
|
335
|
-
// Handle server shutdown in standalone mode
|
|
336
|
-
process.on("SIGINT", async () => {
|
|
337
|
-
console.log("Received SIGINT signal");
|
|
338
|
-
server.shutdown();
|
|
339
|
-
if (vite) {
|
|
340
|
-
await vite.close();
|
|
341
|
-
console.log("Vite server closed");
|
|
342
|
-
}
|
|
343
|
-
process.exit(0);
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
console.log("Meilisearch MCP Server is running on Vite HTTP transport (plugin mode):", `${config.mcpEndpoint}`);
|
|
348
|
-
}
|
|
282
|
+
console.log("Meilisearch MCP Server is running on Vite HTTP transport (plugin mode):", `${config.mcpEndpoint}`);
|
|
349
283
|
// Return both server instances for proper cleanup
|
|
350
284
|
return { mcpServer: server, viteServer: vite };
|
|
351
285
|
};
|
package/dist/standalone.d.ts
CHANGED
|
@@ -36,6 +36,6 @@ interface StandaloneServerOptions {
|
|
|
36
36
|
* @param options Configuration options for the MCP server
|
|
37
37
|
* @returns A promise that resolves to the HTTP server instance
|
|
38
38
|
*/
|
|
39
|
-
export declare function
|
|
40
|
-
export default
|
|
39
|
+
export declare function mcpStandalone(options?: StandaloneServerOptions): Promise<http.Server>;
|
|
40
|
+
export default mcpStandalone;
|
|
41
41
|
//# sourceMappingURL=standalone.d.ts.map
|
package/dist/standalone.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAO7B,UAAU,uBAAuB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,OAAO,GAAE,uBAGR,GACA,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAmGtB;AAqCD,eAAe,aAAa,CAAC"}
|
package/dist/standalone.js
CHANGED
|
@@ -8,7 +8,7 @@ import { createErrorResponse } from "./utils/error-handler.js";
|
|
|
8
8
|
* @param options Configuration options for the MCP server
|
|
9
9
|
* @returns A promise that resolves to the HTTP server instance
|
|
10
10
|
*/
|
|
11
|
-
export async function
|
|
11
|
+
export async function mcpStandalone(options = {
|
|
12
12
|
meilisearchApiKey: "",
|
|
13
13
|
meilisearchHost: "http://localhost:7700",
|
|
14
14
|
}) {
|
|
@@ -123,11 +123,11 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
|
|
123
123
|
break;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
mcpStandalone(options)
|
|
127
127
|
.then(() => console.log("MCP server running"))
|
|
128
128
|
.catch((err) => {
|
|
129
129
|
console.error("Failed to start server:", err);
|
|
130
130
|
process.exit(1);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
-
export default
|
|
133
|
+
export default mcpStandalone;
|