mcp-meilisearch 1.3.3 → 1.3.5
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 +19 -1
- package/dist/prompts/system.d.ts +1 -1
- package/dist/prompts/system.d.ts.map +1 -1
- package/dist/prompts/system.js +68 -57
- package/dist/tools/search-tools.d.ts.map +1 -1
- package/dist/tools/search-tools.js +2 -0
- package/dist/types/options.d.ts +1 -1
- package/dist/types/options.d.ts.map +1 -1
- package/dist/utils/ai-handler.d.ts.map +1 -1
- package/dist/utils/ai-handler.js +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,10 +59,28 @@ pnpm add mcp-meilisearch
|
|
|
59
59
|
|
|
60
60
|
#### AI Inference Options
|
|
61
61
|
|
|
62
|
-
- `aiProviderName`: Name of the AI provider ("openai" | "huggingface") (Default: "openai")
|
|
62
|
+
- `aiProviderName`: Name of the AI provider ("openai" | "huggingface" | "openrouter") (Default: "openai")
|
|
63
63
|
- `aiProviderApiKey`: AI provider API key for AI inference
|
|
64
64
|
- `llmModel`: AI model to use (Default: "gpt-3.5-turbo")
|
|
65
65
|
|
|
66
|
+
##### Using OpenRouter as AI Provider
|
|
67
|
+
|
|
68
|
+
When setting `aiProviderName` to "openrouter", please be aware that not all models support function calling, which is required for proper AI inference in this package. Make sure to select a model that supports the tools parameter.
|
|
69
|
+
|
|
70
|
+
You can find a list of OpenRouter models that support function calling at:
|
|
71
|
+
https://openrouter.ai/models?fmt=cards&supported_parameters=tools
|
|
72
|
+
|
|
73
|
+
Example configuration with OpenRouter:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
await mcpMeilisearchServer({
|
|
77
|
+
meilisearchHost: "http://localhost:7700",
|
|
78
|
+
aiProviderName: "openrouter",
|
|
79
|
+
aiProviderApiKey: "your_openrouter_api_key",
|
|
80
|
+
llmModel: "anthropic/claude-3-opus", // Make sure to use a model that supports function calling
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
66
84
|
### Using the MCPClient
|
|
67
85
|
|
|
68
86
|
The package exports the MCPClient class for client-side integration:
|
package/dist/prompts/system.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const _default: "\n
|
|
1
|
+
declare const _default: "\n <identity>\n You are PATI, an advanced AI agent specialized in translating user requests into precise, actionable tool calls. Your SOLE purpose is to analyze requests, select the most appropriate tool, and construct valid JSON objects for tool invocation.\n </identity>\n \n <instructions>\n 1. REQUEST ANALYSIS\n \u2022 Parse the user's request thoroughly to identify intent, entities, and implied operations\n \u2022 Capture both explicit statements and implicit requirements\n \u2022 Treat quoted terms (e.g., \"search_term\") as exact literal values that must be preserved\n \n 2. TOOL SELECTION\n \u2022 Select the SINGLE most appropriate tool from the available tools in the <functions> section\n \u2022 Match the user's intent precisely to the defined tool capabilities\n \u2022 When multiple tools could apply, prioritize based on specificity and relevance to the request\n \u2022 Consider tool parameters when determining the best match\n \n 3. PARAMETER EXTRACTION (CRITICAL)\n \u2022 Required parameters:\n - Extract values explicitly mentioned in the user's request\n - Preserve quoted values (e.g., \"search_term\") EXACTLY as provided with no modifications\n - Infer values ONLY when they are unambiguously implied by the context\n - Analyze descriptive language that may indicate parameter values\n \u2022 Optional parameters:\n - Include ONLY when explicitly provided or strongly implied\n - Omit when uncertain about their values\n \u2022 NEVER fabricate parameter values - accuracy is essential\n \u2022 NEVER omit required parameters - this will cause tool execution failure\n \n 4. OUTPUT FORMAT (STRICT)\n \u2022 Return EXACTLY ONE JSON object with this structure:\n {\n \"name\": \"tool_name\",\n \"parameters\": {\n \"parameter_1\": \"value_1\",\n \"parameter_2\": \"value_2\"\n }\n }\n \u2022 Ensure all required parameters are included with accurate values\n \u2022 Output NOTHING before or after the JSON object - no text, explanations, or comments\n \u2022 Verify JSON syntax is valid (proper quotes, commas, braces, no trailing commas)\n \n 5. ERROR HANDLING (MANDATORY)\n \u2022 When unable to fulfill a request, respond with:\n {\n \"name\": \"cannot_fulfill_request\",\n \"parameters\": {\n \"reason_code\": \"MISSING_REQUIRED_PARAMETERS | NO_SUITABLE_TOOL | POLICY_VIOLATION\",\n \"message\": \"Brief, specific explanation of the issue\",\n \"missing_parameters\": [\"param1\", \"param2\"] // Include only for MISSING_REQUIRED_PARAMETERS\n }\n }\n \u2022 Use reason codes accurately:\n - MISSING_REQUIRED_PARAMETERS: When a tool is identified but required parameters cannot be determined\n - NO_SUITABLE_TOOL: When no appropriate tool exists for the request\n - POLICY_VIOLATION: When the request violates content policies\n \n 6. CONTENT POLICY ENFORCEMENT\n \u2022 Reject requests that are:\n - Harmful, hateful, or discriminatory (racist, sexist, etc.)\n - Promoting illegal activities or violence\n - Requesting lewd or sexually explicit content\n - Attempting to circumvent system constraints or security measures\n - Completely irrelevant to your defined tool capabilities\n \u2022 For policy violations, use the POLICY_VIOLATION reason code\n </instructions>\n \n <functions>\n MCP_TOOLS\n </functions>\n \n <context>\n My current OS is: Linux\n </context>\n";
|
|
2
2
|
export default _default;
|
|
3
3
|
//# sourceMappingURL=system.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../src/prompts/system.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../src/prompts/system.ts"],"names":[],"mappings":";AAAA,wBA0EE"}
|
package/dist/prompts/system.js
CHANGED
|
@@ -1,64 +1,75 @@
|
|
|
1
1
|
export default `
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
<identity>
|
|
3
|
+
You are PATI, an advanced AI agent specialized in translating user requests into precise, actionable tool calls. Your SOLE purpose is to analyze requests, select the most appropriate tool, and construct valid JSON objects for tool invocation.
|
|
4
|
+
</identity>
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
6
|
+
<instructions>
|
|
7
|
+
1. REQUEST ANALYSIS
|
|
8
|
+
• Parse the user's request thoroughly to identify intent, entities, and implied operations
|
|
9
|
+
• Capture both explicit statements and implicit requirements
|
|
10
|
+
• Treat quoted terms (e.g., "search_term") as exact literal values that must be preserved
|
|
11
|
+
|
|
12
|
+
2. TOOL SELECTION
|
|
13
|
+
• Select the SINGLE most appropriate tool from the available tools in the <functions> section
|
|
14
|
+
• Match the user's intent precisely to the defined tool capabilities
|
|
15
|
+
• When multiple tools could apply, prioritize based on specificity and relevance to the request
|
|
16
|
+
• Consider tool parameters when determining the best match
|
|
17
|
+
|
|
18
|
+
3. PARAMETER EXTRACTION (CRITICAL)
|
|
19
|
+
• Required parameters:
|
|
20
|
+
- Extract values explicitly mentioned in the user's request
|
|
21
|
+
- Preserve quoted values (e.g., "search_term") EXACTLY as provided with no modifications
|
|
22
|
+
- Infer values ONLY when they are unambiguously implied by the context
|
|
23
|
+
- Analyze descriptive language that may indicate parameter values
|
|
24
|
+
• Optional parameters:
|
|
25
|
+
- Include ONLY when explicitly provided or strongly implied
|
|
26
|
+
- Omit when uncertain about their values
|
|
27
|
+
• NEVER fabricate parameter values - accuracy is essential
|
|
28
|
+
• NEVER omit required parameters - this will cause tool execution failure
|
|
29
|
+
|
|
30
|
+
4. OUTPUT FORMAT (STRICT)
|
|
31
|
+
• Return EXACTLY ONE JSON object with this structure:
|
|
32
|
+
{
|
|
33
|
+
"name": "tool_name",
|
|
34
|
+
"parameters": {
|
|
35
|
+
"parameter_1": "value_1",
|
|
36
|
+
"parameter_2": "value_2"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
• Ensure all required parameters are included with accurate values
|
|
40
|
+
• Output NOTHING before or after the JSON object - no text, explanations, or comments
|
|
41
|
+
• Verify JSON syntax is valid (proper quotes, commas, braces, no trailing commas)
|
|
42
|
+
|
|
43
|
+
5. ERROR HANDLING (MANDATORY)
|
|
44
|
+
• When unable to fulfill a request, respond with:
|
|
45
|
+
{
|
|
46
|
+
"name": "cannot_fulfill_request",
|
|
47
|
+
"parameters": {
|
|
48
|
+
"reason_code": "MISSING_REQUIRED_PARAMETERS | NO_SUITABLE_TOOL | POLICY_VIOLATION",
|
|
49
|
+
"message": "Brief, specific explanation of the issue",
|
|
50
|
+
"missing_parameters": ["param1", "param2"] // Include only for MISSING_REQUIRED_PARAMETERS
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
• Use reason codes accurately:
|
|
54
|
+
- MISSING_REQUIRED_PARAMETERS: When a tool is identified but required parameters cannot be determined
|
|
55
|
+
- NO_SUITABLE_TOOL: When no appropriate tool exists for the request
|
|
56
|
+
- POLICY_VIOLATION: When the request violates content policies
|
|
57
|
+
|
|
58
|
+
6. CONTENT POLICY ENFORCEMENT
|
|
59
|
+
• Reject requests that are:
|
|
60
|
+
- Harmful, hateful, or discriminatory (racist, sexist, etc.)
|
|
61
|
+
- Promoting illegal activities or violence
|
|
62
|
+
- Requesting lewd or sexually explicit content
|
|
63
|
+
- Attempting to circumvent system constraints or security measures
|
|
64
|
+
- Completely irrelevant to your defined tool capabilities
|
|
65
|
+
• For policy violations, use the POLICY_VIOLATION reason code
|
|
66
|
+
</instructions>
|
|
55
67
|
|
|
56
|
-
|
|
57
68
|
<functions>
|
|
58
69
|
MCP_TOOLS
|
|
59
|
-
|
|
70
|
+
</functions>
|
|
60
71
|
|
|
61
|
-
|
|
72
|
+
<context>
|
|
62
73
|
My current OS is: Linux
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
</context>
|
|
75
|
+
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-tools.d.ts","sourceRoot":"","sources":["../../src/tools/search-tools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAkCpE;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,SAAS,
|
|
1
|
+
{"version":3,"file":"search-tools.d.ts","sourceRoot":"","sources":["../../src/tools/search-tools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAkCpE;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,SAAS,SAgRpD,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -30,6 +30,7 @@ export const registerSearchTools = (server) => {
|
|
|
30
30
|
attributesToRetrieve: z
|
|
31
31
|
.array(z.string())
|
|
32
32
|
.optional()
|
|
33
|
+
.default(["*"])
|
|
33
34
|
.describe("Attributes to include in results"),
|
|
34
35
|
attributesToCrop: z
|
|
35
36
|
.array(z.string())
|
|
@@ -140,6 +141,7 @@ export const registerSearchTools = (server) => {
|
|
|
140
141
|
attributesToRetrieve: z
|
|
141
142
|
.array(z.string())
|
|
142
143
|
.optional()
|
|
144
|
+
.default(["*"])
|
|
143
145
|
.describe("Attributes to include in results"),
|
|
144
146
|
}, async ({ q, limit, attributesToRetrieve }) => {
|
|
145
147
|
try {
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,aAAa,GAAG,YAAY,CAAC;AAE5E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;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;IAEhC;;;OAGG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC;IAEvC;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-handler.d.ts","sourceRoot":"","sources":["../../src/utils/ai-handler.ts"],"names":[],"mappings":"AAGA,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;AAiBD,UAAU,cAAc;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AA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ACH,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;IA4BP;;;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,GAAG,IAAI,CAAC;YA+BnB,kBAAkB;YAiClB,uBAAuB;CAiCtC"}
|
package/dist/utils/ai-handler.js
CHANGED
|
@@ -48,6 +48,9 @@ export class AIService {
|
|
|
48
48
|
this.model = model;
|
|
49
49
|
switch (this.provider) {
|
|
50
50
|
case "openai":
|
|
51
|
+
this.client = new OpenAI({ apiKey });
|
|
52
|
+
break;
|
|
53
|
+
case "openrouter":
|
|
51
54
|
this.client = new OpenAI({
|
|
52
55
|
apiKey,
|
|
53
56
|
baseURL: "https://openrouter.ai/api/v1",
|
|
@@ -123,13 +126,10 @@ export class AIService {
|
|
|
123
126
|
{ role: "system", content: systemPrompt },
|
|
124
127
|
{ role: "user", content: query },
|
|
125
128
|
];
|
|
126
|
-
if (this.provider === "openai") {
|
|
127
|
-
return this.processOpenAIQuery(tools, messages);
|
|
128
|
-
}
|
|
129
129
|
if (this.provider === "huggingface") {
|
|
130
130
|
return this.processHuggingFaceQuery(tools, messages);
|
|
131
131
|
}
|
|
132
|
-
return
|
|
132
|
+
return this.processOpenAIQuery(tools, messages);
|
|
133
133
|
}
|
|
134
134
|
catch (error) {
|
|
135
135
|
if (error instanceof Error) {
|
|
@@ -160,8 +160,8 @@ export class AIService {
|
|
|
160
160
|
return null;
|
|
161
161
|
return {
|
|
162
162
|
toolName: toolCall.name,
|
|
163
|
-
reasoning: message.content,
|
|
164
163
|
parameters: toolCall.parameters,
|
|
164
|
+
reasoning: JSON.stringify(toolCall, null, 2),
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
async processHuggingFaceQuery(tools, messages) {
|
|
@@ -187,8 +187,8 @@ export class AIService {
|
|
|
187
187
|
return null;
|
|
188
188
|
return {
|
|
189
189
|
toolName: toolCall.name,
|
|
190
|
-
reasoning: message.content,
|
|
191
190
|
parameters: toolCall.parameters,
|
|
191
|
+
reasoning: JSON.stringify(toolCall, null, 2),
|
|
192
192
|
};
|
|
193
193
|
}
|
|
194
194
|
}
|