Files
HealthLog/src/lib/mcp/index.ts
T
Marc-André Bombeck cfffb693c3 feat(mcp): add deep-value reads and a doctor-visit prompt
Expose four read-only relational tools and one prompt over the MCP wire,
each a thin re-export of an existing server-authoritative engine — no new
statistics, no new business logic:

- get_correlation: the FDR-controlled, lag-aware association between two
  named metrics, selected out of the existing correlation discovery the
  Coach and the insight route already run. Descriptive, never causal.
- compare_metric: two metrics over the same trailing window, or one metric
  across two trailing windows, computed over the WMY rollup readers with a
  delta only when both sides share a unit.
- get_metric_baseline: where today's reading sits against the user's own
  usual range (median ± robust deviation) plus the strongest lagged driver,
  reusing the metric-page baseline builder. Honest-null below the learning
  floor — never a fabricated range.
- detect_changepoints: level shifts over the rollup tier via a small in-repo
  CUSUM binary segmentation with a high firing bar.
- doctor_visit_summary prompt: a structured, grounded visit-prep summary
  assembled from the doctor-report data path so the numbers match the
  exported PDF, with the grounding framing injected once — data and context
  only, no diagnosis or verdict.

Every tool returns values, units, reference bands and provenance, declares
read-only / non-destructive / closed-world annotations plus an output schema,
and reports { present: false } for absence. All reads stay session-narrowed
and read-only; the existing security posture is unchanged.
2026-06-27 15:34:11 +02:00

41 lines
1.1 KiB
TypeScript

/**
* HealthLog MCP server — barrel.
*
* A read-only-by-default Model Context Protocol surface that re-exports
* HealthLog's existing server-authoritative read paths over the MCP wire, so a
* user can query their own health data from any MCP-capable assistant. The tool
* / resource layer here is transport-agnostic; transports (stdio now, remote
* `/mcp` later) attach to `createMcpServer(ctx)`.
*/
export { createMcpServer, MCP_SERVER_NAME, MCP_SERVER_VERSION } from "./server";
export { resolveMcpAuthContext, type McpAuthContext } from "./auth";
export { MCP_TOOLS, MCP_TOOL_NAMES, type McpToolDefinition } from "./tools";
export {
MCP_RESOURCES,
MCP_RESOURCE_URIS,
type McpResourceDefinition,
} from "./resources";
export {
MCP_PROMPTS,
MCP_PROMPT_NAMES,
type McpPromptDefinition,
type McpPromptResult,
type McpPromptMessage,
} from "./prompts";
export {
getCorrelation,
compareMetric,
getMetricBaseline,
detectChangepoints,
resolveRichMetric,
type RichMetric,
} from "./rich-reads";
export {
SCOPE_HEALTH_READ,
SCOPE_HEALTH_WRITE,
SCOPE_WILDCARD,
tokenAllowsRead,
tokenAllowsWrite,
sessionBinding,
} from "./scopes";