@alpic-ai/insights 0.0.0-dev.gd8fe3e4 → 0.0.0-dev.gd908bf7
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 +9 -0
- package/dist/index.mjs +43 -32
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
|
|
3
4
|
//#region src/intent-middleware.d.ts
|
|
4
5
|
interface PromptData {
|
|
5
6
|
toolName: string;
|
|
@@ -64,6 +65,10 @@ declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMid
|
|
|
64
65
|
* or the low-level `Server` and patches the `tools/list` and `tools/call`
|
|
65
66
|
* request handlers to surface captured feedback via `options.handler` (or,
|
|
66
67
|
* when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
|
|
68
|
+
*
|
|
69
|
+
* Already-registered handlers are wrapped immediately; future registrations
|
|
70
|
+
* are wrapped via a `Map.set` proxy so order of calls relative to
|
|
71
|
+
* `registerTool` does not matter.
|
|
67
72
|
*/
|
|
68
73
|
declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMiddlewareOptions) => void;
|
|
69
74
|
//#endregion
|
|
@@ -74,6 +79,10 @@ declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMi
|
|
|
74
79
|
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
75
80
|
* handlers to surface the captured intent via `options.handler` (or, when
|
|
76
81
|
* `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
|
|
82
|
+
*
|
|
83
|
+
* Already-registered handlers are wrapped immediately; future registrations
|
|
84
|
+
* (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
|
|
85
|
+
* of calls relative to `registerTool` does not matter.
|
|
77
86
|
*/
|
|
78
87
|
declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
|
|
79
88
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -49,7 +49,7 @@ function feedbackMiddleware(options) {
|
|
|
49
49
|
},
|
|
50
50
|
outputSchema: FEEDBACK_OUTPUT_SCHEMA,
|
|
51
51
|
annotations: {
|
|
52
|
-
readOnlyHint:
|
|
52
|
+
readOnlyHint: false,
|
|
53
53
|
destructiveHint: false,
|
|
54
54
|
openWorldHint: false,
|
|
55
55
|
idempotentHint: true
|
|
@@ -98,25 +98,29 @@ function feedbackMiddleware(options) {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
//#endregion
|
|
101
|
-
//#region src/
|
|
101
|
+
//#region src/capture-feedback.ts
|
|
102
|
+
const INSTALLED_MARKER$1 = "__alpicCaptureFeedbackInstalled";
|
|
102
103
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* `Server`
|
|
104
|
+
* Injects a `send_feedback` tool into a vanilla `@modelcontextprotocol/sdk`
|
|
105
|
+
* server and captures feedback submissions. Accepts the high-level `McpServer`
|
|
106
|
+
* or the low-level `Server` and patches the `tools/list` and `tools/call`
|
|
107
|
+
* request handlers to surface captured feedback via `options.handler` (or,
|
|
108
|
+
* when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
|
|
106
109
|
*
|
|
107
110
|
* Already-registered handlers are wrapped immediately; future registrations
|
|
108
|
-
*
|
|
109
|
-
*
|
|
111
|
+
* are wrapped via a `Map.set` proxy so order of calls relative to
|
|
112
|
+
* `registerTool` does not matter.
|
|
110
113
|
*/
|
|
111
|
-
const
|
|
114
|
+
const captureFeedback = (server, options) => {
|
|
112
115
|
const handlers = ("server" in server ? server.server : server)?._requestHandlers;
|
|
113
116
|
if (!(handlers instanceof Map)) {
|
|
114
|
-
console.warn(
|
|
117
|
+
console.warn("@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected `_requestHandlers` Map on Server. Feedback capture disabled.");
|
|
115
118
|
return;
|
|
116
119
|
}
|
|
117
120
|
const marked = handlers;
|
|
118
|
-
if (marked[
|
|
119
|
-
marked[
|
|
121
|
+
if (marked[INSTALLED_MARKER$1]) return;
|
|
122
|
+
marked[INSTALLED_MARKER$1] = true;
|
|
123
|
+
const middleware = feedbackMiddleware(options);
|
|
120
124
|
const targets = /* @__PURE__ */ new Set(["tools/list", "tools/call"]);
|
|
121
125
|
const wrap = (method, handler) => {
|
|
122
126
|
if (!targets.has(method)) return handler;
|
|
@@ -133,22 +137,6 @@ const installCaptureMiddleware = (server, { middleware, installedMarker, disable
|
|
|
133
137
|
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
134
138
|
};
|
|
135
139
|
//#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
|
|
152
140
|
//#region src/intent-middleware.ts
|
|
153
141
|
const USER_INTENT_FIELD = "user_intent";
|
|
154
142
|
/**
|
|
@@ -256,19 +244,42 @@ Examples:
|
|
|
256
244
|
}
|
|
257
245
|
//#endregion
|
|
258
246
|
//#region src/capture-intents.ts
|
|
247
|
+
const INSTALLED_MARKER = "__alpicCaptureIntentsInstalled";
|
|
259
248
|
/**
|
|
260
249
|
* Captures the user's natural-language intent behind each tool call on a vanilla
|
|
261
250
|
* `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
|
|
262
251
|
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
263
252
|
* handlers to surface the captured intent via `options.handler` (or, when
|
|
264
253
|
* `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
|
|
254
|
+
*
|
|
255
|
+
* Already-registered handlers are wrapped immediately; future registrations
|
|
256
|
+
* (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
|
|
257
|
+
* of calls relative to `registerTool` does not matter.
|
|
265
258
|
*/
|
|
266
259
|
const captureIntents = (server, options) => {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
260
|
+
const handlers = ("server" in server ? server.server : server)?._requestHandlers;
|
|
261
|
+
if (!(handlers instanceof Map)) {
|
|
262
|
+
console.warn("@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected `_requestHandlers` Map on Server. Prompt capture disabled.");
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const marked = handlers;
|
|
266
|
+
if (marked[INSTALLED_MARKER]) return;
|
|
267
|
+
marked[INSTALLED_MARKER] = true;
|
|
268
|
+
const middleware = intentMiddleware(options);
|
|
269
|
+
const targets = /* @__PURE__ */ new Set(["tools/list", "tools/call"]);
|
|
270
|
+
const wrap = (method, handler) => {
|
|
271
|
+
if (!targets.has(method)) return handler;
|
|
272
|
+
return async (...args) => {
|
|
273
|
+
const [request, extra] = args;
|
|
274
|
+
return middleware({
|
|
275
|
+
method,
|
|
276
|
+
params: request.params ?? {}
|
|
277
|
+
}, extra, () => handler(...args));
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
for (const [method, handler] of [...handlers]) handlers.set(method, wrap(method, handler));
|
|
281
|
+
const originalSet = handlers.set.bind(handlers);
|
|
282
|
+
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
272
283
|
};
|
|
273
284
|
//#endregion
|
|
274
285
|
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.
|
|
3
|
+
"version": "0.0.0-dev.gd908bf7",
|
|
4
4
|
"description": "User insights middlewares for Alpic-hosted MCP servers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -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.9.
|
|
31
|
+
"@types/node": "^25.9.4",
|
|
32
32
|
"shx": "^0.4.0",
|
|
33
|
-
"skybridge": "^1.2.
|
|
34
|
-
"tsdown": "^0.22.
|
|
33
|
+
"skybridge": "^1.2.4",
|
|
34
|
+
"tsdown": "^0.22.3",
|
|
35
35
|
"typescript": "^6.0.3",
|
|
36
|
-
"vitest": "^4.1.
|
|
36
|
+
"vitest": "^4.1.9",
|
|
37
37
|
"zod": "^4.4.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|