icd11_hierarchy
Explore the ICD-11 classification by retrieving parent categories or child subcategories for any given code. Understand the hierarchical structure of medical conditions.
Instructions
Navigate the ICD-11 hierarchy to find parent or child entities.
Use this tool to:
Find broader categories (parents) of a condition
Find specific subtypes (children) of a condition
Understand the classification structure
Direction 'parents' returns ancestor categories, 'children' returns subcategories.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ICD-11 code to get hierarchy for | |
| direction | Yes | Direction: "parents" for ancestors, "children" for subtypes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| direction | Yes | ||
| entities | Yes |
Implementation Reference
- src/tools/icd11.ts:334-367 (handler)Handler function for icd11_hierarchy. Parses params (code, direction), calls WHO client getParents or getChildren, builds structured output and formatted text response.
async function handleICD11Hierarchy(args: Record<string, unknown>): Promise<CallToolResult> { try { const params = ICD11HierarchyParamsSchema.parse(args); const client = getWHOClient(); const entities = params.direction === 'parents' ? await client.getParents(params.code) : await client.getChildren(params.code); const structured: ICD11HierarchyOutput = { code: params.code, direction: params.direction, entities: entities.map((e) => ({ code: e.code ?? null, code_range: e.codeRange ?? null, title: e.title?.['@value'] ?? 'Unknown', uri: e['@id'], })), }; const formatted = formatHierarchyList(entities, params.direction); return { content: [{ type: 'text', text: `## ICD-11 Hierarchy for ${params.code}\n\n${formatted}`, }], structuredContent: structured, }; } catch (error) { return handleToolError(error); } } - src/types/index.ts:122-133 (schema)Output schema (ICD11HierarchyOutputSchema) defining the structured content shape: code, direction, and entities array with code, code_range, title, uri.
export const ICD11HierarchyOutputSchema = z.object({ code: z.string(), direction: z.enum(['parents', 'children']), entities: z.array( z.object({ code: z.string().nullable(), code_range: z.string().nullable(), title: z.string(), uri: z.string(), }), ), }); - src/types/index.ts:59-64 (schema)Input schema (ICD11HierarchyParamsSchema) with required 'code' (string) and 'direction' (enum: parents/children).
export const ICD11HierarchyParamsSchema = z.object({ code: z.string().min(1).describe('ICD-11 code to get hierarchy for'), direction: z .enum(['parents', 'children']) .describe('Direction: "parents" for ancestors, "children" for subtypes'), }); - src/tools/icd11.ts:484-484 (registration)Registration of icd11HierarchyTool with handleICD11Hierarchy via toolRegistry.
toolRegistry.register(icd11HierarchyTool, handleICD11Hierarchy); - src/tools/icd11.ts:204-220 (helper)Helper function formatHierarchyList that formats entities into a user-readable bullet list.
function formatHierarchyList(entities: ICD11EntityResponse[], direction: string): string { if (entities.length === 0) { return `No ${direction} found for this entity.`; } const lines: string[] = []; lines.push(`## ${direction.charAt(0).toUpperCase() + direction.slice(1)} (${entities.length})`); lines.push(''); for (const entity of entities) { const title = entity.title?.['@value'] || 'Unknown'; const code = entity.code || entity.codeRange || 'No code'; lines.push(`- **${code}** - ${title}`); } return lines.join('\n'); }