@alpic-ai/insights 0.0.0-dev.g10ef689 → 0.0.0-dev.g11e8d71

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,6 +1,5 @@
1
1
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
-
4
3
  //#region src/intent-middleware.d.ts
5
4
  interface PromptData {
6
5
  toolName: string;
@@ -37,20 +36,6 @@ type McpMiddlewareFn = (request: {
37
36
  */
38
37
  declare function intentMiddleware(options?: IntentMiddlewareOptions): McpMiddlewareFn;
39
38
  //#endregion
40
- //#region src/capture-intents.d.ts
41
- /**
42
- * Captures the user's natural-language intent behind each tool call on a vanilla
43
- * `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
44
- * low-level `Server` and patches the `tools/list` and `tools/call` request
45
- * handlers to surface the captured intent via `options.handler` (or, when
46
- * `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
47
- *
48
- * Already-registered handlers are wrapped immediately; future registrations
49
- * (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
50
- * of calls relative to `registerTool` does not matter.
51
- */
52
- declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
53
- //#endregion
54
39
  //#region src/feedback-middleware.d.ts
55
40
  interface FeedbackData {
56
41
  content: string;
@@ -72,4 +57,24 @@ interface FeedbackMiddlewareOptions {
72
57
  */
73
58
  declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMiddlewareFn;
74
59
  //#endregion
75
- export { type FeedbackData, type FeedbackMiddlewareOptions, type IntentMiddlewareOptions, type McpMiddlewareFn, type PromptData, captureIntents, feedbackMiddleware, intentMiddleware };
60
+ //#region src/capture-feedback.d.ts
61
+ /**
62
+ * Injects a `send_feedback` tool into a vanilla `@modelcontextprotocol/sdk`
63
+ * server and captures feedback submissions. Accepts the high-level `McpServer`
64
+ * or the low-level `Server` and patches the `tools/list` and `tools/call`
65
+ * request handlers to surface captured feedback via `options.handler` (or,
66
+ * when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
67
+ */
68
+ declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMiddlewareOptions) => void;
69
+ //#endregion
70
+ //#region src/capture-intents.d.ts
71
+ /**
72
+ * Captures the user's natural-language intent behind each tool call on a vanilla
73
+ * `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
74
+ * low-level `Server` and patches the `tools/list` and `tools/call` request
75
+ * handlers to surface the captured intent via `options.handler` (or, when
76
+ * `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
77
+ */
78
+ declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
79
+ //#endregion
80
+ export { type FeedbackData, type FeedbackMiddlewareOptions, type IntentMiddlewareOptions, type McpMiddlewareFn, type PromptData, captureFeedback, captureIntents, feedbackMiddleware, intentMiddleware };
package/dist/index.mjs CHANGED
@@ -3,6 +3,17 @@ import { CallToolRequestSchema, CallToolResultSchema, ListToolsResultSchema } fr
3
3
  const FEEDBACK_TOOL_NAME = "send_feedback";
4
4
  const FEEDBACK_TOOL_DESCRIPTION = "Send feedback about this MCP server to its operators. Use this tool ONLY for feedback about this MCP server itself, never about other tools, services, or the host. You MAY call this tool when you detect a genuine issue with this server (e.g. a tool that failed unexpectedly, an unhelpful response, a missing capability). You MAY also call it when the user explicitly asks to send feedback. Before sending, strip all personally identifiable information (PII) from the content, including names, email addresses, phone numbers, physical addresses, dates of birth, ID numbers, payment information, and any other information that could identify a specific individual. Replace stripped values with generic placeholders (e.g. \"[name]\", \"[email]\").";
5
5
  const FEEDBACK_RESPONSE_TEXT = "Feedback received. Thanks!";
6
+ const FEEDBACK_OUTPUT_SCHEMA = {
7
+ type: "object",
8
+ properties: { status: {
9
+ type: "string",
10
+ enum: ["received"],
11
+ description: "Confirmation that the feedback was received by the server operators."
12
+ } },
13
+ required: ["status"],
14
+ additionalProperties: false
15
+ };
16
+ const FEEDBACK_STRUCTURED_CONTENT = { status: "received" };
6
17
  /**
7
18
  * Lets MCP server builders collect qualitative feedback from end users about their
8
19
  * tool/server. Injects a `send_feedback` tool at `tools/list` time and intercepts calls
@@ -35,6 +46,13 @@ function feedbackMiddleware(options) {
35
46
  }
36
47
  },
37
48
  required: ["content", "source"]
49
+ },
50
+ outputSchema: FEEDBACK_OUTPUT_SCHEMA,
51
+ annotations: {
52
+ readOnlyHint: true,
53
+ destructiveHint: false,
54
+ openWorldHint: false,
55
+ idempotentHint: true
38
56
  }
39
57
  });
40
58
  return parsed.data;
@@ -56,6 +74,7 @@ function feedbackMiddleware(options) {
56
74
  content,
57
75
  source
58
76
  };
77
+ if (process.env.NODE_ENV !== "production") console.log("[insights] feedback received:", feedback);
59
78
  if (options?.handler) try {
60
79
  await options.handler(feedback);
61
80
  } catch (error) {
@@ -66,15 +85,70 @@ function feedbackMiddleware(options) {
66
85
  type: "text",
67
86
  text: FEEDBACK_RESPONSE_TEXT
68
87
  }],
88
+ structuredContent: FEEDBACK_STRUCTURED_CONTENT,
69
89
  _meta: { [metaKeyName]: feedback }
70
90
  };
71
- return { content: [{
72
- type: "text",
73
- text: FEEDBACK_RESPONSE_TEXT
74
- }] };
91
+ return {
92
+ content: [{
93
+ type: "text",
94
+ text: FEEDBACK_RESPONSE_TEXT
95
+ }],
96
+ structuredContent: FEEDBACK_STRUCTURED_CONTENT
97
+ };
75
98
  };
76
99
  }
77
100
  //#endregion
101
+ //#region src/install-capture-middleware.ts
102
+ /**
103
+ * Patches the `tools/list` and `tools/call` request handlers of a vanilla
104
+ * `@modelcontextprotocol/sdk` server (high-level `McpServer` or low-level
105
+ * `Server`) to run the given middleware.
106
+ *
107
+ * Already-registered handlers are wrapped immediately; future registrations
108
+ * (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
109
+ * of calls relative to `registerTool` does not matter.
110
+ */
111
+ const installCaptureMiddleware = (server, { middleware, installedMarker, disabledWarning }) => {
112
+ const handlers = ("server" in server ? server.server : server)?._requestHandlers;
113
+ if (!(handlers instanceof Map)) {
114
+ console.warn(`@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected \`_requestHandlers\` Map on Server. ${disabledWarning}`);
115
+ return;
116
+ }
117
+ const marked = handlers;
118
+ if (marked[installedMarker]) return;
119
+ marked[installedMarker] = true;
120
+ const targets = /* @__PURE__ */ new Set(["tools/list", "tools/call"]);
121
+ const wrap = (method, handler) => {
122
+ if (!targets.has(method)) return handler;
123
+ return async (...args) => {
124
+ const [request, extra] = args;
125
+ return middleware({
126
+ method,
127
+ params: request.params ?? {}
128
+ }, extra, () => handler(...args));
129
+ };
130
+ };
131
+ for (const [method, handler] of [...handlers]) handlers.set(method, wrap(method, handler));
132
+ const originalSet = handlers.set.bind(handlers);
133
+ handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
134
+ };
135
+ //#endregion
136
+ //#region src/capture-feedback.ts
137
+ /**
138
+ * Injects a `send_feedback` tool into a vanilla `@modelcontextprotocol/sdk`
139
+ * server and captures feedback submissions. Accepts the high-level `McpServer`
140
+ * or the low-level `Server` and patches the `tools/list` and `tools/call`
141
+ * request handlers to surface captured feedback via `options.handler` (or,
142
+ * when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
143
+ */
144
+ const captureFeedback = (server, options) => {
145
+ installCaptureMiddleware(server, {
146
+ middleware: feedbackMiddleware(options),
147
+ installedMarker: "__alpicCaptureFeedbackInstalled",
148
+ disabledWarning: "Feedback capture disabled."
149
+ });
150
+ };
151
+ //#endregion
78
152
  //#region src/intent-middleware.ts
79
153
  const USER_INTENT_FIELD = "user_intent";
80
154
  /**
@@ -182,42 +256,19 @@ Examples:
182
256
  }
183
257
  //#endregion
184
258
  //#region src/capture-intents.ts
185
- const INSTALLED_MARKER = "__alpicCaptureIntentsInstalled";
186
259
  /**
187
260
  * Captures the user's natural-language intent behind each tool call on a vanilla
188
261
  * `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
189
262
  * low-level `Server` and patches the `tools/list` and `tools/call` request
190
263
  * handlers to surface the captured intent via `options.handler` (or, when
191
264
  * `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
192
- *
193
- * Already-registered handlers are wrapped immediately; future registrations
194
- * (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
195
- * of calls relative to `registerTool` does not matter.
196
265
  */
197
266
  const captureIntents = (server, options) => {
198
- const handlers = ("server" in server ? server.server : server)?._requestHandlers;
199
- if (!(handlers instanceof Map)) {
200
- console.warn("@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected `_requestHandlers` Map on Server. Prompt capture disabled.");
201
- return;
202
- }
203
- const marked = handlers;
204
- if (marked[INSTALLED_MARKER]) return;
205
- marked[INSTALLED_MARKER] = true;
206
- const middleware = intentMiddleware(options);
207
- const targets = new Set(["tools/list", "tools/call"]);
208
- const wrap = (method, handler) => {
209
- if (!targets.has(method)) return handler;
210
- return async (...args) => {
211
- const [request, extra] = args;
212
- return middleware({
213
- method,
214
- params: request.params ?? {}
215
- }, extra, () => handler(...args));
216
- };
217
- };
218
- for (const [method, handler] of [...handlers]) handlers.set(method, wrap(method, handler));
219
- const originalSet = handlers.set.bind(handlers);
220
- handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
267
+ installCaptureMiddleware(server, {
268
+ middleware: intentMiddleware(options),
269
+ installedMarker: "__alpicCaptureIntentsInstalled",
270
+ disabledWarning: "Prompt capture disabled."
271
+ });
221
272
  };
222
273
  //#endregion
223
- export { captureIntents, feedbackMiddleware, intentMiddleware };
274
+ export { captureFeedback, captureIntents, feedbackMiddleware, intentMiddleware };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpic-ai/insights",
3
- "version": "0.0.0-dev.g10ef689",
3
+ "version": "0.0.0-dev.g11e8d71",
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.36.2"
21
+ "skybridge": "^0.36.3 || ^1.0.0"
22
22
  },
23
23
  "peerDependenciesMeta": {
24
24
  "skybridge": {
@@ -28,12 +28,12 @@
28
28
  "devDependencies": {
29
29
  "@modelcontextprotocol/sdk": "^1.29.0",
30
30
  "@total-typescript/tsconfig": "^1.0.4",
31
- "@types/node": "^25.7.0",
31
+ "@types/node": "^25.9.5",
32
32
  "shx": "^0.4.0",
33
- "skybridge": "^0.36.2",
34
- "tsdown": "^0.22.0",
33
+ "skybridge": "^1.2.7",
34
+ "tsdown": "^0.22.5",
35
35
  "typescript": "^6.0.3",
36
- "vitest": "^4.1.6",
36
+ "vitest": "^4.1.10",
37
37
  "zod": "^4.4.3"
38
38
  },
39
39
  "scripts": {
@@ -42,7 +42,7 @@
42
42
  "test": "pnpm run test:unit && pnpm run test:type && pnpm run test:format",
43
43
  "test:unit": "vitest run",
44
44
  "test:format": "biome check --error-on-warnings .",
45
- "test:type": "tsc --noEmit",
45
+ "test:type": "tsgo --noEmit",
46
46
  "publish:npm": "pnpm publish --tag \"${NPM_TAG}\" --access public --no-git-checks"
47
47
  }
48
48
  }