mcp-meilisearch 1.4.4 → 1.4.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,qBAAa,SAAS;IACpB;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAS;IAE7B;;;OAGG;IACH,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACjC,EAAE,CAAM;IAET,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,oBAAoB,CAEZ;gBAEJ,UAAU,EAAE,MAAM;IAI9B;;;OAGG;IACH,sBAAsB,CACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,IAAI;IAKzE;;;;;OAKG;IACG,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAOhE;;;;OAIG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAuBzC,SAAS;IA0BvB,OAAO,CAAC,kBAAkB;IAW1B;;;;;;;OAOG;IACG,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACzB,OAAO,CAAC;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;KACh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AAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAuBzC,SAAS;IA0BvB,OAAO,CAAC,kBAAkB;IAW1B;;;;;;;OAOG;IACG,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACzB,OAAO,CAAC;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IA2CF;;;;;;;;OAQG;IACG,cAAc,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QAAE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,CAAC,EAAE,OAAO,CAAA;KAAO,GAClE,OAAO,CAAC;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IA6CF,OAAO,CAAC,cAAc;IAKtB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAK/B"}
package/dist/client.js CHANGED
@@ -167,6 +167,12 @@ export class MCPClient {
167
167
  toolUsed: toolName,
168
168
  };
169
169
  }
170
+ if (!toolName) {
171
+ return {
172
+ success: false,
173
+ error: "No tool name provided in AI response",
174
+ };
175
+ }
170
176
  const toolResult = await this.callTool(toolName, parameters);
171
177
  return {
172
178
  ...toolResult,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,OAAO,EAAE,aAAa,EAAyB,MAAM,oBAAoB,CAAC;AAE1E;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,aAA8B,GACtC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAkEtB;AAwCD,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,OAAO,EAAE,aAAa,EAAyB,MAAM,oBAAoB,CAAC;AAE1E;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,aAA8B,GACtC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAmEtB;AAwCD,eAAe,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -23,10 +23,10 @@ export async function mcpMeilisearchServer(options = defaultOptions) {
23
23
  else {
24
24
  console.warn("AI provider API key not found. AI will not be available");
25
25
  }
26
- const httpPort = options.httpPort || 4995;
27
- const transport = options.transport || "http";
28
26
  let mcpServerInstance = null;
29
- const mcpEndpoint = options.mcpEndpoint || "/mcp";
27
+ const transport = options.transport;
28
+ const mcpEndpoint = options.mcpEndpoint;
29
+ const httpPort = options.httpPort || defaultOptions.httpPort;
30
30
  const server = createServer(async (req, res) => {
31
31
  if (!mcpServerInstance) {
32
32
  res.statusCode = 503;
@@ -97,7 +97,7 @@ if (import.meta.url === `file://${process.argv?.[1]}`) {
97
97
  break;
98
98
  }
99
99
  }
100
- mcpMeilisearchServer(options)
100
+ await mcpMeilisearchServer(options)
101
101
  .then(() => console.info("MCP server running"))
102
102
  .catch((err) => {
103
103
  console.error("Failed to start server:", err);
package/dist/server.d.ts CHANGED
@@ -7,7 +7,14 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
7
  interface ServerInstance {
8
8
  mcpServer: MCPServer;
9
9
  }
10
- export declare const defaultOptions: ServerOptions;
10
+ export declare const defaultOptions: {
11
+ httpPort: number;
12
+ mcpEndpoint: string;
13
+ sessionTimeout: number;
14
+ sessionCleanupInterval: number;
15
+ meilisearchHost: string | undefined;
16
+ meilisearchApiKey: string | undefined;
17
+ };
11
18
  /**
12
19
  * Implementation of an MCP server for Meilisearch
13
20
  */
@@ -30,7 +37,7 @@ export declare class MCPServer {
30
37
  * @param res The HTTP response
31
38
  * @param mcpEndpoint The MCP endpoint path
32
39
  */
33
- handleHttpRequest(req: IncomingMessage, res: ServerResponse, mcpEndpoint: string): Promise<void>;
40
+ handleHttpRequest(req: IncomingMessage, res: ServerResponse, mcpEndpoint?: string): Promise<void>;
34
41
  /**
35
42
  * Handles an HTTP GET request
36
43
  * @param req The HTTP request
@@ -95,6 +102,6 @@ export declare class MCPServer {
95
102
  * @returns A promise that resolves to the server instances
96
103
  * @throws Error if the transport type is unsupported
97
104
  */
98
- export declare const initServer: (transport: "stdio" | "http", config?: Partial<ServerOptions>) => Promise<ServerInstance>;
105
+ export declare const initServer: (transport?: "http" | "stdio", config?: Partial<ServerOptions>) => Promise<ServerInstance>;
99
106
  export {};
100
107
  //# sourceMappingURL=server.d.ts.map
@@ -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;AAOvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAUpE;;GAEG;AACH,UAAU,cAAc;IACtB,SAAS,EAAE,SAAS,CAAC;CACtB;AASD,eAAO,MAAM,cAAc,EAAE,aAO5B,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAoB;IAE3D,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,eAAe,CAA+B;IACtD,OAAO,CAAC,QAAQ,CAAuC;IAEvD;;;;OAIG;gBACS,MAAM,EAAE,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GAAG,OAAgB,EACpC,SAAS,OAAO,CAAC,aAAa,CAAC,KAC9B,OAAO,CAAC,cAAc,CAcxB,CAAC"}
package/dist/server.js CHANGED
@@ -17,8 +17,8 @@ export const defaultOptions = {
17
17
  mcpEndpoint: "/mcp",
18
18
  sessionTimeout: 3600000,
19
19
  sessionCleanupInterval: 60000,
20
- meilisearchApiKey: process.env.MEILISEARCH_API_KEY || "",
21
- meilisearchHost: process.env.MEILISEARCH_HOST || "http://localhost:7700",
20
+ meilisearchHost: process.env.MEILISEARCH_HOST,
21
+ meilisearchApiKey: process.env.MEILISEARCH_API_KEY,
22
22
  };
23
23
  /**
24
24
  * Implementation of an MCP server for Meilisearch
@@ -46,7 +46,7 @@ export class MCPServer {
46
46
  * @param res The HTTP response
47
47
  * @param mcpEndpoint The MCP endpoint path
48
48
  */
49
- async handleHttpRequest(req, res, mcpEndpoint) {
49
+ async handleHttpRequest(req, res, mcpEndpoint = defaultOptions.mcpEndpoint) {
50
50
  res.setHeader("Access-Control-Allow-Origin", "*");
51
51
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
52
52
  res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, mcp-session-id");
@@ -258,7 +258,7 @@ export class MCPServer {
258
258
  * Starts the session cleanup process
259
259
  */
260
260
  startSessionCleanup() {
261
- const cleanupInterval = this.config.sessionCleanupInterval || 60000;
261
+ const cleanupInterval = this.config.sessionCleanupInterval;
262
262
  this.cleanupInterval = setInterval(() => {
263
263
  this.cleanupExpiredSessions();
264
264
  }, cleanupInterval);
@@ -269,7 +269,7 @@ export class MCPServer {
269
269
  cleanupExpiredSessions() {
270
270
  const now = Date.now();
271
271
  const expiredIds = [];
272
- const sessionTimeout = this.config.sessionTimeout || 3600000;
272
+ const sessionTimeout = this.config.sessionTimeout;
273
273
  for (const [sessionId, info] of this.sessions.entries()) {
274
274
  if (now - info.lastActivity > sessionTimeout) {
275
275
  expiredIds.push(sessionId);
@@ -345,13 +345,13 @@ const initServerStdioTransport = async (customConfig) => {
345
345
  * @returns A promise that resolves to the server instances
346
346
  * @throws Error if the transport type is unsupported
347
347
  */
348
- export const initServer = async (transport, config) => {
348
+ export const initServer = async (transport = "http", config) => {
349
349
  try {
350
350
  switch (transport) {
351
- case "stdio":
352
- return await initServerStdioTransport(config);
353
351
  case "http":
354
352
  return await initServerHTTPTransport(config);
353
+ case "stdio":
354
+ return await initServerStdioTransport(config);
355
355
  default:
356
356
  throw new Error(`Unsupported transport type: ${transport}`);
357
357
  }
package/dist/stdio.js CHANGED
@@ -1,5 +1,2 @@
1
1
  import { mcpMeilisearchServer } from "./index.js";
2
- mcpMeilisearchServer({
3
- transport: "stdio",
4
- meilisearchHost: process.env.MEILISEARCH_HOST,
5
- });
2
+ await mcpMeilisearchServer({ transport: "stdio" });
@@ -2,19 +2,12 @@ import { AiProviderNameOptions } from "../types/options.js";
2
2
  interface AITool {
3
3
  name: string;
4
4
  description: string;
5
- parameters: Record<string, any>;
6
- }
7
- interface AIToolResponseBase {
8
- reasoning?: string | null;
9
- }
10
- interface AIToolSuccessResponse extends AIToolResponseBase {
11
- error: null;
12
- toolName: string;
13
5
  parameters: Record<string, unknown>;
14
6
  }
15
- interface AIToolErrorResponse extends AIToolResponseBase {
16
- error: string;
7
+ interface AIToolResponse {
17
8
  toolName?: string;
9
+ reasoning?: string;
10
+ error: string | null;
18
11
  parameters?: Record<string, unknown>;
19
12
  }
20
13
  /**
@@ -24,13 +17,13 @@ interface AIToolErrorResponse extends AIToolResponseBase {
24
17
  * to use based on the user's query
25
18
  */
26
19
  export declare class AIService {
20
+ private availableTools;
27
21
  private model;
28
22
  private static instance;
29
23
  private static serverInitialized;
30
24
  private provider;
31
25
  private readonly systemPrompt;
32
26
  private client;
33
- private availableTools;
34
27
  /**
35
28
  * Private constructor to prevent direct instantiation
36
29
  * Use getInstance() method instead
@@ -73,7 +66,7 @@ export declare class AIService {
73
66
  * @param specificTools Optional array of specific tool names to consider
74
67
  * @returns Object containing the selected tool name and parameters
75
68
  */
76
- processQuery(query: string, specificTools?: string[]): Promise<AIToolSuccessResponse | AIToolErrorResponse>;
69
+ processQuery(query: string, specificTools?: string[]): Promise<AIToolResponse>;
77
70
  private processOpenAIQuery;
78
71
  private processHuggingFaceQuery;
79
72
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ai-handler.d.ts","sourceRoot":"","sources":["../../src/utils/ai-handler.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,UAAU,MAAM;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAmBD,UAAU,kBAAkB;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,UAAU,qBAAsB,SAAQ,kBAAkB;IACxD,KAAK,EAAE,IAAI,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED,UAAU,mBAAoB,SAAQ,kBAAkB;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED;;;;;GAKG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0B;IACjD,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAwB;IACrD,OAAO,CAAC,MAAM,CAAgD;IAC9D,OAAO,CAAC,cAAc,CAIb;IAET;;;OAGG;IACH,OAAO;IAEP;;;OAGG;WACW,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C,YAAY,CAAwB;IACrD,OAAO,CAAC,MAAM,CAAgD;IAE9D;;;OAGG;IACH,OAAO;IAEP;;;OAGG;WACW,WAAW,IAAI,SAAS;IAOtC;;;;;;OAMG;IACH,UAAU,CACR,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,qBAAgC,EAC1C,KAAK,CAAC,EAAE,MAAM,GACb,IAAI;IAyBP;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;IAIxC,iBAAiB,IAAI,OAAO;IAI5B;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAaxB;;;;;OAKG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,cAAc,CAAC;YA4BZ,kBAAkB;YA+DlB,uBAAuB;CAyDtC"}
@@ -1,8 +1,8 @@
1
1
  import { OpenAI } from "openai";
2
2
  import systemPrompt from "../prompts/system.js";
3
3
  import { OPEN_ROUTER_API } from "../types/enums.js";
4
- import { markdownToJson } from "./response-handler.js";
5
4
  import { InferenceClient } from "@huggingface/inference";
5
+ import { markdownToJson, cleanNullValues } from "./response-handler.js";
6
6
  /**
7
7
  * AI Inference Service
8
8
  *
@@ -10,13 +10,13 @@ import { InferenceClient } from "@huggingface/inference";
10
10
  * to use based on the user's query
11
11
  */
12
12
  export class AIService {
13
+ availableTools = [];
13
14
  model = "gpt-3.5-turbo";
14
15
  static instance = null;
15
16
  static serverInitialized = false;
16
17
  provider = "openai";
17
18
  systemPrompt = systemPrompt;
18
19
  client = null;
19
- availableTools = [];
20
20
  /**
21
21
  * Private constructor to prevent direct instantiation
22
22
  * Use getInstance() method instead
@@ -144,6 +144,22 @@ export class AIService {
144
144
  return { error: "No choices returned from OpenAI" };
145
145
  }
146
146
  const message = response.choices[0].message;
147
+ if (message.tool_calls?.length) {
148
+ const toolCall = message.tool_calls[0]?.function;
149
+ if (!toolCall) {
150
+ return { error: "Invalid tool from OpenAI response" };
151
+ }
152
+ const inferenceToolResponse = {
153
+ name: toolCall.name,
154
+ parameters: cleanNullValues(JSON.parse(toolCall.arguments)),
155
+ };
156
+ return {
157
+ error: null,
158
+ toolName: inferenceToolResponse.name,
159
+ parameters: inferenceToolResponse.parameters,
160
+ reasoning: JSON.stringify(inferenceToolResponse, null, 2),
161
+ };
162
+ }
147
163
  if (message.content) {
148
164
  const toolCall = markdownToJson(message.content);
149
165
  if (!toolCall) {
@@ -177,11 +193,26 @@ export class AIService {
177
193
  return { error: "No choices in Hugging Face response" };
178
194
  }
179
195
  const message = response.choices[0].message;
180
- if (message.content) {
181
- const toolCall = markdownToJson(message.content);
196
+ if (message.tool_calls?.length) {
197
+ const toolCall = message.tool_calls[0]?.function;
182
198
  if (!toolCall) {
183
- return { error: `Invalid tool call format in content: ${response}` };
199
+ return { error: "Invalid tool from Hugging Face response" };
184
200
  }
201
+ const inferenceToolResponse = {
202
+ name: toolCall.name,
203
+ parameters: cleanNullValues(JSON.parse(toolCall.arguments)),
204
+ };
205
+ return {
206
+ error: null,
207
+ toolName: inferenceToolResponse.name,
208
+ parameters: inferenceToolResponse.parameters,
209
+ reasoning: JSON.stringify(inferenceToolResponse, null, 2),
210
+ };
211
+ }
212
+ if (message.content) {
213
+ const toolCall = markdownToJson(message.content);
214
+ if (!toolCall)
215
+ return { error: "Invalid tool call format in content" };
185
216
  return {
186
217
  error: null,
187
218
  toolName: toolCall.name,
@@ -7,4 +7,9 @@
7
7
  * @returns A parsed JavaScript object/array, or null if parsing fails.
8
8
  */
9
9
  export declare function markdownToJson<T>(markdownJsonString: string): T | null;
10
+ /**
11
+ * Recursively removes null values from an object, replacing them with undefined
12
+ * This ensures optional parameters are properly handled by JSON schema validation
13
+ */
14
+ export declare function cleanNullValues(obj: Record<string, any>): Record<string, any>;
10
15
  //# sourceMappingURL=response-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../src/utils/response-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAoCtE"}
1
+ {"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../src/utils/response-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAoCtE;AAgCD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAsB7E"}
@@ -70,3 +70,29 @@ function parseNestedJsonStrings(obj) {
70
70
  }
71
71
  return obj;
72
72
  }
73
+ /**
74
+ * Recursively removes null values from an object, replacing them with undefined
75
+ * This ensures optional parameters are properly handled by JSON schema validation
76
+ */
77
+ export function cleanNullValues(obj) {
78
+ const result = {};
79
+ for (const [key, value] of Object.entries(obj)) {
80
+ if (value === null) {
81
+ continue;
82
+ }
83
+ else if (typeof value === "object" && value !== null) {
84
+ if (Array.isArray(value)) {
85
+ result[key] = value.map((item) => typeof item === "object" && item !== null
86
+ ? cleanNullValues(item)
87
+ : item);
88
+ }
89
+ else {
90
+ result[key] = cleanNullValues(value);
91
+ }
92
+ }
93
+ else {
94
+ result[key] = value;
95
+ }
96
+ }
97
+ return result;
98
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-meilisearch",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Model Context Protocol (MCP) implementation for Meilisearch",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "scripts": {
26
26
  "build": "tsc && tsc -p tsconfig.types.json",
27
- "demo": "npm run build & npm run preview --workspace=demo",
27
+ "demo": "npm run build & npm run dev --workspace=demo",
28
28
  "server": "npm run build && node --env-file=.env dist/index.js",
29
29
  "prepublishOnly": "rm -rf dist && npm version patch && npm run build"
30
30
  },
@@ -33,10 +33,10 @@
33
33
  "@modelcontextprotocol/sdk": "^1.11.4",
34
34
  "axios": "^1.9.0",
35
35
  "openai": "^4.100.0",
36
- "zod": "^3.24.4"
36
+ "zod": "^3.25.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/node": "^22.15.18",
39
+ "@types/node": "^22.15.19",
40
40
  "typescript": "^5.8.3",
41
41
  "zod-to-json-schema": "^3.24.5"
42
42
  },