@alpic-ai/insights 0.0.0-dev.6f3fb0d → 0.0.0-dev.6f73a04

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.d.mts CHANGED
@@ -1,21 +1,24 @@
1
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
2
 
4
- //#region src/user-prompt-middleware.d.ts
3
+ //#region src/intent-middleware.d.ts
5
4
  interface PromptData {
6
5
  toolName: string;
7
6
  userPrompt: string;
8
7
  }
9
- interface UserPromptMiddlewareOptions {
8
+ interface IntentMiddlewareOptions {
10
9
  handler?: (prompt: PromptData) => Promise<void> | void;
11
10
  /**
12
- * Mapping of tool names to input field names whose values should be captured as the prompt.
13
- * This overrides the default behavior of injecting a synthetic `user_prompt` field into the tool's schema.
14
- * Use this when the tool already has a parameter (e.g. `query`, `question`) that conveys user intent.
15
- * For tools in this mapping, the synthetic `user_prompt` field is not injected into the schema and
16
- * the field's value is read straight from the tool call arguments without being stripped.
11
+ * If provided, only these tool names will have the `user_intent` field injected and their
12
+ * prompts captured. All other tools are left untouched.
17
13
  */
18
- promptArgByTool?: Record<string, string>;
14
+ tools?: string[];
15
+ /**
16
+ * Mapping of tool names to argument names whose values should be captured as the intent.
17
+ * Use this when the tool already has an argument (e.g. `query`, `question`) that conveys user
18
+ * intent. For tools in this mapping, the synthetic `user_intent` argument is not injected into the
19
+ * schema and the argument's value is read straight from the tool call arguments without being stripped.
20
+ */
21
+ argumentNameOverride?: Record<string, string>;
19
22
  }
20
23
  /**
21
24
  * Structurally compatible with `skybridge/server`'s `McpMiddlewareFn` so
@@ -28,12 +31,12 @@ type McpMiddlewareFn = (request: {
28
31
  /**
29
32
  * Captures the user's natural-language intent behind each tool call so MCP
30
33
  * server builders can see *why* their tools are being invoked, not just that
31
- * they were. The LLM fills in `user_prompt` from the original user message
34
+ * they were. The LLM fills in `user_intent` from the original user message
32
35
  * (the server has no other way to access it).
33
36
  */
34
- declare function userPromptMiddleware(options?: UserPromptMiddlewareOptions): McpMiddlewareFn;
37
+ declare function intentMiddleware(options?: IntentMiddlewareOptions): McpMiddlewareFn;
35
38
  //#endregion
36
- //#region src/capture-user-prompts.d.ts
39
+ //#region src/capture-intents.d.ts
37
40
  /**
38
41
  * Captures the user's natural-language prompt behind each tool call on a vanilla
39
42
  * `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
@@ -45,6 +48,6 @@ declare function userPromptMiddleware(options?: UserPromptMiddlewareOptions): Mc
45
48
  * (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
46
49
  * of calls relative to `registerTool` does not matter.
47
50
  */
48
- declare const captureUserPrompts: (server: McpServer | Server, options?: UserPromptMiddlewareOptions) => void;
51
+ declare const captureIntents: (server: McpServer, options?: IntentMiddlewareOptions) => void;
49
52
  //#endregion
50
- export { type McpMiddlewareFn, type PromptData, type UserPromptMiddlewareOptions, captureUserPrompts, userPromptMiddleware };
53
+ export { type IntentMiddlewareOptions, type McpMiddlewareFn, type PromptData, captureIntents, intentMiddleware };
package/dist/index.mjs CHANGED
@@ -1,27 +1,63 @@
1
1
  import { CallToolRequestSchema, CallToolResultSchema, ListToolsResultSchema } from "@modelcontextprotocol/sdk/types.js";
2
- //#region src/user-prompt-middleware.ts
3
- const USER_PROMPT_FIELD = "user_prompt";
2
+ //#region src/intent-middleware.ts
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
7
- * they were. The LLM fills in `user_prompt` from the original user message
7
+ * they were. The LLM fills in `user_intent` from the original user message
8
8
  * (the server has no other way to access it).
9
9
  */
10
- function userPromptMiddleware(options) {
11
- const metaKeyName = process.env.ALPIC_PROMPT_META_KEY;
12
- const promptArgByTool = options?.promptArgByTool ?? {};
10
+ function intentMiddleware(options) {
11
+ const metaKeyName = process.env.ALPIC_INTENT_META_KEY;
12
+ const argumentNameOverride = options?.argumentNameOverride ?? {};
13
+ const toolsFilter = options?.tools ? new Set(options.tools) : null;
13
14
  return async (request, _extra, next) => {
14
15
  if (request.method === "tools/list") {
15
16
  const rawResult = await next();
16
17
  const parsed = ListToolsResultSchema.safeParse(rawResult);
17
18
  if (!parsed.success) return rawResult;
18
19
  for (const tool of parsed.data.tools) {
19
- if (promptArgByTool[tool.name] != null) continue;
20
+ if (toolsFilter && !toolsFilter.has(tool.name)) continue;
21
+ if (argumentNameOverride[tool.name] != null) continue;
20
22
  tool.inputSchema.properties = {
21
23
  ...tool.inputSchema.properties,
22
- [USER_PROMPT_FIELD]: {
24
+ [USER_INTENT_FIELD]: {
23
25
  type: "string",
24
- description: "Copy the user's prompt that led to this tool call. Remove any PII (Personal Identifiable Information)."
26
+ description: `A concise summary of what the user is trying to accomplish, derived from their message or the
27
+ conversation context that triggered this tool call.
28
+ This is used to understand the user's intent and context to improve the overall user experience.
29
+
30
+ - For short, self-contained prompts (e.g. "I want new shoes"), copy the user message as-is.
31
+ - For longer conversations or detailed requests, summarize the core goal and any relevant
32
+ context in 1-2 sentences. Focus on intent, constraints, and preferences - not the full
33
+ dialogue.
34
+
35
+ Before sending, strip all personally identifiable information (PII), including but not
36
+ limited to:
37
+ - Names (first, last, usernames, handles)
38
+ - Email addresses
39
+ - Phone numbers
40
+ - Physical addresses (street, city, zip/postal code, country when tied to an individual)
41
+ - Dates of birth or exact ages
42
+ - Government-issued ID numbers (SSN, passport, driver's license, etc.)
43
+ - Payment or financial information (card numbers, bank accounts, etc.)
44
+ - IP addresses or device identifiers
45
+ - Account credentials (passwords, tokens, API keys)
46
+ - Health or biometric data
47
+ - Any other information that could identify a specific individual
48
+
49
+ Replace stripped values with a generic placeholder (e.g. "[name]", "[email]", "[address]").
50
+
51
+ Examples:
52
+ User: "I want red running shoes under $100"
53
+ -> "I want red running shoes under $100"
54
+
55
+ User: "Hi, I'm John Smith, john@example.com, and I'm looking for flights from Paris to
56
+ Tokyo for 2 adults departing around mid-June, budget around EUR2000 total"
57
+ -> "Looking for flights from Paris to Tokyo for 2 adults, mid-June, budget ~EUR2000"
58
+
59
+ User: "I need help resetting my password for account ID acct_12345"
60
+ -> "I need help resetting my password for account ID [account_id]"`
25
61
  }
26
62
  };
27
63
  }
@@ -30,12 +66,14 @@ function userPromptMiddleware(options) {
30
66
  if (request.method === "tools/call") {
31
67
  const parsedRequest = CallToolRequestSchema.safeParse(request);
32
68
  if (!parsedRequest.success) return next();
33
- const promptField = promptArgByTool[parsedRequest.data.params.name] ?? USER_PROMPT_FIELD;
69
+ const toolName = parsedRequest.data.params.name;
70
+ if (toolsFilter && !toolsFilter.has(toolName)) return next();
71
+ const promptField = argumentNameOverride[toolName] ?? USER_INTENT_FIELD;
34
72
  const args = parsedRequest.data.params.arguments ?? {};
35
73
  const userPrompt = typeof args[promptField] === "string" ? args[promptField] : void 0;
36
74
  const hasUserPrompt = userPrompt != null && userPrompt.length > 0;
37
- if (USER_PROMPT_FIELD in args) {
38
- delete args[USER_PROMPT_FIELD];
75
+ if (USER_INTENT_FIELD in args) {
76
+ delete args[USER_INTENT_FIELD];
39
77
  request.params.arguments = args;
40
78
  }
41
79
  if (hasUserPrompt && options?.handler) try {
@@ -49,7 +87,7 @@ function userPromptMiddleware(options) {
49
87
  const rawResult = await next();
50
88
  const parsedResult = CallToolResultSchema.safeParse(rawResult);
51
89
  if (!parsedResult.success) return rawResult;
52
- if (metaKeyName && !options?.handler && hasUserPrompt) parsedResult.data._meta = {
90
+ if (metaKeyName && hasUserPrompt) parsedResult.data._meta = {
53
91
  ...parsedResult.data._meta,
54
92
  [metaKeyName]: userPrompt
55
93
  };
@@ -59,7 +97,7 @@ function userPromptMiddleware(options) {
59
97
  };
60
98
  }
61
99
  //#endregion
62
- //#region src/capture-user-prompts.ts
100
+ //#region src/capture-intents.ts
63
101
  const INSTALLED_MARKER = "__alpicCaptureUserPromptsInstalled";
64
102
  /**
65
103
  * Captures the user's natural-language prompt behind each tool call on a vanilla
@@ -72,7 +110,7 @@ const INSTALLED_MARKER = "__alpicCaptureUserPromptsInstalled";
72
110
  * (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
73
111
  * of calls relative to `registerTool` does not matter.
74
112
  */
75
- const captureUserPrompts = (server, options) => {
113
+ const captureIntents = (server, options) => {
76
114
  const handlers = ("server" in server ? server.server : server)?._requestHandlers;
77
115
  if (!(handlers instanceof Map)) {
78
116
  console.warn("@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected `_requestHandlers` Map on Server. Prompt capture disabled.");
@@ -81,7 +119,7 @@ const captureUserPrompts = (server, options) => {
81
119
  const marked = handlers;
82
120
  if (marked[INSTALLED_MARKER]) return;
83
121
  marked[INSTALLED_MARKER] = true;
84
- const middleware = userPromptMiddleware(options);
122
+ const middleware = intentMiddleware(options);
85
123
  const targets = new Set(["tools/list", "tools/call"]);
86
124
  const wrap = (method, handler) => {
87
125
  if (!targets.has(method)) return handler;
@@ -98,4 +136,4 @@ const captureUserPrompts = (server, options) => {
98
136
  handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
99
137
  };
100
138
  //#endregion
101
- export { captureUserPrompts, userPromptMiddleware };
139
+ export { captureIntents, intentMiddleware };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpic-ai/insights",
3
- "version": "0.0.0-dev.6f3fb0d",
3
+ "version": "0.0.0-dev.6f73a04",
4
4
  "description": "User insights middlewares for Alpic-hosted MCP servers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -18,7 +18,7 @@
18
18
  "license": "ISC",
19
19
  "peerDependencies": {
20
20
  "@modelcontextprotocol/sdk": ">=1.29.0 <2",
21
- "skybridge": ">=0.35.21"
21
+ "skybridge": ">=0.36.2"
22
22
  },
23
23
  "peerDependenciesMeta": {
24
24
  "skybridge": {
@@ -28,13 +28,13 @@
28
28
  "devDependencies": {
29
29
  "@modelcontextprotocol/sdk": "^1.29.0",
30
30
  "@total-typescript/tsconfig": "^1.0.4",
31
- "@types/node": "^25.6.0",
31
+ "@types/node": "^25.7.0",
32
32
  "shx": "^0.4.0",
33
- "skybridge": "^0.35.21",
34
- "tsdown": "^0.21.10",
33
+ "skybridge": "^0.36.2",
34
+ "tsdown": "^0.22.0",
35
35
  "typescript": "^6.0.3",
36
- "vitest": "^4.1.5",
37
- "zod": "^4.4.1"
36
+ "vitest": "^4.1.6",
37
+ "zod": "^4.4.3"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "shx rm -rf dist && tsdown",