@alpic-ai/insights 0.0.0-dev.g1ceded3 → 0.0.0-dev.g1d08792
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 +0 -9
- package/dist/index.mjs +53 -48
- package/package.json +7 -7
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;
|
|
@@ -65,10 +64,6 @@ declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMid
|
|
|
65
64
|
* or the low-level `Server` and patches the `tools/list` and `tools/call`
|
|
66
65
|
* request handlers to surface captured feedback via `options.handler` (or,
|
|
67
66
|
* 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.
|
|
72
67
|
*/
|
|
73
68
|
declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMiddlewareOptions) => void;
|
|
74
69
|
//#endregion
|
|
@@ -79,10 +74,6 @@ declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMi
|
|
|
79
74
|
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
80
75
|
* handlers to surface the captured intent via `options.handler` (or, when
|
|
81
76
|
* `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.
|
|
86
77
|
*/
|
|
87
78
|
declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
|
|
88
79
|
//#endregion
|
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
|
|
@@ -36,10 +47,11 @@ function feedbackMiddleware(options) {
|
|
|
36
47
|
},
|
|
37
48
|
required: ["content", "source"]
|
|
38
49
|
},
|
|
50
|
+
outputSchema: FEEDBACK_OUTPUT_SCHEMA,
|
|
39
51
|
annotations: {
|
|
40
52
|
readOnlyHint: false,
|
|
41
53
|
destructiveHint: false,
|
|
42
|
-
openWorldHint:
|
|
54
|
+
openWorldHint: false,
|
|
43
55
|
idempotentHint: true
|
|
44
56
|
}
|
|
45
57
|
});
|
|
@@ -73,39 +85,39 @@ function feedbackMiddleware(options) {
|
|
|
73
85
|
type: "text",
|
|
74
86
|
text: FEEDBACK_RESPONSE_TEXT
|
|
75
87
|
}],
|
|
88
|
+
structuredContent: FEEDBACK_STRUCTURED_CONTENT,
|
|
76
89
|
_meta: { [metaKeyName]: feedback }
|
|
77
90
|
};
|
|
78
|
-
return {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
return {
|
|
92
|
+
content: [{
|
|
93
|
+
type: "text",
|
|
94
|
+
text: FEEDBACK_RESPONSE_TEXT
|
|
95
|
+
}],
|
|
96
|
+
structuredContent: FEEDBACK_STRUCTURED_CONTENT
|
|
97
|
+
};
|
|
82
98
|
};
|
|
83
99
|
}
|
|
84
100
|
//#endregion
|
|
85
|
-
//#region src/capture-
|
|
86
|
-
const INSTALLED_MARKER$1 = "__alpicCaptureFeedbackInstalled";
|
|
101
|
+
//#region src/install-capture-middleware.ts
|
|
87
102
|
/**
|
|
88
|
-
*
|
|
89
|
-
* server
|
|
90
|
-
*
|
|
91
|
-
* request handlers to surface captured feedback via `options.handler` (or,
|
|
92
|
-
* when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
|
|
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.
|
|
93
106
|
*
|
|
94
107
|
* Already-registered handlers are wrapped immediately; future registrations
|
|
95
|
-
* are wrapped via a `Map.set` proxy so order
|
|
96
|
-
* `registerTool` does not matter.
|
|
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.
|
|
97
110
|
*/
|
|
98
|
-
const
|
|
111
|
+
const installCaptureMiddleware = (server, { middleware, installedMarker, disabledWarning }) => {
|
|
99
112
|
const handlers = ("server" in server ? server.server : server)?._requestHandlers;
|
|
100
113
|
if (!(handlers instanceof Map)) {
|
|
101
|
-
console.warn(
|
|
114
|
+
console.warn(`@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected \`_requestHandlers\` Map on Server. ${disabledWarning}`);
|
|
102
115
|
return;
|
|
103
116
|
}
|
|
104
117
|
const marked = handlers;
|
|
105
|
-
if (marked[
|
|
106
|
-
marked[
|
|
107
|
-
const
|
|
108
|
-
const targets = new Set(["tools/list", "tools/call"]);
|
|
118
|
+
if (marked[installedMarker]) return;
|
|
119
|
+
marked[installedMarker] = true;
|
|
120
|
+
const targets = /* @__PURE__ */ new Set(["tools/list", "tools/call"]);
|
|
109
121
|
const wrap = (method, handler) => {
|
|
110
122
|
if (!targets.has(method)) return handler;
|
|
111
123
|
return async (...args) => {
|
|
@@ -121,6 +133,22 @@ const captureFeedback = (server, options) => {
|
|
|
121
133
|
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
122
134
|
};
|
|
123
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
|
|
124
152
|
//#region src/intent-middleware.ts
|
|
125
153
|
const USER_INTENT_FIELD = "user_intent";
|
|
126
154
|
/**
|
|
@@ -228,42 +256,19 @@ Examples:
|
|
|
228
256
|
}
|
|
229
257
|
//#endregion
|
|
230
258
|
//#region src/capture-intents.ts
|
|
231
|
-
const INSTALLED_MARKER = "__alpicCaptureIntentsInstalled";
|
|
232
259
|
/**
|
|
233
260
|
* Captures the user's natural-language intent behind each tool call on a vanilla
|
|
234
261
|
* `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
|
|
235
262
|
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
236
263
|
* handlers to surface the captured intent via `options.handler` (or, when
|
|
237
264
|
* `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
|
|
238
|
-
*
|
|
239
|
-
* Already-registered handlers are wrapped immediately; future registrations
|
|
240
|
-
* (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
|
|
241
|
-
* of calls relative to `registerTool` does not matter.
|
|
242
265
|
*/
|
|
243
266
|
const captureIntents = (server, options) => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
const marked = handlers;
|
|
250
|
-
if (marked[INSTALLED_MARKER]) return;
|
|
251
|
-
marked[INSTALLED_MARKER] = true;
|
|
252
|
-
const middleware = intentMiddleware(options);
|
|
253
|
-
const targets = new Set(["tools/list", "tools/call"]);
|
|
254
|
-
const wrap = (method, handler) => {
|
|
255
|
-
if (!targets.has(method)) return handler;
|
|
256
|
-
return async (...args) => {
|
|
257
|
-
const [request, extra] = args;
|
|
258
|
-
return middleware({
|
|
259
|
-
method,
|
|
260
|
-
params: request.params ?? {}
|
|
261
|
-
}, extra, () => handler(...args));
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
|
-
for (const [method, handler] of [...handlers]) handlers.set(method, wrap(method, handler));
|
|
265
|
-
const originalSet = handlers.set.bind(handlers);
|
|
266
|
-
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
|
+
});
|
|
267
272
|
};
|
|
268
273
|
//#endregion
|
|
269
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.
|
|
3
|
+
"version": "0.0.0-dev.g1d08792",
|
|
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": "
|
|
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.
|
|
31
|
+
"@types/node": "^25.9.5",
|
|
32
32
|
"shx": "^0.4.0",
|
|
33
|
-
"skybridge": "^
|
|
34
|
-
"tsdown": "^0.22.
|
|
33
|
+
"skybridge": "^1.2.7",
|
|
34
|
+
"tsdown": "^0.22.5",
|
|
35
35
|
"typescript": "^6.0.3",
|
|
36
|
-
"vitest": "^4.1.
|
|
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": "
|
|
45
|
+
"test:type": "tsgo --noEmit",
|
|
46
46
|
"publish:npm": "pnpm publish --tag \"${NPM_TAG}\" --access public --no-git-checks"
|
|
47
47
|
}
|
|
48
48
|
}
|