UNPKG

mcpay

Version:

SDK and CLI for MCPay functionality - MCP servers with payment capabilities

133 lines 4.74 kB
export class AnalyticsHook { name = "analytics"; sink; origin; constructor(sink, origin) { this.sink = sink; this.origin = origin; } async processCallToolResult(res, req, extra) { console.log("[AnalyticsHook] processCallToolResult called", { res, req, extra }); try { // Deep clone the response to ensure we capture its state at this moment // This is important because hooks execute in reverse order, and we want to capture // the final response after all hooks (like VLayerHook) have modified it const clonedRes = JSON.parse(JSON.stringify(res)); const clonedReq = JSON.parse(JSON.stringify(req)); // Log if proof is present in the response const hasProof = clonedRes._meta && typeof clonedRes._meta === 'object' && 'vlayer/proof' in clonedRes._meta; console.log("[AnalyticsHook] Storing response with proof:", hasProof, hasProof ? "Proof present" : "No proof"); this.sink({ request_id: extra?.requestId, server_id: extra?.serverId, origin: this.origin, method: req.method, meta: { res: clonedRes, req: clonedReq, extra }, ts: new Date().toISOString(), }); } catch (error) { console.error("[AnalyticsHook] Error storing analytics:", error); } return { resultType: "continue", response: res }; } async processInitializeResult(res, req, extra) { try { this.sink({ request_id: extra?.requestId, server_id: extra?.serverId, origin: this.origin, method: req.method, meta: { res, req, extra }, ts: new Date().toISOString(), }); } catch { } return { resultType: "continue", response: res }; } async processListToolsResult(res, req, extra) { try { this.sink({ request_id: extra?.requestId, server_id: extra?.serverId, origin: this.origin, method: req.method, meta: { res, req, extra }, ts: new Date().toISOString(), }); } catch { } return { resultType: "continue", response: res }; } async processListPromptsResult(res, req, extra) { try { this.sink({ request_id: extra?.requestId, server_id: extra?.serverId, origin: this.origin, method: req.method, meta: { res, req, extra }, ts: new Date().toISOString(), }); } catch { } return { resultType: "continue", response: res }; } async processListResourcesResult(res, req, extra) { try { this.sink({ request_id: extra?.requestId, server_id: extra?.serverId, origin: this.origin, method: req.method, meta: { res, req, extra }, ts: new Date().toISOString(), }); } catch { } return { resultType: "continue", response: res }; } async processListResourceTemplatesResult(res, req, extra) { try { this.sink({ request_id: extra?.requestId, server_id: extra?.serverId, origin: this.origin, method: req.method, meta: { res, req, extra }, ts: new Date().toISOString(), }); } catch { } return { resultType: "continue", response: res }; } async processReadResourceResult(res, req, extra) { try { this.sink({ request_id: extra?.requestId, server_id: extra?.serverId, origin: this.origin, method: req.method, meta: { res, req, extra }, ts: new Date().toISOString(), }); } catch { } return { resultType: "continue", response: res }; } async processOtherResult(res, req, extra) { try { this.sink({ request_id: extra?.requestId, server_id: extra?.serverId, origin: this.origin, method: req?.method || "other", meta: { res, req, extra }, ts: new Date().toISOString(), }); } catch { } return { resultType: "continue", response: res }; } } //# sourceMappingURL=analytics-hook.js.map