From f70001de74485a2469644dae04a7210523ab4961 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Thu, 5 Mar 2026 14:05:03 -0800 Subject: [PATCH] =?UTF-8?q?fix(mcp-server):=20audit=20fixes=20=E2=80=94=20?= =?UTF-8?q?3=20bugs=20+=202=20new=20tools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug fixes: - lysnrai: add lysnrai.sessions.get tool (GET /sessions/:id existed but had no MCP surface) - nomgap: add nomgap.autophagyConfidence tool (POST /fasting/autophagy-confidence had no tool) - chronomind: fix syncStatus description 'paused' -> 'pending' (wrong field name) New client functions: lysnraiSessionGet, nomgapAutophagyConfidence (with typed interfaces) Root bug fixed in learning_voice_ai_agent commit 42aa931: GET /transcripts/:id was missing from backend — lysnrai.transcripts.get was always 404-ing --- services/mcp-server/src/lib/lysnrai-client.ts | 7 +++ services/mcp-server/src/lib/nomgap-client.ts | 36 ++++++++++++++ .../modules/chronomind/chronomind-tools.ts | 2 +- .../src/modules/lysnrai/lysnrai-tools.ts | 16 +++++++ .../src/modules/nomgap/nomgap-tools.ts | 48 +++++++++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) diff --git a/services/mcp-server/src/lib/lysnrai-client.ts b/services/mcp-server/src/lib/lysnrai-client.ts index 69773b66..df903775 100644 --- a/services/mcp-server/src/lib/lysnrai-client.ts +++ b/services/mcp-server/src/lib/lysnrai-client.ts @@ -111,6 +111,13 @@ export interface SessionDoc { updatedAt: string; } +export function lysnraiSessionGet( + sessionId: string, + opts: LysnraiClientOptions +): Promise { + return lysnraiFetch(`/sessions/${sessionId}`, { method: 'GET' }, opts); +} + export function lysnraiSessionsList( params: { limit?: number; offset?: number; status?: string }, opts: LysnraiClientOptions diff --git a/services/mcp-server/src/lib/nomgap-client.ts b/services/mcp-server/src/lib/nomgap-client.ts index c70f7df3..8daad2e6 100644 --- a/services/mcp-server/src/lib/nomgap-client.ts +++ b/services/mcp-server/src/lib/nomgap-client.ts @@ -101,6 +101,42 @@ export function nomgapBodyStagesList( return nomgapFetch('/fasting/stages', { method: 'GET' }, opts); } +// ── Autophagy confidence ────────────────────────────────────────────────── + +export interface AutophagyConfidenceInput { + durationHours: number; + activityLevel: 'sedentary' | 'light' | 'moderate' | 'active' | 'very_active'; + lastMealCarbs?: number; + sleepHours?: number; + completionHistory?: { totalFasts: number; completionRate: number }; + hrvData?: { restingHR?: number; hrv?: number }; +} + +export interface AutophagyConfidenceResult { + confidence: number; + label: 'unlikely' | 'possible' | 'likely' | 'very_likely' | 'near_certain'; + breakdown: { + duration: number; + meal: number; + activity: number; + sleep: number; + history: number; + hrv: number; + }; + currentStage: string; +} + +export function nomgapAutophagyConfidence( + input: AutophagyConfidenceInput, + opts: Pick +): Promise { + return nomgapFetch( + '/fasting/autophagy-confidence', + { method: 'POST', body: JSON.stringify(input) }, + opts + ); +} + // ── Push triggers ────────────────────────────────────────────────────────── export type PushTriggerType = diff --git a/services/mcp-server/src/modules/chronomind/chronomind-tools.ts b/services/mcp-server/src/modules/chronomind/chronomind-tools.ts index 262ee8e6..e9e1105b 100644 --- a/services/mcp-server/src/modules/chronomind/chronomind-tools.ts +++ b/services/mcp-server/src/modules/chronomind/chronomind-tools.ts @@ -109,7 +109,7 @@ registerTool({ registerTool({ name: 'chronomind.syncStatus', description: - 'Instant sync health check: total timers, active count, paused count, unsynced count, and last sync timestamp. Requires admin role.', + 'Instant sync health check: total timers, active count, pending count, unsynced count, and last sync timestamp. Requires admin role.', requiredRole: 'admin', inputSchema: z.object({}), async execute(_args, req) { diff --git a/services/mcp-server/src/modules/lysnrai/lysnrai-tools.ts b/services/mcp-server/src/modules/lysnrai/lysnrai-tools.ts index 69f0c32b..d3df375e 100644 --- a/services/mcp-server/src/modules/lysnrai/lysnrai-tools.ts +++ b/services/mcp-server/src/modules/lysnrai/lysnrai-tools.ts @@ -14,6 +14,7 @@ import { lysnraiTranscriptGet, lysnraiTranscriptRunExtraction, lysnraiSttGetBackendStatus, + lysnraiSessionGet, lysnraiSessionsList, lysnraiOrgsList, lysnraiOrgGet, @@ -84,6 +85,21 @@ registerTool({ }, }); +// ── lysnrai.sessions.get ────────────────────────────────────────────────── + +registerTool({ + name: 'lysnrai.sessions.get', + description: + 'Get a single dictation session by ID including its entries[], composedText, compositionHistory, and status. Requires admin role.', + requiredRole: 'admin', + inputSchema: z.object({ + sessionId: z.string().min(1).describe('Session ID (ses_… prefix)'), + }), + async execute(args, req) { + return lysnraiSessionGet(args.sessionId, { token: tokenOf(req), requestId: req.id }); + }, +}); + // ── lysnrai.sessions.list ───────────────────────────────────────────────── registerTool({ diff --git a/services/mcp-server/src/modules/nomgap/nomgap-tools.ts b/services/mcp-server/src/modules/nomgap/nomgap-tools.ts index 98f7bfea..a315c193 100644 --- a/services/mcp-server/src/modules/nomgap/nomgap-tools.ts +++ b/services/mcp-server/src/modules/nomgap/nomgap-tools.ts @@ -14,6 +14,7 @@ import { nomgapFastingGetWeeklyStats, nomgapProtocolsList, nomgapBodyStagesList, + nomgapAutophagyConfidence, nomgapPushFire, nomgapPushGetStats, nomgapPushGetPending, @@ -158,6 +159,53 @@ registerTool({ }, }); +// ── nomgap.autophagyConfidence ───────────────────────────────────────────────── + +registerTool({ + name: 'nomgap.autophagyConfidence', + description: [ + 'Calculate a personalised autophagy confidence score (0–100) given fasting duration and biometrics.', + 'Weights: duration 40%, last-meal carbs 20%, activity 15%, sleep 10%, completion history 10%, HRV 5%.', + 'Returns: confidence (0–100), label (unlikely/possible/likely/very_likely/near_certain), breakdown, currentStage.', + 'Public endpoint — no auth required on backend.', + ].join(' '), + requiredRole: 'admin', + inputSchema: z.object({ + durationHours: z.coerce.number().min(0).describe('Hours elapsed since the fast started'), + activityLevel: z + .enum(['sedentary', 'light', 'moderate', 'active', 'very_active']) + .describe('Physical activity level during the fast'), + lastMealCarbs: z.coerce + .number() + .min(0) + .optional() + .describe('Grams of carbs in the last meal before the fast'), + sleepHours: z.coerce + .number() + .min(0) + .max(24) + .optional() + .describe('Hours of sleep the previous night'), + completionHistory: z + .object({ + totalFasts: z.coerce.number().min(0), + completionRate: z.coerce.number().min(0).max(1), + }) + .optional() + .describe('Historical fasting stats (improves scoring accuracy)'), + hrvData: z + .object({ + restingHR: z.coerce.number().min(0).optional(), + hrv: z.coerce.number().min(0).optional(), + }) + .optional() + .describe('Heart rate variability data from wearable'), + }), + async execute(args, req) { + return nomgapAutophagyConfidence(args, { requestId: req.id }); + }, +}); + // ── nomgap.push.pending ─────────────────────────────────────────────────── registerTool({