@pipeworx/mcp-medical-codes 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.
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +101 -0
- package/tsconfig.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pipeworx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# mcp-medical-codes
|
|
2
|
+
|
|
3
|
+
Medical codes MCP.
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1176+ live data sources.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
| `search_icd10` | Type 2 diabetes mellitus without complications"}]. |
|
|
12
|
+
| `search_loinc` | Search LOINC codes (lab tests & clinical observations) by keyword (keyless). E.g. "hemoglobin a1c" -> LOINC number + long common name. |
|
|
13
|
+
| `search_medical_terms` | Search clinical term lists by keyword (keyless): system = "conditions" (problem/diagnosis names), "procedures" (procedure names), or "drugs" (RxTerms drug display names). |
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"medical-codes": {
|
|
23
|
+
"url": "https://gateway.pipeworx.io/medical-codes/mcp"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or connect to the full Pipeworx gateway for access to all 1176+ data sources:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"mcpServers": {
|
|
34
|
+
"pipeworx": {
|
|
35
|
+
"url": "https://gateway.pipeworx.io/mcp"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Using with ask_pipeworx
|
|
42
|
+
|
|
43
|
+
Instead of calling tools directly, you can ask questions in plain English:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
ask_pipeworx({ question: "your question about Medical Codes data" })
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The gateway picks the right tool and fills the arguments automatically.
|
|
50
|
+
|
|
51
|
+
## More
|
|
52
|
+
|
|
53
|
+
- [All tools and guides](https://github.com/pipeworx-io/examples)
|
|
54
|
+
- [pipeworx.io](https://pipeworx.io)
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-medical-codes",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Medical codes MCP.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "medical-codes"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-medical-codes"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.pipeworx-io/medical-codes",
|
|
4
|
+
"title": "Medical Codes",
|
|
5
|
+
"description": "Medical codes MCP.",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/medical-codes",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-medical-codes",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/medical-codes/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
interface McpToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
required?: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface McpToolExport {
|
|
12
|
+
tools: McpToolDefinition[];
|
|
13
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
14
|
+
meter?: { credits: number };
|
|
15
|
+
cost?: Record<string, unknown>;
|
|
16
|
+
provider?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Medical codes MCP.
|
|
21
|
+
*
|
|
22
|
+
* Keyless: look up clinical codes and terminology via the NLM Clinical Tables
|
|
23
|
+
* API — ICD-10-CM diagnosis codes, LOINC lab/observation codes, and condition /
|
|
24
|
+
* procedure / drug term search. Free, no key. Complements the health stack
|
|
25
|
+
* (openfda/rxnorm/clinicaltrials/pubmed) with the billing/terminology layer.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const BASE = 'https://clinicaltables.nlm.nih.gov/api';
|
|
30
|
+
const UA = 'pipeworx-mcp-medical-codes/1.0 (+https://pipeworx.io)';
|
|
31
|
+
|
|
32
|
+
async function ct(table: string, params: Record<string, string>): Promise<any[]> {
|
|
33
|
+
const p = new URLSearchParams(params);
|
|
34
|
+
const res = await fetch(`${BASE}/${table}/v3/search?${p}`, { headers: { Accept: 'application/json', 'User-Agent': UA } });
|
|
35
|
+
if (!res.ok) throw new Error(`NLM Clinical Tables error: ${res.status} ${await res.text().then((t) => t.slice(0, 120))}`);
|
|
36
|
+
return res.json(); // [total, [keys], extra, [displayRows]]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const tools: McpToolExport['tools'] = [
|
|
40
|
+
{
|
|
41
|
+
name: 'search_icd10',
|
|
42
|
+
description: 'Search ICD-10-CM diagnosis/billing codes by keyword or code (keyless, offline source: NLM). E.g. "type 2 diabetes" -> [{code:"E11.9", description:"Type 2 diabetes mellitus without complications"}].',
|
|
43
|
+
inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'A condition name or an ICD-10 code fragment.' }, limit: { type: 'number', description: 'Max results (1-100, default 15).' } }, required: ['query'] },
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'search_loinc',
|
|
47
|
+
description: 'Search LOINC codes (lab tests & clinical observations) by keyword (keyless). E.g. "hemoglobin a1c" -> LOINC number + long common name.',
|
|
48
|
+
inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'A lab test / observation name.' }, limit: { type: 'number', description: 'Max results (1-100, default 15).' } }, required: ['query'] },
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'search_medical_terms',
|
|
52
|
+
description: 'Search clinical term lists by keyword (keyless): system = "conditions" (problem/diagnosis names), "procedures" (procedure names), or "drugs" (RxTerms drug display names).',
|
|
53
|
+
inputSchema: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
system: { type: 'string', description: 'conditions | procedures | drugs.' },
|
|
57
|
+
query: { type: 'string', description: 'Keyword to search.' },
|
|
58
|
+
limit: { type: 'number', description: 'Max results (1-100, default 15).' },
|
|
59
|
+
},
|
|
60
|
+
required: ['system', 'query'],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
66
|
+
const query = reqStr(args, 'query', '"diabetes"');
|
|
67
|
+
const limit = clamp(numArg(args.limit, 15), 1, 100);
|
|
68
|
+
switch (name) {
|
|
69
|
+
case 'search_icd10': {
|
|
70
|
+
const r = await ct('icd10cm', { sf: 'code,name', df: 'code,name', terms: query, maxList: String(limit) });
|
|
71
|
+
return { query, total: r[0], count: (r[3] ?? []).length, results: (r[3] ?? []).map((row: string[]) => ({ code: row[0], description: row[1] })) };
|
|
72
|
+
}
|
|
73
|
+
case 'search_loinc': {
|
|
74
|
+
const r = await ct('loinc_items', { df: 'LOINC_NUM,LONG_COMMON_NAME', terms: query, maxList: String(limit) });
|
|
75
|
+
return { query, total: r[0], count: (r[3] ?? []).length, results: (r[3] ?? []).map((row: string[]) => ({ loinc: row[0], name: row[1] })) };
|
|
76
|
+
}
|
|
77
|
+
case 'search_medical_terms': {
|
|
78
|
+
const system = reqStr(args, 'system', '"conditions"').toLowerCase();
|
|
79
|
+
const map: Record<string, { table: string; df?: string }> = { conditions: { table: 'conditions' }, procedures: { table: 'procedures' }, drugs: { table: 'rxterms', df: 'DISPLAY_NAME' } };
|
|
80
|
+
const cfg = map[system];
|
|
81
|
+
if (!cfg) return { error: `Unknown system "${system}". Use conditions, procedures, or drugs.` };
|
|
82
|
+
const params: Record<string, string> = { terms: query, maxList: String(limit) };
|
|
83
|
+
if (cfg.df) params.df = cfg.df;
|
|
84
|
+
const r = await ct(cfg.table, params);
|
|
85
|
+
const rows = cfg.df ? (r[3] ?? []).map((row: string[]) => row[0]) : (r[1] ?? []);
|
|
86
|
+
return { system, query, total: r[0], count: rows.length, results: rows };
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function reqStr(args: Record<string, unknown>, key: string, ex: string): string {
|
|
94
|
+
const v = args[key];
|
|
95
|
+
if (typeof v !== 'string' || !v.trim()) throw new Error(`Required argument "${key}" is missing. Pass a string like ${ex}.`);
|
|
96
|
+
return v;
|
|
97
|
+
}
|
|
98
|
+
function numArg(v: unknown, d: number): number { const n = typeof v === 'number' ? v : typeof v === 'string' ? Number(v) : NaN; return Number.isFinite(n) ? n : d; }
|
|
99
|
+
function clamp(n: number, lo: number, hi: number): number { return Math.max(lo, Math.min(hi, Math.trunc(n))); }
|
|
100
|
+
|
|
101
|
+
export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|