mcp-meilisearch 1.0.8 → 1.0.9

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/README.md CHANGED
@@ -7,22 +7,7 @@ A Model Context Protocol (MCP) server implementation that provides a bridge betw
7
7
  This project provides a MCP server that enables AI models to interact directly with Meilisearch functionalities. The architecture includes:
8
8
 
9
9
  - **MCP Server**: Exposes Meilisearch APIs as tools using the Model Context Protocol.
10
- - **Web Client**: A demo interface showcasing search functionalities.
11
-
12
- ## Architecture
13
-
14
- ```
15
- ┌───────────────┐ ┌───────────────┐ ┌───────────────┐
16
- │ Meilisearch │ │ MCP Server │ │ Web Client │
17
- │ Instance │ <--> │ (Node.js) │ <--> │ (Browser) │
18
- └───────────────┘ └───────────────┘ └───────────────┘
19
- ^
20
-
21
- ┌───────────────┐
22
- │ Document Data │
23
- │ Sources │
24
- └───────────────┘
25
- ```
10
+ - **Web Client Demo**: A demo interface showcasing search functionalities.
26
11
 
27
12
  ## Key Features
28
13
 
@@ -79,8 +64,8 @@ MEILISEARCH_API_KEY=your_master_key_here
79
64
  To start the server:
80
65
 
81
66
  ```bash
82
- npm run start:server # Start the MCP server
83
- npm run start:client # Start the web client
67
+ npm run server # Start the MCP server
68
+ npm run demo # Start the Web client demo
84
69
  ```
85
70
 
86
71
  ### Accessing the Web Interface
@@ -99,14 +84,6 @@ This project uses:
99
84
  - **Express**: Powers the web server.
100
85
  - **Model Context Protocol SDK**: Facilitates AI integration.
101
86
 
102
- ## Project Structure
103
-
104
- - `src/`: Core MCP server implementation.
105
- - `tools/`: Meilisearch API tools.
106
- - `utils/`: Utility functions for API communication and error handling.
107
- - `server.ts`: Main MCP server implementation.
108
- - `client/`: Web client for testing and demonstration.
109
-
110
87
  ## Vite Plugin Integration
111
88
 
112
89
  This package provides a Vite plugin for easy integration with your Vite-based applications.
@@ -164,8 +141,7 @@ const client = new MCPClient("meilisearch");
164
141
  await client.connectToServer("http://localhost:3000/mcp");
165
142
 
166
143
  // Call a tool
167
- const result = await client.callTool("search", {
168
- indexUid: "movies",
169
- q: "star wars",
144
+ const result = await client.callTool("search-across-all-indexes", {
145
+ q: "search kiosco antonio",
170
146
  });
171
147
  ```
package/dist/index.js CHANGED
File without changes
@@ -0,0 +1,41 @@
1
+ import http from "node:http";
2
+ interface StandaloneServerOptions {
3
+ /**
4
+ * HTTP port for MCP server
5
+ * @default 8080
6
+ */
7
+ httpPort?: number;
8
+ /**
9
+ * MCP endpoint path
10
+ * @default "/mcp"
11
+ */
12
+ mcpEndpoint?: string;
13
+ /**
14
+ * Session timeout in milliseconds
15
+ * @default 3600000 (1 hour)
16
+ */
17
+ sessionTimeout?: number;
18
+ /**
19
+ * Session cleanup interval in milliseconds
20
+ * @default 60000 (1 minute)
21
+ */
22
+ sessionCleanupInterval?: number;
23
+ /**
24
+ * The URL of the Meilisearch instance
25
+ * @default "http://localhost:7700"
26
+ */
27
+ meilisearchHost: string;
28
+ /**
29
+ * The API key for authenticating with Meilisearch
30
+ * @default ""
31
+ */
32
+ meilisearchApiKey: string;
33
+ }
34
+ /**
35
+ * Start a standalone MCP server (without Vite)
36
+ * @param options Configuration options for the MCP server
37
+ * @returns A promise that resolves to the HTTP server instance
38
+ */
39
+ export declare function initStandaloneServer(options?: StandaloneServerOptions): Promise<http.Server>;
40
+ export default initStandaloneServer;
41
+ //# sourceMappingURL=standalone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAQ7B,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,oBAAoB,CACxC,OAAO,GAAE,uBAGR,GACA,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAmGtB;AAqCD,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,133 @@
1
+ import { createServer } from "node:http";
2
+ import { initServer } from "./server.js";
3
+ import { parse as parseUrl } from "node:url";
4
+ import { configHandler } from "./utils/config-handler.js";
5
+ import { createErrorResponse } from "./utils/error-handler.js";
6
+ /**
7
+ * Start a standalone MCP server (without Vite)
8
+ * @param options Configuration options for the MCP server
9
+ * @returns A promise that resolves to the HTTP server instance
10
+ */
11
+ export async function initStandaloneServer(options = {
12
+ meilisearchApiKey: "",
13
+ meilisearchHost: "http://localhost:7700",
14
+ }) {
15
+ configHandler.setMeilisearchHost(options.meilisearchHost);
16
+ configHandler.setMeilisearchApiKey(options.meilisearchApiKey);
17
+ let mcpServerInstance = null;
18
+ const httpPort = options.httpPort || 8080;
19
+ const mcpEndpoint = options.mcpEndpoint || "/mcp";
20
+ const server = createServer(async (req, res) => {
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
+ const parsedUrl = parseUrl(req.url || "/", true);
30
+ const pathname = parsedUrl.pathname || "/";
31
+ if (pathname.startsWith(mcpEndpoint)) {
32
+ if (!mcpServerInstance) {
33
+ console.error("MCP server not initialized yet");
34
+ res.statusCode = 503;
35
+ res.setHeader("Content-Type", "application/json");
36
+ res.end(JSON.stringify(createErrorResponse("MCP server not initialized yet")));
37
+ return;
38
+ }
39
+ if (req.method === "GET") {
40
+ await mcpServerInstance.handleGetRequest(req, res);
41
+ }
42
+ else if (req.method === "POST") {
43
+ let body = "";
44
+ req.on("data", (chunk) => {
45
+ body += chunk.toString();
46
+ });
47
+ req.on("end", async () => {
48
+ try {
49
+ const jsonBody = JSON.parse(body);
50
+ await mcpServerInstance.handlePostRequest(req, res, jsonBody);
51
+ }
52
+ catch (error) {
53
+ console.error("Error parsing request body:", error);
54
+ res.statusCode = 400;
55
+ res.end(JSON.stringify(createErrorResponse("Invalid JSON body")));
56
+ }
57
+ });
58
+ }
59
+ else {
60
+ res.statusCode = 405;
61
+ res.end(JSON.stringify(createErrorResponse("Method not allowed")));
62
+ }
63
+ }
64
+ else {
65
+ res.statusCode = 404;
66
+ res.end(JSON.stringify({ error: "Not found" }));
67
+ }
68
+ });
69
+ await new Promise((resolve) => {
70
+ server.listen(httpPort, () => {
71
+ console.log(`Standalone MCP server listening on port ${httpPort}`);
72
+ resolve();
73
+ });
74
+ });
75
+ try {
76
+ console.log("Initializing MCP server...");
77
+ const serverInstances = await initServer("http", options);
78
+ mcpServerInstance = serverInstances.mcpServer;
79
+ console.log("MCP server initialized successfully");
80
+ }
81
+ catch (error) {
82
+ console.error("Failed to initialize MCP server:", error);
83
+ server.close();
84
+ throw error;
85
+ }
86
+ const shutdownHandler = () => {
87
+ console.log("Shutting down MCP server...");
88
+ if (mcpServerInstance && typeof mcpServerInstance.shutdown === "function") {
89
+ try {
90
+ mcpServerInstance.shutdown();
91
+ }
92
+ catch (error) {
93
+ console.error("Error shutting down MCP server:", error);
94
+ }
95
+ }
96
+ server.close();
97
+ };
98
+ process.on("SIGINT", shutdownHandler);
99
+ process.on("SIGTERM", shutdownHandler);
100
+ return server;
101
+ }
102
+ if (import.meta.url === `file://${process.argv[1]}`) {
103
+ const args = process.argv.slice(2);
104
+ const options = {
105
+ meilisearchHost: "http://localhost:7700",
106
+ meilisearchApiKey: "",
107
+ };
108
+ for (let i = 0; i < args.length; i += 2) {
109
+ const key = args[i].replace("--", "");
110
+ const value = args[i + 1];
111
+ switch (key) {
112
+ case "port":
113
+ options.httpPort = parseInt(value, 10);
114
+ break;
115
+ case "endpoint":
116
+ options.mcpEndpoint = value;
117
+ break;
118
+ case "host":
119
+ options.meilisearchHost = value;
120
+ break;
121
+ case "apiKey":
122
+ options.meilisearchApiKey = value;
123
+ break;
124
+ }
125
+ }
126
+ initStandaloneServer(options)
127
+ .then(() => console.log("MCP server running"))
128
+ .catch((err) => {
129
+ console.error("Failed to start server:", err);
130
+ process.exit(1);
131
+ });
132
+ }
133
+ export default initStandaloneServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-meilisearch",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Model Context Protocol (MCP) implementation for Meilisearch",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,12 +10,12 @@
10
10
  "README.md"
11
11
  ],
12
12
  "workspaces": [
13
- "client"
13
+ "demo"
14
14
  ],
15
15
  "scripts": {
16
16
  "build": "tsc && tsc --project tsconfig.types.json",
17
- "server": "npm run build && node --env-file=.env dist/index.js",
18
- "client": "npm run server & npm run dev --workspace=client",
17
+ "server": "npm run build && node --env-file=.env dist/standalone.js",
18
+ "demo": "npm run build && node --env-file=.env dist/index.js & npm run dev --workspace=demo",
19
19
  "prepare": "npm version patch",
20
20
  "prepublishOnly": "npm run build"
21
21
  },