@pipeworx/mcp-medlineplus 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 +56 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +193 -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,56 @@
|
|
|
1
|
+
# mcp-medlineplus
|
|
2
|
+
|
|
3
|
+
MedlinePlus MCP — NIH consumer health info
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 250+ live data sources.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
| `search` | Free-text search across MedlinePlus topics (or related NLM databases). |
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"mcpServers": {
|
|
20
|
+
"medlineplus": {
|
|
21
|
+
"url": "https://gateway.pipeworx.io/medlineplus/mcp"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or connect to the full Pipeworx gateway for access to all 250+ data sources:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"mcpServers": {
|
|
32
|
+
"pipeworx": {
|
|
33
|
+
"url": "https://gateway.pipeworx.io/mcp"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Using with ask_pipeworx
|
|
40
|
+
|
|
41
|
+
Instead of calling tools directly, you can ask questions in plain English:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
ask_pipeworx({ question: "your question about Medlineplus data" })
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The gateway picks the right tool and fills the arguments automatically.
|
|
48
|
+
|
|
49
|
+
## More
|
|
50
|
+
|
|
51
|
+
- [All tools and guides](https://github.com/pipeworx-io/examples)
|
|
52
|
+
- [pipeworx.io](https://pipeworx.io)
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-medlineplus",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MedlinePlus MCP — NIH consumer health info",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "medlineplus"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-medlineplus"
|
|
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/medlineplus",
|
|
4
|
+
"title": "Medlineplus",
|
|
5
|
+
"description": "MedlinePlus MCP — NIH consumer health info",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/medlineplus",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-medlineplus",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/medlineplus/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
* MedlinePlus MCP — NIH consumer health info
|
|
21
|
+
*
|
|
22
|
+
* Two underlying services:
|
|
23
|
+
* - Connect API: map clinical codes (ICD-10-CM, SNOMED, RxNorm, LOINC, …) to
|
|
24
|
+
* MedlinePlus topic pages.
|
|
25
|
+
* - NLM Web Search: free-text search across MedlinePlus + other NLM databases.
|
|
26
|
+
*
|
|
27
|
+
* Both are keyless.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const CONNECT_BASE = 'https://connect.medlineplus.gov/service';
|
|
32
|
+
const WSEARCH_BASE = 'https://wsearch.nlm.nih.gov/ws/query';
|
|
33
|
+
|
|
34
|
+
// Common code system short names → official OIDs
|
|
35
|
+
const CODE_SYSTEM_OIDS: Record<string, string> = {
|
|
36
|
+
'ICD-9-CM': '2.16.840.1.113883.6.103',
|
|
37
|
+
ICD9: '2.16.840.1.113883.6.103',
|
|
38
|
+
'ICD-10-CM': '2.16.840.1.113883.6.90',
|
|
39
|
+
ICD10: '2.16.840.1.113883.6.90',
|
|
40
|
+
'ICD-10-PCS': '2.16.840.1.113883.6.4',
|
|
41
|
+
SNOMED: '2.16.840.1.113883.6.96',
|
|
42
|
+
'SNOMED CT': '2.16.840.1.113883.6.96',
|
|
43
|
+
RXNORM: '2.16.840.1.113883.6.88',
|
|
44
|
+
RxNorm: '2.16.840.1.113883.6.88',
|
|
45
|
+
LOINC: '2.16.840.1.113883.6.1',
|
|
46
|
+
NDC: '2.16.840.1.113883.6.69',
|
|
47
|
+
MESH: '2.16.840.1.113883.6.177',
|
|
48
|
+
MeSH: '2.16.840.1.113883.6.177',
|
|
49
|
+
HGNC: '2.16.840.1.113883.6.282',
|
|
50
|
+
GENE: '2.16.840.1.113883.6.282',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const tools: McpToolExport['tools'] = [
|
|
54
|
+
{
|
|
55
|
+
name: 'connect',
|
|
56
|
+
description:
|
|
57
|
+
'Map a clinical code (ICD-10-CM, SNOMED CT, RxCUI, LOINC, NDC, MeSH, HGNC) to MedlinePlus consumer-health topics.',
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
code: { type: 'string', description: 'Code value (e.g. "J00" for ICD-10-CM acute nasopharyngitis)' },
|
|
62
|
+
code_system: {
|
|
63
|
+
type: 'string',
|
|
64
|
+
description: 'Short name or OID — ICD-10-CM | SNOMED | RxNorm | LOINC | NDC | MeSH | HGNC | ICD-9-CM',
|
|
65
|
+
},
|
|
66
|
+
lang: { type: 'string', description: 'en (default) | es' },
|
|
67
|
+
},
|
|
68
|
+
required: ['code', 'code_system'],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'search',
|
|
73
|
+
description: 'Free-text search across MedlinePlus topics (or related NLM databases).',
|
|
74
|
+
inputSchema: {
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: {
|
|
77
|
+
query: { type: 'string' },
|
|
78
|
+
db: { type: 'string', description: 'healthTopics (default) | healthTopicsSpanish | drug | herb | meshhd | genetic' },
|
|
79
|
+
limit: { type: 'number', description: '1-100 (default 10)' },
|
|
80
|
+
retstart: { type: 'number', description: '0-based offset' },
|
|
81
|
+
knowledge_response_type: { type: 'string', description: 'application/json (default) | application/xml' },
|
|
82
|
+
},
|
|
83
|
+
required: ['query'],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
89
|
+
switch (name) {
|
|
90
|
+
case 'connect':
|
|
91
|
+
return connect(args);
|
|
92
|
+
case 'search':
|
|
93
|
+
return search(args);
|
|
94
|
+
default:
|
|
95
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function connect(args: Record<string, unknown>) {
|
|
100
|
+
const code = reqStr(args, 'code', '"J00"');
|
|
101
|
+
const sysIn = reqStr(args, 'code_system', '"ICD-10-CM"');
|
|
102
|
+
const oid = /^[0-9.]+$/.test(sysIn) ? sysIn : CODE_SYSTEM_OIDS[sysIn] ?? CODE_SYSTEM_OIDS[sysIn.toUpperCase()];
|
|
103
|
+
if (!oid) {
|
|
104
|
+
throw new Error(`Unknown code_system "${sysIn}". Supported: ${Object.keys(CODE_SYSTEM_OIDS).slice(0, 8).join(', ')}, or pass the OID directly.`);
|
|
105
|
+
}
|
|
106
|
+
const params = new URLSearchParams({
|
|
107
|
+
'mainSearchCriteria.v.cs': oid,
|
|
108
|
+
'mainSearchCriteria.v.c': code,
|
|
109
|
+
'informationRecipient.languageCode.c': String(args.lang ?? 'en'),
|
|
110
|
+
knowledgeResponseType: 'application/json',
|
|
111
|
+
});
|
|
112
|
+
const res = await fetch(`${CONNECT_BASE}?${params}`, {
|
|
113
|
+
headers: {
|
|
114
|
+
Accept: 'application/json',
|
|
115
|
+
'User-Agent': 'pipeworx-mcp-medlineplus/1.0 (+https://pipeworx.io)',
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
if (!res.ok) {
|
|
119
|
+
const t = await res.text();
|
|
120
|
+
throw new Error(`MedlinePlus Connect error: ${res.status} ${t.slice(0, 200)}`);
|
|
121
|
+
}
|
|
122
|
+
return res.json();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function search(args: Record<string, unknown>) {
|
|
126
|
+
const params = new URLSearchParams({
|
|
127
|
+
db: String(args.db ?? 'healthTopics'),
|
|
128
|
+
term: reqStr(args, 'query', '"diabetes"'),
|
|
129
|
+
rettype: 'brief',
|
|
130
|
+
retmax: String(Math.min(100, Math.max(1, (args.limit as number) ?? 10))),
|
|
131
|
+
retstart: String(Math.max(0, (args.retstart as number) ?? 0)),
|
|
132
|
+
});
|
|
133
|
+
const res = await fetch(`${WSEARCH_BASE}?${params}`, {
|
|
134
|
+
headers: {
|
|
135
|
+
Accept: 'application/xml',
|
|
136
|
+
'User-Agent': 'pipeworx-mcp-medlineplus/1.0 (+https://pipeworx.io)',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
if (!res.ok) {
|
|
140
|
+
const t = await res.text();
|
|
141
|
+
throw new Error(`MedlinePlus search error: ${res.status} ${t.slice(0, 200)}`);
|
|
142
|
+
}
|
|
143
|
+
const xml = await res.text();
|
|
144
|
+
return parseWsearchXml(xml);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface SearchResult {
|
|
148
|
+
rank?: number;
|
|
149
|
+
url?: string;
|
|
150
|
+
title?: string;
|
|
151
|
+
snippet?: string;
|
|
152
|
+
organization?: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// NLM wsearch returns XML; parse out the documents.
|
|
156
|
+
function parseWsearchXml(xml: string) {
|
|
157
|
+
const count = Number(/count=["'](\d+)["']/.exec(xml)?.[1] ?? '0');
|
|
158
|
+
const total = Number(/<count>(\d+)<\/count>/.exec(xml)?.[1] ?? count);
|
|
159
|
+
const docs: SearchResult[] = [];
|
|
160
|
+
const docRe = /<document(?:\s+rank=["'](\d+)["'])?[^>]*?(?:\s+url=["']([^"']+)["'])?[^>]*>([\s\S]*?)<\/document>/g;
|
|
161
|
+
for (const m of xml.matchAll(docRe)) {
|
|
162
|
+
const rank = m[1] ? Number(m[1]) : undefined;
|
|
163
|
+
const url = m[2];
|
|
164
|
+
const inner = m[3];
|
|
165
|
+
const fields: Record<string, string> = {};
|
|
166
|
+
const fieldRe = /<content name=["']([^"']+)["'][^>]*>([\s\S]*?)<\/content>/g;
|
|
167
|
+
for (const f of inner.matchAll(fieldRe)) {
|
|
168
|
+
fields[f[1]] = stripTags(f[2]);
|
|
169
|
+
}
|
|
170
|
+
docs.push({
|
|
171
|
+
rank,
|
|
172
|
+
url,
|
|
173
|
+
title: fields.title,
|
|
174
|
+
snippet: fields.snippet ?? fields.FullSummary,
|
|
175
|
+
organization: fields.organizationName,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return { total, returned: docs.length, results: docs };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function stripTags(s: string): string {
|
|
182
|
+
return s.replace(/<[^>]+>/g, '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').trim();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function reqStr(args: Record<string, unknown>, key: string, example: string): string {
|
|
186
|
+
const v = args[key];
|
|
187
|
+
if (typeof v !== 'string' || !v.trim()) {
|
|
188
|
+
throw new Error(`Required argument "${key}" is missing. Pass a string like ${example}.`);
|
|
189
|
+
}
|
|
190
|
+
return v;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
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
|
+
}
|