lookup_icd10
Search ICD-10-CM codes by diagnosis name or code. Returns the code, full description, and category for clinical documentation.
Instructions
Search ICD-10-CM codes by diagnosis name or look up a specific code. Returns code, full description, and category. Essential for clinical documentation agents.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Diagnosis name (e.g. 'major depressive disorder') or ICD-10 code (e.g. 'F33.1') | |
| limit | No | Number of results to return |
Implementation Reference
- index.js:120-165 (registration)The tool 'lookup_icd10' is registered with the MCP server on line 120 using server.tool(). It is the first tool registered.
server.tool( "lookup_icd10", "Search ICD-10-CM codes by diagnosis name or look up a specific code. Returns code, full description, and category. Essential for clinical documentation agents.", { query: z .string() .describe("Diagnosis name (e.g. 'major depressive disorder') or ICD-10 code (e.g. 'F33.1')"), limit: z .number() .int() .min(1) .max(20) .default(10) .describe("Number of results to return"), }, async ({ query, limit }) => { const url = `${ICD_BASE}/search?sf=code,name&terms=${encodeURIComponent(query)}&maxList=${limit}`; const data = await apiFetch(url); // Response: [total, codes[], null, [code, name][]] const total = data[0] || 0; const entries = data[3] || []; if (!entries.length) { return { content: [{ type: "text", text: `No ICD-10-CM codes found for "${query}".` }] }; } const rows = entries.map(([code, name]) => `- **${code}** — ${name}`); const text = [ `## ICD-10-CM Results for "${query}"`, `Found ${total} total matches, showing ${entries.length}:`, "", ...rows, "", "_Source: NIH National Library of Medicine ICD-10-CM API_" ].join("\n"); return { content: [{ type: "text", text }] }; } ); - index.js:122-134 (schema)The Zod schema defines two input parameters: 'query' (string, diagnosis name or ICD-10 code) and 'limit' (number, 1-20, default 10).
"Search ICD-10-CM codes by diagnosis name or look up a specific code. Returns code, full description, and category. Essential for clinical documentation agents.", { query: z .string() .describe("Diagnosis name (e.g. 'major depressive disorder') or ICD-10 code (e.g. 'F33.1')"), limit: z .number() .int() .min(1) .max(20) .default(10) .describe("Number of results to return"), }, - index.js:135-165 (handler)The handler function fetches from the NIH ICD-10-CM API (clinicaltables.nlm.nih.gov), parses the response, formats results as markdown, and returns them as text content.
async ({ query, limit }) => { const url = `${ICD_BASE}/search?sf=code,name&terms=${encodeURIComponent(query)}&maxList=${limit}`; const data = await apiFetch(url); // Response: [total, codes[], null, [code, name][]] const total = data[0] || 0; const entries = data[3] || []; if (!entries.length) { return { content: [{ type: "text", text: `No ICD-10-CM codes found for "${query}".` }] }; } const rows = entries.map(([code, name]) => `- **${code}** — ${name}`); const text = [ `## ICD-10-CM Results for "${query}"`, `Found ${total} total matches, showing ${entries.length}:`, "", ...rows, "", "_Source: NIH National Library of Medicine ICD-10-CM API_" ].join("\n"); return { content: [{ type: "text", text }] }; } ); - index.js:28-34 (helper)The apiFetch() utility function used by the handler to make HTTP requests to external APIs.
async function apiFetch(url) { const res = await fetch(url, { headers: { "Accept": "application/json" } }); if (!res.ok) throw new Error(`API error ${res.status}: ${url}`); return res.json(); }