mcp-meilisearch 1.0.15 → 1.0.17
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 +16 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +103 -0
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -101,3 +101,19 @@ This project uses:
|
|
|
101
101
|
|
|
102
102
|
- `sessionTimeout`: Session timeout in milliseconds (Default: 3600000)
|
|
103
103
|
- `sessionCleanupInterval`: Session cleanup interval in milliseconds (Default: 60000)
|
|
104
|
+
|
|
105
|
+
### Using the MCPClient
|
|
106
|
+
|
|
107
|
+
The package also exports the MCPClient class for client-side integration:
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { MCPClient } from "mcp-meilisearch/client";
|
|
111
|
+
|
|
112
|
+
const client = new MCPClient("mcp-meilisearch-client");
|
|
113
|
+
await client.connectToServer("http://localhost:3000/mcp");
|
|
114
|
+
|
|
115
|
+
// Call a tool
|
|
116
|
+
const result = await client.callTool("search-across-all-indexes", {
|
|
117
|
+
q: "search kiosco antonio",
|
|
118
|
+
});
|
|
119
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class MCPClient {
|
|
2
|
+
tools: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
}[];
|
|
6
|
+
private client;
|
|
7
|
+
private tries;
|
|
8
|
+
private transport;
|
|
9
|
+
private onToolsUpdatedCallback;
|
|
10
|
+
constructor(serverName: string);
|
|
11
|
+
setOnToolsUpdatedCallback(callback: (tools: Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
}>) => void): void;
|
|
15
|
+
connectToServer(serverUrl: string): Promise<void>;
|
|
16
|
+
listTools(): Promise<void>;
|
|
17
|
+
private setUpNotifications;
|
|
18
|
+
callTool(name: string, args?: Record<string, any>): Promise<{
|
|
19
|
+
success: boolean;
|
|
20
|
+
data?: any;
|
|
21
|
+
error?: string;
|
|
22
|
+
}>;
|
|
23
|
+
private setUpTransport;
|
|
24
|
+
cleanup(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,qBAAa,SAAS;IACpB,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,sBAAsB,CAEd;gBAEJ,UAAU,EAAE,MAAM;IAIvB,yBAAyB,CAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,IAAI;IAKnE,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBjD,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBhC,OAAO,CAAC,kBAAkB;IAWpB,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;IAKhB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
import { TextContentSchema, LoggingMessageNotificationSchema, ToolListChangedNotificationSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
export class MCPClient {
|
|
5
|
+
tools = [];
|
|
6
|
+
client;
|
|
7
|
+
tries = 0;
|
|
8
|
+
transport = null;
|
|
9
|
+
onToolsUpdatedCallback = null;
|
|
10
|
+
constructor(serverName) {
|
|
11
|
+
this.client = new Client({ name: serverName, version: "1.0.0" });
|
|
12
|
+
}
|
|
13
|
+
setOnToolsUpdatedCallback(callback) {
|
|
14
|
+
this.onToolsUpdatedCallback = callback;
|
|
15
|
+
}
|
|
16
|
+
async connectToServer(serverUrl) {
|
|
17
|
+
const url = new URL(serverUrl);
|
|
18
|
+
try {
|
|
19
|
+
this.transport = new StreamableHTTPClientTransport(url);
|
|
20
|
+
await this.client.connect(this.transport);
|
|
21
|
+
this.setUpTransport();
|
|
22
|
+
this.setUpNotifications();
|
|
23
|
+
await this.listTools();
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
this.tries++;
|
|
27
|
+
if (this.tries > 5) {
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
await new Promise((resolve) => setTimeout(resolve, this.tries * 1000));
|
|
31
|
+
await this.connectToServer(serverUrl);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async listTools() {
|
|
35
|
+
try {
|
|
36
|
+
const toolsResult = await this.client.listTools();
|
|
37
|
+
if (!toolsResult) {
|
|
38
|
+
this.tools = [];
|
|
39
|
+
}
|
|
40
|
+
else if (toolsResult.tools && Array.isArray(toolsResult.tools)) {
|
|
41
|
+
this.tools = toolsResult.tools.map((tool) => ({
|
|
42
|
+
name: tool.name,
|
|
43
|
+
description: tool.description ?? "",
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.tools = [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
this.tools = [];
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
if (this.onToolsUpdatedCallback) {
|
|
55
|
+
this.onToolsUpdatedCallback([...this.tools]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
setUpNotifications() {
|
|
60
|
+
this.client.setNotificationHandler(LoggingMessageNotificationSchema, console.info);
|
|
61
|
+
this.client.setNotificationHandler(ToolListChangedNotificationSchema, this.listTools);
|
|
62
|
+
}
|
|
63
|
+
async callTool(name, args) {
|
|
64
|
+
try {
|
|
65
|
+
const result = await this.client.callTool({ name, arguments: args });
|
|
66
|
+
if (!result) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
error: "Received null or undefined result from tool",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const content = result.content;
|
|
73
|
+
if (!content?.length) {
|
|
74
|
+
return { success: true, data: [] };
|
|
75
|
+
}
|
|
76
|
+
const processedContent = content.reduce((_, item) => {
|
|
77
|
+
const parse = TextContentSchema.safeParse(item);
|
|
78
|
+
if (parse.success) {
|
|
79
|
+
try {
|
|
80
|
+
return JSON.parse(parse.data.text);
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
return parse.data.text;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return item;
|
|
87
|
+
}, {});
|
|
88
|
+
return { success: true, data: processedContent };
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
92
|
+
return { success: false, error: errorMessage };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
setUpTransport() {
|
|
96
|
+
if (this.transport === null)
|
|
97
|
+
return;
|
|
98
|
+
this.transport.onerror = this.cleanup;
|
|
99
|
+
}
|
|
100
|
+
async cleanup() {
|
|
101
|
+
await this.client.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-meilisearch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Model Context Protocol (MCP) implementation for Meilisearch",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
"dist",
|
|
10
10
|
"README.md"
|
|
11
11
|
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./client": {
|
|
18
|
+
"import": "./dist/client.js",
|
|
19
|
+
"types": "./dist/client.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
12
22
|
"workspaces": [
|
|
13
23
|
"demo"
|
|
14
24
|
],
|