tool-telemetry.mjs
38 lines 1.2 KB
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 17 hours ago
1 /**
2 * MCP Phase H — progress notifications (notifications/progress) and logging (notifications/message).
3 * @see docs/MCP-PHASE-H.md
4 */
5
6 /**
7 * @param {Record<string, unknown>} extra - McpServer tool handler extra (from SDK)
8 * @param {{ progress: number, total?: number, message?: string }} params
9 */
10 export async function sendMcpToolProgress(extra, params) {
11 const token = extra?._meta?.progressToken;
12 if (token === undefined || typeof extra?.sendNotification !== 'function') return;
13 try {
14 await extra.sendNotification({
15 method: 'notifications/progress',
16 params: {
17 progressToken: token,
18 progress: params.progress,
19 ...(params.total !== undefined ? { total: params.total } : {}),
20 ...(params.message ? { message: params.message } : {}),
21 },
22 });
23 } catch (_) {
24 /* client may not support progress */
25 }
26 }
27
28 /**
29 * @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} mcpServer
30 * @param {'debug'|'info'|'notice'|'warning'|'error'|'critical'|'alert'|'emergency'} level
31 * @param {unknown} data
32 */
33 export async function sendMcpLog(mcpServer, level, data) {
34 if (!mcpServer?.isConnected?.()) return;
35 try {
36 await mcpServer.sendLoggingMessage({ level, data });
37 } catch (_) {}
38 }
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 17 hours ago