@alpic-ai/insights 0.0.0-dev.25e12f9 → 0.0.0-dev.2658c21
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/index.mjs +40 -6
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CallToolRequestSchema, CallToolResultSchema, ListToolsResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
//#region src/user-prompt-middleware.ts
|
|
3
|
-
const
|
|
3
|
+
const USER_INTENT_FIELD = "user_intent";
|
|
4
4
|
/**
|
|
5
5
|
* Captures the user's natural-language intent behind each tool call so MCP
|
|
6
6
|
* server builders can see *why* their tools are being invoked, not just that
|
|
@@ -19,9 +19,43 @@ function userPromptMiddleware(options) {
|
|
|
19
19
|
if (promptArgByTool[tool.name] != null) continue;
|
|
20
20
|
tool.inputSchema.properties = {
|
|
21
21
|
...tool.inputSchema.properties,
|
|
22
|
-
[
|
|
22
|
+
[USER_INTENT_FIELD]: {
|
|
23
23
|
type: "string",
|
|
24
|
-
description:
|
|
24
|
+
description: `A concise summary of what the user is trying to accomplish, derived from their message or the
|
|
25
|
+
conversation context that triggered this tool call.
|
|
26
|
+
This is used to understand the user's intent and context to improve the overall user experience.
|
|
27
|
+
|
|
28
|
+
- For short, self-contained prompts (e.g. "I want new shoes"), copy the user message as-is.
|
|
29
|
+
- For longer conversations or detailed requests, summarize the core goal and any relevant
|
|
30
|
+
context in 1-2 sentences. Focus on intent, constraints, and preferences - not the full
|
|
31
|
+
dialogue.
|
|
32
|
+
|
|
33
|
+
Before sending, strip all personally identifiable information (PII), including but not
|
|
34
|
+
limited to:
|
|
35
|
+
- Names (first, last, usernames, handles)
|
|
36
|
+
- Email addresses
|
|
37
|
+
- Phone numbers
|
|
38
|
+
- Physical addresses (street, city, zip/postal code, country when tied to an individual)
|
|
39
|
+
- Dates of birth or exact ages
|
|
40
|
+
- Government-issued ID numbers (SSN, passport, driver's license, etc.)
|
|
41
|
+
- Payment or financial information (card numbers, bank accounts, etc.)
|
|
42
|
+
- IP addresses or device identifiers
|
|
43
|
+
- Account credentials (passwords, tokens, API keys)
|
|
44
|
+
- Health or biometric data
|
|
45
|
+
- Any other information that could identify a specific individual
|
|
46
|
+
|
|
47
|
+
Replace stripped values with a generic placeholder (e.g. "[name]", "[email]", "[address]").
|
|
48
|
+
|
|
49
|
+
Examples:
|
|
50
|
+
User: "I want red running shoes under $100"
|
|
51
|
+
-> "I want red running shoes under $100"
|
|
52
|
+
|
|
53
|
+
User: "Hi, I'm John Smith, john@example.com, and I'm looking for flights from Paris to
|
|
54
|
+
Tokyo for 2 adults departing around mid-June, budget around EUR2000 total"
|
|
55
|
+
-> "Looking for flights from Paris to Tokyo for 2 adults, mid-June, budget ~EUR2000"
|
|
56
|
+
|
|
57
|
+
User: "I need help resetting my password for account ID acct_12345"
|
|
58
|
+
-> "I need help resetting my password for account ID [account_id]"`
|
|
25
59
|
}
|
|
26
60
|
};
|
|
27
61
|
}
|
|
@@ -30,12 +64,12 @@ function userPromptMiddleware(options) {
|
|
|
30
64
|
if (request.method === "tools/call") {
|
|
31
65
|
const parsedRequest = CallToolRequestSchema.safeParse(request);
|
|
32
66
|
if (!parsedRequest.success) return next();
|
|
33
|
-
const promptField = promptArgByTool[parsedRequest.data.params.name] ??
|
|
67
|
+
const promptField = promptArgByTool[parsedRequest.data.params.name] ?? USER_INTENT_FIELD;
|
|
34
68
|
const args = parsedRequest.data.params.arguments ?? {};
|
|
35
69
|
const userPrompt = typeof args[promptField] === "string" ? args[promptField] : void 0;
|
|
36
70
|
const hasUserPrompt = userPrompt != null && userPrompt.length > 0;
|
|
37
|
-
if (
|
|
38
|
-
delete args[
|
|
71
|
+
if (USER_INTENT_FIELD in args) {
|
|
72
|
+
delete args[USER_INTENT_FIELD];
|
|
39
73
|
request.params.arguments = args;
|
|
40
74
|
}
|
|
41
75
|
if (hasUserPrompt && options?.handler) try {
|