{
  "markdown": "# validar-codigo-medico\n\n[![validar-codigo-medico MCP server](https://glama.ai/mcp/servers/encodi/validar-codigo-medico/badges/score.svg)](https://glama.ai/mcp/servers/encodi/validar-codigo-medico)\n\nRemote MCP server (Cloudflare Workers) with one tool that validates medical codes against real data:\n\n- **`validate_medical_code`** — `system: \"icd10\"` does a real lookup against the official **billable ICD-10-CM** code catalog (FY2026, [NCHS/CDC](https://ftp.cdc.gov/pub/health_statistics/nchs/publications/ICD10CM/2026/), public domain as a work of the U.S. government) and returns the official short description. `system: \"cpt\"` validates the **real structure** of a CPT code (Category I: 5 digits; Category II: 4 digits + `F`; Category III: 4 digits + `T`) and estimates its area by public numeric range — it **doesn't** include per-code descriptions, because the CPT catalog is owned by the AMA and requires a paid license (it can't be redistributed).\n\nNo database, no persistent state between calls: each call builds a fresh `McpServer` (see `createServer()` in `src/index.ts`). The ICD-10-CM catalog (~6MB, 74,719 codes) is bundled into the Worker itself as static data (`src/tools/data/icd10cm.ts`) and parsed once per isolate into an in-memory `Map` — see `src/tools/codigoMedico.ts`.\n\n## Why CPT has no descriptions\n\nThe CPT (Current Procedural Terminology) description catalog is owned by the American Medical Association and requires a paid license to redistribute its content — unlike ICD-10-CM, which is a work of the U.S. government and therefore public domain. That's why this tool validates a CPT code's **real format** (regex + numeric range, publicly available information about the code's structure) but doesn't offer the procedure's description: that requires an AMA-licensed codebook.\n\n## Billing (x402)\n\nCharges per call via [x402](https://x402.org) — real USDC payment on **Base mainnet**, against the Coinbase Developer Platform (CDP) facilitator. The payment travels inside the MCP JSON-RPC itself (`_meta`), not as an HTTP header; see `src/payments.ts`.\n\n| Tool | Price |\n|---|---|\n| `validate_medical_code` | $0.02 USDC |\n\nAn unpaid `tools/call` returns `isError: true` with the `accepts` (network, amount, `payTo`) the client needs to pay and retry — not an unexplained exception.\n\n## Structure\n\n```\nsrc/\n  index.ts             # registers the tool in the McpServer and exposes the MCP HTTP handler\n  payments.ts          # x402 billing on Base mainnet via the CDP facilitator\n  tools/\n    codigoMedico.ts       # pure logic for validate_medical_code (testable without Workers)\n    codigoMedico.test.ts\n    data/\n      icd10cm.ts          # bundled FY2026 ICD-10-CM catalog (generated, do not edit by hand)\nscripts/\n  dev-node.ts           # dev server that runs the handler in plain Node, no wrangler\n  gen-icd10-data.mjs    # regenerates tools/data/icd10cm.ts from a new CMS/NCHS order file\n```\n\n## Updating the ICD-10-CM catalog\n\nWhen NCHS publishes a new version (new fiscal year or addenda):\n\n1. Download the \"Code Descriptions\" zip from `https://ftp.cdc.gov/pub/health_statistics/nchs/publications/ICD10CM/<YEAR>/`.\n2. Unzip it and locate `icd10cm-codes-<YEAR>.txt`.\n3. `node scripts/gen-icd10-data.mjs <path-to-txt> src/tools/data/icd10cm.ts`.\n\n## Running it locally\n\n⚠️ **Note on `wrangler dev`**: the real Cloudflare Workers runtime (`workerd`) requires **macOS 13.5+**. If your Mac has an older version, `wrangler dev` (and `npm run dev`) will fail. This project includes a plain-Node shim that runs the exact same `fetch()` handler without needing `workerd`.\n\n### 1. Install dependencies\n\n```bash\nnpm install\n```\n\n### 2. Run the unit tests\n\n```bash\nnpm test\n```\n\n### 3a. If your wrangler dev works (macOS 13.5+, Linux, Windows)\n\n```bash\nnpm run dev\n```\n\n### 3b. If `wrangler dev` fails because of the macOS version\n\n```bash\nnpm run dev:node\n```\n\nStarts at `http://localhost:8787/mcp`, reading CDP credentials from `~/.mcp-tools-factory-credentials.env` (shared across all tools in this factory).\n\n### 4. Test with curl\n\n```bash\n# 1) initialize\ncurl -s -X POST http://localhost:8787/mcp \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Accept: application/json, text/event-stream\" \\\n  -d '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-06-18\",\"capabilities\":{},\"clientInfo\":{\"name\":\"curl-test\",\"version\":\"0.0.1\"}}}'\n\n# 2) tools/list\ncurl -s -X POST http://localhost:8787/mcp \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Accept: application/json, text/event-stream\" \\\n  -d '{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/list\",\"params\":{}}'\n\n# 3) tools/call — validate_medical_code (ICD-10-CM)\ncurl -s -X POST http://localhost:8787/mcp \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Accept: application/json, text/event-stream\" \\\n  -d '{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"validate_medical_code\",\"arguments\":{\"system\":\"icd10\",\"codes\":[\"A00.0\",\"Z21\",\"does-not-exist\"]}}}'\n```\n\nResponses come as Server-Sent Events (`event: message` + `data: {...}`); the `data:` line is the usual JSON-RPC response.\n\n## Deploy and listings\n\nDeployed at `https://validar-codigo-medico.encodari.workers.dev/mcp` (Cloudflare Workers). Published on the [official MCP registry](https://registry.modelcontextprotocol.io), [Smithery](https://smithery.ai), [mcp.so](https://mcp.so), and with an open PR to [awesome-mcp-servers](https://github.com/punkpeye/awesome-mcp-servers).\n\n## What it doesn't do (yet)\n\n- Doesn't include per-code CPT descriptions (see \"Why CPT has no descriptions\" above).\n- Charges on Base mainnet with real money. To switch back to testnet (Base Sepolia, `eip155:84532`) during development, change `NETWORK` in `src/payments.ts`.\n- No database or persistent state between calls (beyond the billing config and the ICD-10-CM catalog Map, cached in memory per isolate).\n- Not medical or billing advice: this is a structural/catalog validation, not a substitute for a certified professional coder.\n",
  "bytes": 5985,
  "sha": "3d4ae9fe3e4141e92f7bda75b6d72a508b498c4d109ac5b2e05b5be9ba00a4a3",
  "repo_slug": "encodi/validar-codigo-medico",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_encodi_validar_codigo_medico_0769a7fa/readme"
}