@cyanheads/medical-codes-mcp-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/AGENTS.md +375 -0
  2. package/CLAUDE.md +375 -0
  3. package/Dockerfile +124 -0
  4. package/LICENSE +201 -0
  5. package/README.md +328 -0
  6. package/changelog/0.1.x/0.1.0.md +24 -0
  7. package/changelog/template.md +127 -0
  8. package/data/medical-codes.db +0 -0
  9. package/dist/config/server-config.d.ts +23 -0
  10. package/dist/config/server-config.d.ts.map +1 -0
  11. package/dist/config/server-config.js +51 -0
  12. package/dist/config/server-config.js.map +1 -0
  13. package/dist/index.d.ts +9 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +54 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/mcp-server/tools/definitions/_render.d.ts +26 -0
  18. package/dist/mcp-server/tools/definitions/_render.d.ts.map +1 -0
  19. package/dist/mcp-server/tools/definitions/_render.js +45 -0
  20. package/dist/mcp-server/tools/definitions/_render.js.map +1 -0
  21. package/dist/mcp-server/tools/definitions/browse-hierarchy.tool.d.ts +51 -0
  22. package/dist/mcp-server/tools/definitions/browse-hierarchy.tool.d.ts.map +1 -0
  23. package/dist/mcp-server/tools/definitions/browse-hierarchy.tool.js +131 -0
  24. package/dist/mcp-server/tools/definitions/browse-hierarchy.tool.js.map +1 -0
  25. package/dist/mcp-server/tools/definitions/check-code.tool.d.ts +42 -0
  26. package/dist/mcp-server/tools/definitions/check-code.tool.d.ts.map +1 -0
  27. package/dist/mcp-server/tools/definitions/check-code.tool.js +91 -0
  28. package/dist/mcp-server/tools/definitions/check-code.tool.js.map +1 -0
  29. package/dist/mcp-server/tools/definitions/get-code.tool.d.ts +52 -0
  30. package/dist/mcp-server/tools/definitions/get-code.tool.d.ts.map +1 -0
  31. package/dist/mcp-server/tools/definitions/get-code.tool.js +165 -0
  32. package/dist/mcp-server/tools/definitions/get-code.tool.js.map +1 -0
  33. package/dist/mcp-server/tools/definitions/list-systems.tool.d.ts +21 -0
  34. package/dist/mcp-server/tools/definitions/list-systems.tool.d.ts.map +1 -0
  35. package/dist/mcp-server/tools/definitions/list-systems.tool.js +81 -0
  36. package/dist/mcp-server/tools/definitions/list-systems.tool.js.map +1 -0
  37. package/dist/mcp-server/tools/definitions/map-codes.tool.d.ts +55 -0
  38. package/dist/mcp-server/tools/definitions/map-codes.tool.d.ts.map +1 -0
  39. package/dist/mcp-server/tools/definitions/map-codes.tool.js +132 -0
  40. package/dist/mcp-server/tools/definitions/map-codes.tool.js.map +1 -0
  41. package/dist/mcp-server/tools/definitions/search-codes.tool.d.ts +48 -0
  42. package/dist/mcp-server/tools/definitions/search-codes.tool.d.ts.map +1 -0
  43. package/dist/mcp-server/tools/definitions/search-codes.tool.js +133 -0
  44. package/dist/mcp-server/tools/definitions/search-codes.tool.js.map +1 -0
  45. package/dist/services/code-index/code-index-service.d.ts +185 -0
  46. package/dist/services/code-index/code-index-service.d.ts.map +1 -0
  47. package/dist/services/code-index/code-index-service.js +530 -0
  48. package/dist/services/code-index/code-index-service.js.map +1 -0
  49. package/dist/services/code-index/detect.d.ts +23 -0
  50. package/dist/services/code-index/detect.d.ts.map +1 -0
  51. package/dist/services/code-index/detect.js +58 -0
  52. package/dist/services/code-index/detect.js.map +1 -0
  53. package/dist/services/code-index/schema.d.ts +55 -0
  54. package/dist/services/code-index/schema.d.ts.map +1 -0
  55. package/dist/services/code-index/schema.js +129 -0
  56. package/dist/services/code-index/schema.js.map +1 -0
  57. package/dist/services/code-index/types.d.ts +71 -0
  58. package/dist/services/code-index/types.d.ts.map +1 -0
  59. package/dist/services/code-index/types.js +24 -0
  60. package/dist/services/code-index/types.js.map +1 -0
  61. package/package.json +92 -0
  62. package/server.json +125 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Casey Hand @cyanheads
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,328 @@
1
+ <div align="center">
2
+ <h1>medical-codes-mcp-server</h1>
3
+ <p><b>Decode, search, validate, and crosswalk US medical codes — ICD-10-CM, ICD-10-PCS, HCPCS Level II — over a bundled offline index via MCP. STDIO or Streamable HTTP.</b>
4
+ <div>6 Tools</div>
5
+ </p>
6
+ </div>
7
+
8
+ <div align="center">
9
+
10
+ [![Version](https://img.shields.io/badge/Version-0.1.0-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^1.29.0-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/medical-codes-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/medical-codes-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^6.0.3-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.3-blueviolet.svg?style=flat-square)](https://bun.sh/)
11
+
12
+ </div>
13
+
14
+ <div align="center">
15
+
16
+ [![Install in Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en/install-mcp?name=medical-codes-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvbWVkaWNhbC1jb2Rlcy1tY3Atc2VydmVyIl19) [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22medical-codes-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads/medical-codes-mcp-server%22%5D%7D)
17
+
18
+ </div>
19
+
20
+ <div align="center">
21
+
22
+ [![Framework](https://img.shields.io/badge/Built%20on-@cyanheads/mcp--ts--core-67E8F9?style=flat-square)](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)
23
+
24
+ </div>
25
+
26
+ ---
27
+
28
+ > [!NOTE]
29
+ > **Informational, not clinical or coding advice.** This server returns official code descriptions and billable/validity flags from public-domain federal releases to help you decode and look up codes. It is **not** medical advice, and a `valid_billable` result is **not** a coding or reimbursement decision. Always verify codes against the official source releases (CMS, CDC/NCHS, NLM) and your payer's rules before submitting a claim. The bundled data is only as current as the release baked into the build — call `medcode_list_systems` to see exactly which releases are active.
30
+
31
+ ## How it works
32
+
33
+ The code data is **bundled inside the package** — a single SQLite + FTS5 database (`data/medical-codes.db`) built at package-build time from the canonical federal source files and shipped in the npm tarball and Docker image. The server opens it **read-only** at startup and answers every tool call from disk.
34
+
35
+ That means the server is **offline, keyless, and deterministic**: no runtime network calls, no API key, no rate limit, single-tenant. The same inputs against the same bundled build always return the same output.
36
+
37
+ ### Bundled code systems
38
+
39
+ Only freely-redistributable, public-domain US federal code sets are bundled:
40
+
41
+ | System | Source | Covers |
42
+ |:---|:---|:---|
43
+ | **ICD-10-CM** | [CDC/NCHS](https://www.cdc.gov/nchs/icd/icd-10-cm/index.html) — US federal, public domain | Diagnoses (billable leaf codes + non-billable category headers) |
44
+ | **ICD-10-PCS** | [CMS](https://www.cms.gov/medicare/coding-billing/icd-10-codes) — US federal, public domain | Inpatient procedures (axis-based 7-character codes) |
45
+ | **HCPCS Level II** | [CMS](https://www.cms.gov/medicare/coding-billing/healthcare-common-procedure-system) — US federal, public domain | Supplies, drugs, and non-physician services |
46
+
47
+ **RxNorm** ([NLM](https://www.nlm.nih.gov/research/umls/rxnorm/), public domain) — the drug-crosswalk layer (drug name ↔ RXCUI ↔ NDC, ingredients, brands) — is **not bundled yet**; it lands in a later release. Until then, `medcode_map_codes`' drug directions return a `direction_unavailable` error, and the hierarchy directions (`parents`/`children`) work today.
48
+
49
+ CPT (AMA copyright) and SNOMED CT / LOINC (UMLS-license-gated) are intentionally absent — they are not freely redistributable, so they cannot ship in an offline package.
50
+
51
+ **US scope.** ICD-10-CM and ICD-10-PCS are the US clinical modifications, not the WHO ICD-10/ICD-11 base or another country's national modification.
52
+
53
+ ## Tools
54
+
55
+ Six tools organized goal-first — one per user action, with a `system` discriminator instead of a per-system tool for each of the bundled code sets. All are read-only.
56
+
57
+ | Tool | Description |
58
+ |:---|:---|
59
+ | `medcode_get_code` | Decode 1–50 codes to their official descriptions. Auto-detects the system per code; partial-success `found` / `notFound`. |
60
+ | `medcode_search_codes` | Full-text search over official descriptions — go from a clinical description to the code. |
61
+ | `medcode_check_code` | Validate a code's existence, currency, and billability, with a `whyNot` for non-billable/terminated cases. |
62
+ | `medcode_map_codes` | Crosswalk a code within its hierarchy (`parents`/`children`); RxNorm drug directions land in a later release. |
63
+ | `medcode_browse_hierarchy` | Walk a system's hierarchy for discovery without a search term. |
64
+ | `medcode_list_systems` | List bundled systems with release identifiers, effective dates, and code counts (provenance). |
65
+
66
+ ### `medcode_get_code`
67
+
68
+ Decode one or more codes seen in a claim, EHR field, or another health server's output. The 80% entry point.
69
+
70
+ - Accepts 1–50 codes; mixed systems are fine — each code's system is detected independently from its shape
71
+ - Partial success: resolved codes in `found`, unresolved in `notFound` with a per-code reason, so one bad code never fails the batch
72
+ - An explicit `system` overrides auto-detection when a value is genuinely ambiguous (an ambiguous code lists its `candidateSystems`)
73
+ - `includeHierarchy` attaches each code's parent and immediate children
74
+ - The resolved `system` is echoed on every result for chaining into `medcode_map_codes` or a billability check
75
+
76
+ ---
77
+
78
+ ### `medcode_search_codes`
79
+
80
+ Find codes whose official descriptions match a described concept — the reverse of `medcode_get_code`.
81
+
82
+ - Every search term must appear (prefix-matched), so `"diabetic neuropathy"` returns codes mentioning both
83
+ - Filter by `system`, `billableOnly` (exclude headers/categories), and `chapter`
84
+ - Ranked by full-text relevance; results echo the resolved system per row
85
+ - Discloses truncation when the result hits the cap, and returns an explicit notice (with the parsed query) when nothing matched
86
+
87
+ ---
88
+
89
+ ### `medcode_check_code`
90
+
91
+ Validate whether a code is safe to submit, before a claim goes out.
92
+
93
+ - Discriminated status: `valid_billable`, `valid_not_billable`, `valid_header`, or `terminated`
94
+ - A `whyNot` string explains the non-billable and terminated cases (e.g. "valid ICD-10-CM category but not billable — submit a more specific child code")
95
+ - Validity vs. existence is split: a non-billable or terminated code is a **successful** result with a `whyNot`, not an error — only a code absent from every bundled system raises `unknown_code`
96
+
97
+ ---
98
+
99
+ ### `medcode_map_codes`
100
+
101
+ Crosswalk a code across systems and within a hierarchy.
102
+
103
+ - Hierarchy directions (available now): `parents` and `children` walk a code's prefix hierarchy (ICD-10-CM / HCPCS; ICD-10-PCS codes have no prefix parent)
104
+ - Drug directions (`name_to_rxcui`, `ndc_to_rxcui`, `rxcui_to_ndc`, `rxcui_to_ingredients`, `rxcui_to_brands`) are RxNorm-backed and return `direction_unavailable` until RxNorm is bundled in a later release
105
+ - Every result carries `source` provenance (which system or edge answered) so a chained call uses the right identifier
106
+
107
+ ---
108
+
109
+ ### `medcode_browse_hierarchy`
110
+
111
+ Orient in an unfamiliar system or enumerate a category's specific codes, without a search term.
112
+
113
+ - With no `node`: top-level entries (ICD-10-CM categories, HCPCS range buckets, or ICD-10-PCS first-axis values)
114
+ - With a `node`: its immediate children
115
+ - ICD-10-CM and HCPCS use a prefix hierarchy (a shorter code is the parent of a longer one); ICD-10-PCS is axis-based — each of the 7 characters is an independent axis, so browsing returns valid next-position axis values, not prefix children
116
+
117
+ ## Features
118
+
119
+ Built on [`@cyanheads/mcp-ts-core`](https://www.npmjs.com/package/@cyanheads/mcp-ts-core):
120
+
121
+ - Declarative tool definitions — single file per tool, framework handles registration and validation
122
+ - Unified error handling — handlers throw, framework catches, classifies, and formats
123
+ - Typed per-tool error contracts — capable clients preview failure modes from `tools/list`
124
+ - Structured logging with optional OpenTelemetry tracing
125
+ - STDIO and Streamable HTTP transports
126
+
127
+ Domain-specific:
128
+
129
+ - Bundled SQLite + FTS5 index — offline, keyless, deterministic; no runtime network I/O, no rate limit
130
+ - Code-shape auto-detection routes a code to its system; an explicit `system` disambiguates collisions
131
+ - Real billable/validity signal from the source releases — the order-file billable flag drives `medcode_check_code`, not a heuristic
132
+
133
+ Agent-friendly output:
134
+
135
+ - Provenance on every response — the resolved `system` is echoed for chaining, and `medcode_list_systems` reports exactly which release is baked into the running build
136
+ - Graceful partial failure — `medcode_get_code` returns per-code `found` / `notFound` rows instead of failing the batch
137
+ - Discriminated output contracts — `medcode_check_code`'s typed status and `medcode_map_codes`' `source` let callers branch on data, not string parsing
138
+
139
+ ## Getting started
140
+
141
+ This server ships with the code database bundled — there is no API key to obtain and nothing to download at runtime. Add the following to your MCP client configuration file.
142
+
143
+ ```json
144
+ {
145
+ "mcpServers": {
146
+ "medical-codes-mcp-server": {
147
+ "type": "stdio",
148
+ "command": "bunx",
149
+ "args": ["@cyanheads/medical-codes-mcp-server@latest"],
150
+ "env": {
151
+ "MCP_TRANSPORT_TYPE": "stdio",
152
+ "MCP_LOG_LEVEL": "info"
153
+ }
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ Or with npx (no Bun required):
160
+
161
+ ```json
162
+ {
163
+ "mcpServers": {
164
+ "medical-codes-mcp-server": {
165
+ "type": "stdio",
166
+ "command": "npx",
167
+ "args": ["-y", "@cyanheads/medical-codes-mcp-server@latest"],
168
+ "env": {
169
+ "MCP_TRANSPORT_TYPE": "stdio",
170
+ "MCP_LOG_LEVEL": "info"
171
+ }
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ Or with Docker:
178
+
179
+ ```json
180
+ {
181
+ "mcpServers": {
182
+ "medical-codes-mcp-server": {
183
+ "type": "stdio",
184
+ "command": "docker",
185
+ "args": [
186
+ "run", "-i", "--rm",
187
+ "-e", "MCP_TRANSPORT_TYPE=stdio",
188
+ "ghcr.io/cyanheads/medical-codes-mcp-server:latest"
189
+ ]
190
+ }
191
+ }
192
+ }
193
+ ```
194
+
195
+ For Streamable HTTP, set the transport and start the server:
196
+
197
+ ```sh
198
+ MCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 bun run start:http
199
+ # Server listens at http://localhost:3010/mcp
200
+ ```
201
+
202
+ Refer to "your MCP client configuration file" generically — different clients use different config paths, and the server isn't client-specific.
203
+
204
+ ### Prerequisites
205
+
206
+ - [Bun v1.3](https://bun.sh/) or higher (or Node.js v24+ — the server falls back to the `better-sqlite3` optional dependency when not run under Bun).
207
+ - No API key, account, or network access required.
208
+
209
+ ### Installation
210
+
211
+ 1. **Clone the repository:**
212
+
213
+ ```sh
214
+ git clone https://github.com/cyanheads/medical-codes-mcp-server.git
215
+ ```
216
+
217
+ 2. **Navigate into the directory:**
218
+
219
+ ```sh
220
+ cd medical-codes-mcp-server
221
+ ```
222
+
223
+ 3. **Install dependencies:**
224
+
225
+ ```sh
226
+ bun install
227
+ ```
228
+
229
+ 4. **Configure environment (optional):**
230
+
231
+ ```sh
232
+ cp .env.example .env
233
+ # all runtime vars are optional — the server runs as-is
234
+ ```
235
+
236
+ ## Configuration
237
+
238
+ The server is offline and keyless — there are no required variables. Two server-specific knobs and the standard framework vars apply:
239
+
240
+ | Variable | Description | Default |
241
+ |:---|:---|:---|
242
+ | `MEDCODE_DB_PATH` | Absolute path override for the bundled SQLite index. Set only to point at a custom-built or externally-mounted database. | packaged `data/medical-codes.db` |
243
+ | `MEDCODE_MAX_RESULTS` | Cap on rows returned by `medcode_search_codes` / `medcode_browse_hierarchy`. | `50` (ceiling `200`) |
244
+ | `MCP_TRANSPORT_TYPE` | Transport: `stdio` or `http`. | `stdio` |
245
+ | `MCP_HTTP_PORT` | Port for the HTTP server. | `3010` |
246
+ | `MCP_HTTP_ENDPOINT_PATH` | Endpoint path where the MCP server is mounted. | `/mcp` |
247
+ | `MCP_AUTH_MODE` | Auth mode: `none`, `jwt`, or `oauth`. | `none` |
248
+ | `MCP_LOG_LEVEL` | Log level (RFC 5424). | `info` |
249
+ | `OTEL_ENABLED` | Enable [OpenTelemetry instrumentation](https://github.com/cyanheads/mcp-ts-core/tree/main/docs/telemetry). | `false` |
250
+
251
+ See [`.env.example`](./.env.example) for the full list of optional overrides.
252
+
253
+ ## Running the server
254
+
255
+ ### Local development
256
+
257
+ - **Build and run:**
258
+
259
+ ```sh
260
+ # One-time build
261
+ bun run rebuild
262
+
263
+ # Run the built server
264
+ bun run start:stdio
265
+ # or
266
+ bun run start:http
267
+ ```
268
+
269
+ - **Run checks and tests:**
270
+
271
+ ```sh
272
+ bun run devcheck # Lint, format, typecheck, security
273
+ bun run test # Vitest test suite
274
+ bun run lint:mcp # Validate MCP definitions against spec
275
+ ```
276
+
277
+ ### Building the bundled index
278
+
279
+ The bundled `data/medical-codes.db` is committed and shipped — you only rebuild it when refreshing to a new federal release:
280
+
281
+ ```sh
282
+ bun run scripts/build-index.ts
283
+ ```
284
+
285
+ The script downloads the canonical `.gov` source files, parses them (ICD-10-CM/PCS order files, HCPCS `ANWEB.txt`), and emits the single `.db` file. It runs at build time only — the server never downloads anything.
286
+
287
+ ### Docker
288
+
289
+ ```sh
290
+ docker build -t medical-codes-mcp-server .
291
+ docker run --rm -e MCP_TRANSPORT_TYPE=stdio medical-codes-mcp-server
292
+ ```
293
+
294
+ The Dockerfile defaults to HTTP transport, stateless session mode, and logs to `/var/log/medical-codes-mcp-server`. It copies the bundled `data/medical-codes.db` into the image so the server is fully self-contained. OpenTelemetry peer dependencies are installed by default — build with `--build-arg OTEL_ENABLED=false` to omit them.
295
+
296
+ ## Project structure
297
+
298
+ | Directory | Purpose |
299
+ |:---|:---|
300
+ | `src/index.ts` | `createApp()` entry point — registers the six tools and opens the bundled index in `setup()`. |
301
+ | `src/config` | Server-specific environment variable parsing and validation with Zod. |
302
+ | `src/mcp-server/tools` | Tool definitions (`*.tool.ts`). |
303
+ | `src/services/code-index` | The code-index service — read-only SQLite handle, code-shape detection, FTS5 query translation. |
304
+ | `scripts/build-index.ts` | Build-time ingest pipeline that bakes the federal source files into `data/medical-codes.db`. |
305
+ | `data/medical-codes.db` | The bundled SQLite + FTS5 code index, opened read-only at runtime. |
306
+ | `tests/` | Unit and integration tests mirroring `src/`. |
307
+
308
+ ## Development guide
309
+
310
+ See [`CLAUDE.md`/`AGENTS.md`](./CLAUDE.md) for development guidelines and architectural rules. The short version:
311
+
312
+ - Handlers throw, framework catches — no `try/catch` in tool logic
313
+ - Use `ctx.log` for request-scoped logging; the code index is a read-only global, not tenant state
314
+ - Register new tools via the `createApp()` array in `src/index.ts`
315
+ - The bundled DB is the source of truth — surface real billable/validity flags from the source releases; never fabricate a code or a billability decision
316
+
317
+ ## Contributing
318
+
319
+ Issues and pull requests are welcome. Run checks and tests before submitting:
320
+
321
+ ```sh
322
+ bun run devcheck
323
+ bun run test
324
+ ```
325
+
326
+ ## License
327
+
328
+ Apache-2.0 — see [LICENSE](./LICENSE) for details.
@@ -0,0 +1,24 @@
1
+ ---
2
+ summary: "Offline US medical code lookup and crosswalk over a bundled SQLite+FTS5 index: ICD-10-CM, ICD-10-PCS, and HCPCS Level II across six medcode_* tools (RxNorm in a later release)."
3
+ breaking: false
4
+ security: false
5
+ ---
6
+
7
+ # 0.1.0 — 2026-06-13
8
+
9
+ Initial release. Indexes the freely-redistributable US federal code sets into one offline, keyless, deterministic lookup-and-crosswalk server backed by a bundled SQLite + FTS5 database built at package-build time. v1 bundles ICD-10-CM, ICD-10-PCS, and HCPCS Level II; RxNorm (drug crosswalks) lands in a later release.
10
+
11
+ ## Added
12
+
13
+ - **Six `medcode_*` tools**, all read-only (`readOnlyHint`, `idempotentHint`, `openWorldHint: false`):
14
+ - **`medcode_get_code`** — decode 1–50 codes to official descriptions; auto-detects the system per code, partial-success `found` / `notFound`, optional `includeHierarchy` for parent + immediate children.
15
+ - **`medcode_search_codes`** — FTS5 description search (every term required, prefix-matched), filterable by `system` / `billableOnly` / `chapter`, with truncation disclosure and empty-result notice.
16
+ - **`medcode_check_code`** — validity status (`valid_billable` / `valid_not_billable` / `valid_header` / `terminated`) with a `whyNot`; the validity-vs-existence split means a non-billable or terminated code is a successful result, not an error.
17
+ - **`medcode_map_codes`** — crosswalk `parents` / `children` now; RxNorm drug directions (`name_to_rxcui`, `ndc_to_rxcui`, `rxcui_to_ndc`, `rxcui_to_ingredients`, `rxcui_to_brands`) raise `direction_unavailable` until RxNorm is bundled.
18
+ - **`medcode_browse_hierarchy`** — prefix hierarchy for ICD-10-CM/HCPCS, axis-value browse for ICD-10-PCS.
19
+ - **`medcode_list_systems`** — release identifiers, effective dates, and code counts for provenance.
20
+ - **`code-index` service** — opens the bundled database read-only at startup (`bun:sqlite` under Bun, `better-sqlite3` under Node), fails fast on a missing or empty index, and owns code-shape detection and FTS5 query translation.
21
+ - **`scripts/build-index.ts`** — build-time ingest pipeline that parses the canonical federal source files (ICD-10-CM/PCS order files, HCPCS `ANWEB.txt`, RxNorm Prescribable RRF) into the bundled `.db`. Never downloads at runtime; never pulls the full RxNorm release (Prescribable subset only, to preserve redistribution).
22
+ - **`scripts/build-fixture-db.ts`** — generates the small synthetic `data/medical-codes.db` the test suite and local smoke runs exercise.
23
+ - **Server config** — `MEDCODE_DB_PATH` (bundled-DB path override) and `MEDCODE_MAX_RESULTS` (search/browse cap, default 50, ceiling 200).
24
+ - **`better-sqlite3`** optional dependency — Node-runtime SQLite driver; Bun uses the built-in `bun:sqlite`.