@alpic-ai/insights 0.0.0-dev.gff0a01e → 0.0.0-dev.gff8f374
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 +29 -15
- package/dist/index.mjs +67 -5
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -37,20 +37,6 @@ type McpMiddlewareFn = (request: {
|
|
|
37
37
|
*/
|
|
38
38
|
declare function intentMiddleware(options?: IntentMiddlewareOptions): McpMiddlewareFn;
|
|
39
39
|
//#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
40
|
//#region src/feedback-middleware.d.ts
|
|
55
41
|
interface FeedbackData {
|
|
56
42
|
content: string;
|
|
@@ -72,4 +58,32 @@ interface FeedbackMiddlewareOptions {
|
|
|
72
58
|
*/
|
|
73
59
|
declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMiddlewareFn;
|
|
74
60
|
//#endregion
|
|
75
|
-
|
|
61
|
+
//#region src/capture-feedback.d.ts
|
|
62
|
+
/**
|
|
63
|
+
* Injects a `send_feedback` tool into a vanilla `@modelcontextprotocol/sdk`
|
|
64
|
+
* server and captures feedback submissions. Accepts the high-level `McpServer`
|
|
65
|
+
* or the low-level `Server` and patches the `tools/list` and `tools/call`
|
|
66
|
+
* request handlers to surface captured feedback via `options.handler` (or,
|
|
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.
|
|
72
|
+
*/
|
|
73
|
+
declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMiddlewareOptions) => void;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/capture-intents.d.ts
|
|
76
|
+
/**
|
|
77
|
+
* Captures the user's natural-language intent behind each tool call on a vanilla
|
|
78
|
+
* `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
|
|
79
|
+
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
80
|
+
* handlers to surface the captured intent via `options.handler` (or, when
|
|
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.
|
|
86
|
+
*/
|
|
87
|
+
declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
|
|
88
|
+
//#endregion
|
|
89
|
+
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: false,
|
|
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,58 @@ 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 {
|
|
72
|
-
|
|
73
|
-
|
|
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/capture-feedback.ts
|
|
102
|
+
const INSTALLED_MARKER$1 = "__alpicCaptureFeedbackInstalled";
|
|
103
|
+
/**
|
|
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`).
|
|
109
|
+
*
|
|
110
|
+
* Already-registered handlers are wrapped immediately; future registrations
|
|
111
|
+
* are wrapped via a `Map.set` proxy so order of calls relative to
|
|
112
|
+
* `registerTool` does not matter.
|
|
113
|
+
*/
|
|
114
|
+
const captureFeedback = (server, options) => {
|
|
115
|
+
const handlers = ("server" in server ? server.server : server)?._requestHandlers;
|
|
116
|
+
if (!(handlers instanceof Map)) {
|
|
117
|
+
console.warn("@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected `_requestHandlers` Map on Server. Feedback capture disabled.");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const marked = handlers;
|
|
121
|
+
if (marked[INSTALLED_MARKER$1]) return;
|
|
122
|
+
marked[INSTALLED_MARKER$1] = true;
|
|
123
|
+
const middleware = feedbackMiddleware(options);
|
|
124
|
+
const targets = new Set(["tools/list", "tools/call"]);
|
|
125
|
+
const wrap = (method, handler) => {
|
|
126
|
+
if (!targets.has(method)) return handler;
|
|
127
|
+
return async (...args) => {
|
|
128
|
+
const [request, extra] = args;
|
|
129
|
+
return middleware({
|
|
130
|
+
method,
|
|
131
|
+
params: request.params ?? {}
|
|
132
|
+
}, extra, () => handler(...args));
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
for (const [method, handler] of [...handlers]) handlers.set(method, wrap(method, handler));
|
|
136
|
+
const originalSet = handlers.set.bind(handlers);
|
|
137
|
+
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
138
|
+
};
|
|
139
|
+
//#endregion
|
|
78
140
|
//#region src/intent-middleware.ts
|
|
79
141
|
const USER_INTENT_FIELD = "user_intent";
|
|
80
142
|
/**
|
|
@@ -220,4 +282,4 @@ const captureIntents = (server, options) => {
|
|
|
220
282
|
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
221
283
|
};
|
|
222
284
|
//#endregion
|
|
223
|
-
export { captureIntents, feedbackMiddleware, intentMiddleware };
|
|
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.gff8f374",
|
|
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.3",
|
|
32
32
|
"shx": "^0.4.0",
|
|
33
|
-
"skybridge": "^
|
|
34
|
-
"tsdown": "^0.22.
|
|
33
|
+
"skybridge": "^1.1.0",
|
|
34
|
+
"tsdown": "^0.22.2",
|
|
35
35
|
"typescript": "^6.0.3",
|
|
36
|
-
"vitest": "^4.1.
|
|
36
|
+
"vitest": "^4.1.8",
|
|
37
37
|
"zod": "^4.4.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|