mcp-meilisearch 1.3.4 → 1.3.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.
- 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/utils/ai-handler.d.ts.map +1 -1
- package/dist/utils/ai-handler.js +24 -34
- package/package.json +1 -1
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 {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-handler.d.ts","sourceRoot":"","sources":["../../src/utils/ai-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai-handler.d.ts","sourceRoot":"","sources":["../../src/utils/ai-handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,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;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,CAAyC;IACvD,OAAO,CAAC,cAAc,CAIb;IAET;;;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;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;YAwBnB,kBAAkB;YAiClB,uBAAuB;CAiCtC"}
|
package/dist/utils/ai-handler.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OpenAI } from "openai";
|
|
2
2
|
import systemPrompt from "../prompts/system.js";
|
|
3
|
-
import { InferenceClient } from "@huggingface/inference";
|
|
4
3
|
import { markdownToJson } from "./response-handler.js";
|
|
4
|
+
import { InferenceClient } from "@huggingface/inference";
|
|
5
5
|
/**
|
|
6
6
|
* AI Inference Service
|
|
7
7
|
*
|
|
@@ -117,39 +117,30 @@ export class AIService {
|
|
|
117
117
|
async processQuery(query, specificTools) {
|
|
118
118
|
if (!this.ensureInitialized())
|
|
119
119
|
return null;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return this.processHuggingFaceQuery(tools, messages);
|
|
131
|
-
}
|
|
132
|
-
return this.processOpenAIQuery(tools, messages);
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
if (error instanceof Error) {
|
|
136
|
-
throw new Error(error.message);
|
|
137
|
-
}
|
|
138
|
-
throw error;
|
|
120
|
+
const mentionedTools = this.extractToolNames(query);
|
|
121
|
+
const toolsToUse = specificTools || (mentionedTools.length ? mentionedTools : undefined);
|
|
122
|
+
const tools = this.getToolDefinitions(toolsToUse);
|
|
123
|
+
const systemPrompt = this.systemPrompt.replace("MCP_TOOLS", JSON.stringify(tools, null, 2));
|
|
124
|
+
const messages = [
|
|
125
|
+
{ role: "system", content: systemPrompt },
|
|
126
|
+
{ role: "user", content: query },
|
|
127
|
+
];
|
|
128
|
+
if (this.provider === "huggingface") {
|
|
129
|
+
return this.processHuggingFaceQuery(tools, messages);
|
|
139
130
|
}
|
|
131
|
+
return this.processOpenAIQuery(tools, messages);
|
|
140
132
|
}
|
|
141
133
|
async processOpenAIQuery(tools, messages) {
|
|
142
134
|
const client = this.client;
|
|
143
|
-
const response = await client.chat.completions
|
|
144
|
-
.create({
|
|
135
|
+
const response = await client.chat.completions.create({
|
|
145
136
|
tools,
|
|
146
137
|
messages,
|
|
147
138
|
model: this.model,
|
|
148
|
-
})
|
|
149
|
-
.catch((error) => {
|
|
150
|
-
console.error("Error in OpenAI API call:", error);
|
|
151
|
-
return null;
|
|
152
139
|
});
|
|
140
|
+
if ("error" in response) {
|
|
141
|
+
console.error("Error in OpenAI API call:", response);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
153
144
|
if (!response?.choices.length)
|
|
154
145
|
return null;
|
|
155
146
|
const message = response.choices[0].message;
|
|
@@ -160,23 +151,22 @@ export class AIService {
|
|
|
160
151
|
return null;
|
|
161
152
|
return {
|
|
162
153
|
toolName: toolCall.name,
|
|
163
|
-
reasoning: message.content,
|
|
164
154
|
parameters: toolCall.parameters,
|
|
155
|
+
reasoning: JSON.stringify(toolCall, null, 2),
|
|
165
156
|
};
|
|
166
157
|
}
|
|
167
158
|
async processHuggingFaceQuery(tools, messages) {
|
|
168
159
|
const client = this.client;
|
|
169
|
-
const response = await client
|
|
170
|
-
.chatCompletion({
|
|
160
|
+
const response = await client.chatCompletion({
|
|
171
161
|
tools,
|
|
172
162
|
messages,
|
|
173
163
|
max_tokens: 512,
|
|
174
164
|
model: this.model,
|
|
175
|
-
})
|
|
176
|
-
.catch((error) => {
|
|
177
|
-
console.error("Error in HugginFace API call:", error);
|
|
178
|
-
return null;
|
|
179
165
|
});
|
|
166
|
+
if ("error" in response) {
|
|
167
|
+
console.error("Error in HugginFace call:", response);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
180
170
|
if (!response?.choices.length)
|
|
181
171
|
return null;
|
|
182
172
|
const message = response.choices[0].message;
|
|
@@ -187,8 +177,8 @@ export class AIService {
|
|
|
187
177
|
return null;
|
|
188
178
|
return {
|
|
189
179
|
toolName: toolCall.name,
|
|
190
|
-
reasoning: message.content,
|
|
191
180
|
parameters: toolCall.parameters,
|
|
181
|
+
reasoning: JSON.stringify(toolCall, null, 2),
|
|
192
182
|
};
|
|
193
183
|
}
|
|
194
184
|
}
|