health_check
Probe all registered Swiss grocery chain adapters with a trivial query to report their health status, latency, and capability flags. Use this to diagnose why a chain is missing from search results or plan.
Instructions
Probe each registered chain adapter with a trivial query and report status, latency, and capability flags. Use this when a chain seems missing from results or when debugging adapter problems.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chains | No | Chains to probe. Default: all configured. | |
| timeoutMs | No | Per-chain timeout in milliseconds. Default 5000. |
Implementation Reference
- src/tools/health_check.ts:26-72 (handler)The main handler function that probes each requested chain adapter with a trivial search query ('milch') and reports health status, latency, capabilities, and errors.
export async function healthCheckHandler( registry: AdapterRegistry, input: HealthCheckInput, ): Promise<{ chains: HealthCheckResult[]; summary: { healthy: number; unhealthy: number; unregistered: number } }> { const all: Chain[] = ['migros', 'coop', 'aldi', 'denner', 'lidl']; const requested = input.chains ?? all; const timeout = input.timeoutMs ?? 5000; const results = await Promise.all(requested.map(async (chain): Promise<HealthCheckResult> => { const adapter = registry.get(chain); if (!adapter) return { chain, registered: false, ok: false }; const start = Date.now(); try { const r = await Promise.race([ adapter.searchProducts({ query: TRIVIAL_QUERY, limit: 1 }), new Promise<never>((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout)), ]); const latencyMs = Date.now() - start; if (r.ok) { return { chain, registered: true, ok: true, latencyMs, capabilities: { ...adapter.capabilities }, }; } return { chain, registered: true, ok: false, latencyMs, error: { code: r.error.code, reason: 'reason' in r.error ? r.error.reason : undefined }, capabilities: { ...adapter.capabilities }, }; } catch (e) { const msg = e instanceof Error ? e.message : String(e); return { chain, registered: true, ok: false, error: { code: msg === 'timeout' ? 'timeout' : 'unavailable', reason: msg }, capabilities: { ...adapter.capabilities }, }; } })); const summary = { healthy: results.filter((r) => r.ok).length, unhealthy: results.filter((r) => r.registered && !r.ok).length, unregistered: results.filter((r) => !r.registered).length, }; return { chains: results, summary }; } - src/tools/health_check.ts:5-11 (schema)Zod schema defining the input parameters: optional chains array and optional timeout in milliseconds.
export const healthCheckSchema = z.object({ chains: z.array(z.enum(['migros', 'coop', 'aldi', 'denner', 'lidl', 'farmy', 'volgshop', 'ottos'])) .optional() .describe('Chains to probe. Default: all configured.'), timeoutMs: z.number().int().positive().max(30000).optional() .describe('Per-chain timeout in milliseconds. Default 5000.'), }).describe('Probe each registered chain adapter with a trivial query and report which are healthy. Useful for diagnosing why a particular chain is missing from search/plan results.'); - src/tools/health_check.ts:15-22 (schema)TypeScript interface describing the result structure returned per chain.
export interface HealthCheckResult { chain: Chain; registered: boolean; ok: boolean; latencyMs?: number; error?: { code: string; reason?: string }; capabilities?: Record<string, boolean>; } - src/index.ts:105-110 (registration)Tool registration in the TOOLS array, mapping name 'health_check' to its schema and handler.
{ name: 'health_check', description: 'Probe each registered chain adapter with a trivial query and report status, latency, and capability flags. Use this when a chain seems missing from results or when debugging adapter problems.', schema: healthCheckSchema, handler: healthCheckHandler, }, - scripts/probe-health-check.ts:1-11 (helper)Standalone probe script that runs the health check against all chains and prints results.
import { buildRegistry } from '../src/index.js'; import { healthCheckHandler } from '../src/tools/health_check.js'; const r = buildRegistry(); const out = await healthCheckHandler(r, {}); for (const c of out.chains) { const status = !c.registered ? 'UNREGISTERED' : c.ok ? `OK ${c.latencyMs}ms` : `FAIL (${c.error?.code}: ${c.error?.reason ?? ''})`; console.log(`${c.chain}: ${status}`); } console.log('\nSummary:', out.summary);