mcp-meilisearch 1.2.0 → 1.2.1
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/client.d.ts +34 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +34 -0
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export declare class MCPClient {
|
|
2
|
+
/**
|
|
3
|
+
* Indicates whether the client is connected to the MCP server
|
|
4
|
+
* Used to track the connection state and control async operations
|
|
5
|
+
*/
|
|
2
6
|
isConnected: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* List of available tools provided by the MCP server
|
|
9
|
+
* Each tool has a name and description
|
|
10
|
+
*/
|
|
3
11
|
tools: {
|
|
4
12
|
name: string;
|
|
5
13
|
description: string;
|
|
@@ -9,20 +17,46 @@ export declare class MCPClient {
|
|
|
9
17
|
private transport;
|
|
10
18
|
private toolsUpdatedCallback;
|
|
11
19
|
constructor(serverName: string);
|
|
20
|
+
/**
|
|
21
|
+
* Registers a callback to be called when the list of available tools changes
|
|
22
|
+
* @param callback The function to call when tools are updated
|
|
23
|
+
*/
|
|
12
24
|
onToolsUpdatedCallback(callback: (tools: Array<{
|
|
13
25
|
name: string;
|
|
14
26
|
description: string;
|
|
15
27
|
}>) => void): void;
|
|
28
|
+
/**
|
|
29
|
+
* Executes the provided callback once the client is connected to the server
|
|
30
|
+
* Waits in a loop until the connection is established
|
|
31
|
+
* @param callback The function to execute after connection is established
|
|
32
|
+
* @returns The result of the callback function
|
|
33
|
+
*/
|
|
16
34
|
onConnected<T>(callback: () => T | Promise<T>): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Connects to the MCP server with retry logic
|
|
37
|
+
* @param serverUrl The URL of the MCP server to connect to
|
|
38
|
+
* @throws Error if connection fails after 5 attempts
|
|
39
|
+
*/
|
|
17
40
|
connectToServer(serverUrl: string): Promise<void>;
|
|
18
41
|
private listTools;
|
|
19
42
|
private setUpNotifications;
|
|
43
|
+
/**
|
|
44
|
+
* Calls a tool on the MCP server with optional arguments
|
|
45
|
+
* Parses and processes the response from the server
|
|
46
|
+
* @param name The name of the tool to call
|
|
47
|
+
* @param args Optional arguments to pass to the tool
|
|
48
|
+
* @returns Object containing success status and either data or error message
|
|
49
|
+
*/
|
|
20
50
|
callTool(name: string, args?: Record<string, any>): Promise<{
|
|
21
51
|
success: boolean;
|
|
22
52
|
data?: any;
|
|
23
53
|
error?: string;
|
|
24
54
|
}>;
|
|
25
55
|
private setUpTransport;
|
|
56
|
+
/**
|
|
57
|
+
* Closes the connection to the server and resets the connection state
|
|
58
|
+
* Called automatically on transport error or can be called manually
|
|
59
|
+
*/
|
|
26
60
|
cleanup(): Promise<void>;
|
|
27
61
|
}
|
|
28
62
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,qBAAa,SAAS;IACpB,WAAW,EAAE,OAAO,CAAS;
|
|
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;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAM;IAEpD,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;YAsBzC,SAAS;IAuBvB,OAAO,CAAC,kBAAkB;IAW1B;;;;;;OAMG;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;IAoCF,OAAO,CAAC,cAAc;IAKtB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAK/B"}
|
package/dist/client.js
CHANGED
|
@@ -2,7 +2,15 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
|
2
2
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
3
|
import { TextContentSchema, LoggingMessageNotificationSchema, ToolListChangedNotificationSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
4
|
export class MCPClient {
|
|
5
|
+
/**
|
|
6
|
+
* Indicates whether the client is connected to the MCP server
|
|
7
|
+
* Used to track the connection state and control async operations
|
|
8
|
+
*/
|
|
5
9
|
isConnected = false;
|
|
10
|
+
/**
|
|
11
|
+
* List of available tools provided by the MCP server
|
|
12
|
+
* Each tool has a name and description
|
|
13
|
+
*/
|
|
6
14
|
tools = [];
|
|
7
15
|
client;
|
|
8
16
|
tries = 0;
|
|
@@ -11,15 +19,30 @@ export class MCPClient {
|
|
|
11
19
|
constructor(serverName) {
|
|
12
20
|
this.client = new Client({ name: serverName, version: "1.0.0" });
|
|
13
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Registers a callback to be called when the list of available tools changes
|
|
24
|
+
* @param callback The function to call when tools are updated
|
|
25
|
+
*/
|
|
14
26
|
onToolsUpdatedCallback(callback) {
|
|
15
27
|
this.toolsUpdatedCallback = callback;
|
|
16
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Executes the provided callback once the client is connected to the server
|
|
31
|
+
* Waits in a loop until the connection is established
|
|
32
|
+
* @param callback The function to execute after connection is established
|
|
33
|
+
* @returns The result of the callback function
|
|
34
|
+
*/
|
|
17
35
|
async onConnected(callback) {
|
|
18
36
|
while (!this.isConnected) {
|
|
19
37
|
await new Promise((resolve) => setTimeout(resolve));
|
|
20
38
|
}
|
|
21
39
|
return callback();
|
|
22
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Connects to the MCP server with retry logic
|
|
43
|
+
* @param serverUrl The URL of the MCP server to connect to
|
|
44
|
+
* @throws Error if connection fails after 5 attempts
|
|
45
|
+
*/
|
|
23
46
|
async connectToServer(serverUrl) {
|
|
24
47
|
const url = new URL(serverUrl);
|
|
25
48
|
try {
|
|
@@ -69,6 +92,13 @@ export class MCPClient {
|
|
|
69
92
|
this.client.setNotificationHandler(LoggingMessageNotificationSchema, console.info);
|
|
70
93
|
this.client.setNotificationHandler(ToolListChangedNotificationSchema, this.listTools);
|
|
71
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Calls a tool on the MCP server with optional arguments
|
|
97
|
+
* Parses and processes the response from the server
|
|
98
|
+
* @param name The name of the tool to call
|
|
99
|
+
* @param args Optional arguments to pass to the tool
|
|
100
|
+
* @returns Object containing success status and either data or error message
|
|
101
|
+
*/
|
|
72
102
|
async callTool(name, args) {
|
|
73
103
|
try {
|
|
74
104
|
const result = await this.client.callTool({ name, arguments: args });
|
|
@@ -106,6 +136,10 @@ export class MCPClient {
|
|
|
106
136
|
return;
|
|
107
137
|
this.transport.onerror = this.cleanup;
|
|
108
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Closes the connection to the server and resets the connection state
|
|
141
|
+
* Called automatically on transport error or can be called manually
|
|
142
|
+
*/
|
|
109
143
|
async cleanup() {
|
|
110
144
|
if (this.client == null)
|
|
111
145
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-meilisearch",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Model Context Protocol (MCP) implementation for Meilisearch",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"build": "tsc && tsc --project tsconfig.types.json",
|
|
27
27
|
"demo": "npm run build & npm run dev --workspace=demo",
|
|
28
28
|
"server": "npm run build && node --env-file=.env dist/index.js",
|
|
29
|
-
"prepublishOnly": "rm -rf dist && npm version
|
|
29
|
+
"prepublishOnly": "rm -rf dist && npm version patch && npm run build"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@modelcontextprotocol/sdk": "^1.10.1",
|