@alpic-ai/insights 0.0.0-dev.91b6509 → 0.0.0-dev.91e166c
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 +1 -22
- package/dist/index.mjs +3 -80
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -51,25 +51,4 @@ declare function intentMiddleware(options?: IntentMiddlewareOptions): McpMiddlew
|
|
|
51
51
|
*/
|
|
52
52
|
declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
|
|
53
53
|
//#endregion
|
|
54
|
-
|
|
55
|
-
interface FeedbackData {
|
|
56
|
-
toolName?: string;
|
|
57
|
-
message: string;
|
|
58
|
-
}
|
|
59
|
-
interface FeedbackMiddlewareOptions {
|
|
60
|
-
/**
|
|
61
|
-
* Custom handler invoked with the user's feedback. When provided, the middleware still attaches the feedback to the response `_meta`.
|
|
62
|
-
* The handler runs **in addition to** Alpic's dashboard delivery, feedback are still captured when deployed on Alpic.
|
|
63
|
-
*/
|
|
64
|
-
handler?: (feedback: FeedbackData) => Promise<void> | void;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Lets MCP server builders collect qualitative feedback from end users about their
|
|
68
|
-
* tool/server. Injects a `send_feedback` tool at `tools/list` time and intercepts calls
|
|
69
|
-
* to it at `tools/call` time. The tool has no handler on the server. The middleware
|
|
70
|
-
* short-circuits the call and either invokes the provided `handler` or attaches the
|
|
71
|
-
* feedback to the response `_meta`.
|
|
72
|
-
*/
|
|
73
|
-
declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMiddlewareFn;
|
|
74
|
-
//#endregion
|
|
75
|
-
export { type FeedbackData, type FeedbackMiddlewareOptions, type IntentMiddlewareOptions, type McpMiddlewareFn, type PromptData, captureIntents, feedbackMiddleware, intentMiddleware };
|
|
54
|
+
export { type IntentMiddlewareOptions, type McpMiddlewareFn, type PromptData, captureIntents, intentMiddleware };
|
package/dist/index.mjs
CHANGED
|
@@ -1,80 +1,4 @@
|
|
|
1
1
|
import { CallToolRequestSchema, CallToolResultSchema, ListToolsResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
//#region src/feedback-middleware.ts
|
|
3
|
-
const FEEDBACK_TOOL_NAME = "send_feedback";
|
|
4
|
-
const FEEDBACK_TOOL_DESCRIPTION = "Send the user's 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 MUST ask the user for explicit consent before calling this tool. You can proactively suggest sending feedback when something didn't work well, but never call without consent. ";
|
|
5
|
-
const FEEDBACK_RESPONSE_TEXT = "Feedback received. Thanks!";
|
|
6
|
-
/**
|
|
7
|
-
* Lets MCP server builders collect qualitative feedback from end users about their
|
|
8
|
-
* tool/server. Injects a `send_feedback` tool at `tools/list` time and intercepts calls
|
|
9
|
-
* to it at `tools/call` time. The tool has no handler on the server. The middleware
|
|
10
|
-
* short-circuits the call and either invokes the provided `handler` or attaches the
|
|
11
|
-
* feedback to the response `_meta`.
|
|
12
|
-
*/
|
|
13
|
-
function feedbackMiddleware(options) {
|
|
14
|
-
return async (request, _extra, next) => {
|
|
15
|
-
const metaKeyName = process.env.ALPIC_FEEDBACK_META_KEY;
|
|
16
|
-
if (request.method === "tools/list") {
|
|
17
|
-
const rawResult = await next();
|
|
18
|
-
const parsed = ListToolsResultSchema.safeParse(rawResult);
|
|
19
|
-
if (!parsed.success) return rawResult;
|
|
20
|
-
if (parsed.data.tools.some((tool) => tool.name === "send_feedback")) return parsed.data;
|
|
21
|
-
parsed.data.tools.push({
|
|
22
|
-
name: FEEDBACK_TOOL_NAME,
|
|
23
|
-
description: FEEDBACK_TOOL_DESCRIPTION,
|
|
24
|
-
inputSchema: {
|
|
25
|
-
type: "object",
|
|
26
|
-
properties: {
|
|
27
|
-
tool_name: {
|
|
28
|
-
type: "string",
|
|
29
|
-
description: "Name of the tool the feedback is about, when applicable."
|
|
30
|
-
},
|
|
31
|
-
message: {
|
|
32
|
-
type: "string",
|
|
33
|
-
description: "The user's feedback content."
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
required: ["message"]
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return parsed.data;
|
|
40
|
-
}
|
|
41
|
-
if (request.method !== "tools/call") return next();
|
|
42
|
-
const parsedRequest = CallToolRequestSchema.safeParse(request);
|
|
43
|
-
if (!parsedRequest.success || parsedRequest.data.params.name !== "send_feedback") return next();
|
|
44
|
-
const args = parsedRequest.data.params.arguments ?? {};
|
|
45
|
-
const message = typeof args.message === "string" ? args.message.trim() : void 0;
|
|
46
|
-
const rawToolName = typeof args.tool_name === "string" ? args.tool_name.trim() : "";
|
|
47
|
-
const toolName = rawToolName.length > 0 ? rawToolName : void 0;
|
|
48
|
-
if (message === void 0 || message.length === 0) return {
|
|
49
|
-
content: [{
|
|
50
|
-
type: "text",
|
|
51
|
-
text: "Feedback ignored — `message` is required."
|
|
52
|
-
}],
|
|
53
|
-
isError: true
|
|
54
|
-
};
|
|
55
|
-
const feedback = toolName !== void 0 ? {
|
|
56
|
-
toolName,
|
|
57
|
-
message
|
|
58
|
-
} : { message };
|
|
59
|
-
if (options?.handler) try {
|
|
60
|
-
await options.handler(feedback);
|
|
61
|
-
} catch (error) {
|
|
62
|
-
console.error("Error calling feedback handler", error);
|
|
63
|
-
}
|
|
64
|
-
if (metaKeyName) return {
|
|
65
|
-
content: [{
|
|
66
|
-
type: "text",
|
|
67
|
-
text: FEEDBACK_RESPONSE_TEXT
|
|
68
|
-
}],
|
|
69
|
-
_meta: { [metaKeyName]: feedback }
|
|
70
|
-
};
|
|
71
|
-
return { content: [{
|
|
72
|
-
type: "text",
|
|
73
|
-
text: FEEDBACK_RESPONSE_TEXT
|
|
74
|
-
}] };
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
2
|
//#region src/intent-middleware.ts
|
|
79
3
|
const USER_INTENT_FIELD = "user_intent";
|
|
80
4
|
/**
|
|
@@ -84,17 +8,16 @@ const USER_INTENT_FIELD = "user_intent";
|
|
|
84
8
|
* (the server has no other way to access it).
|
|
85
9
|
*/
|
|
86
10
|
function intentMiddleware(options) {
|
|
11
|
+
const metaKeyName = process.env.ALPIC_INTENT_META_KEY;
|
|
87
12
|
const argumentNameOverride = options?.argumentNameOverride ?? {};
|
|
88
13
|
const toolsFilter = options?.tools ? new Set(options.tools) : null;
|
|
89
14
|
return async (request, _extra, next) => {
|
|
90
|
-
const metaKeyName = process.env.ALPIC_INTENT_META_KEY;
|
|
91
15
|
if (request.method === "tools/list") {
|
|
92
16
|
const rawResult = await next();
|
|
93
17
|
const parsed = ListToolsResultSchema.safeParse(rawResult);
|
|
94
18
|
if (!parsed.success) return rawResult;
|
|
95
19
|
for (const tool of parsed.data.tools) {
|
|
96
20
|
if (toolsFilter && !toolsFilter.has(tool.name)) continue;
|
|
97
|
-
if (tool.name === "send_feedback") continue;
|
|
98
21
|
if (argumentNameOverride[tool.name] != null) continue;
|
|
99
22
|
tool.inputSchema.properties = {
|
|
100
23
|
...tool.inputSchema.properties,
|
|
@@ -144,7 +67,7 @@ Examples:
|
|
|
144
67
|
const parsedRequest = CallToolRequestSchema.safeParse(request);
|
|
145
68
|
if (!parsedRequest.success) return next();
|
|
146
69
|
const toolName = parsedRequest.data.params.name;
|
|
147
|
-
if (toolsFilter && !toolsFilter.has(toolName)
|
|
70
|
+
if (toolsFilter && !toolsFilter.has(toolName)) {
|
|
148
71
|
const args = parsedRequest.data.params.arguments ?? {};
|
|
149
72
|
if (USER_INTENT_FIELD in args) {
|
|
150
73
|
delete args[USER_INTENT_FIELD];
|
|
@@ -220,4 +143,4 @@ const captureIntents = (server, options) => {
|
|
|
220
143
|
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
221
144
|
};
|
|
222
145
|
//#endregion
|
|
223
|
-
export { captureIntents,
|
|
146
|
+
export { captureIntents, intentMiddleware };
|