@pipeworx/mcp-mesh 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 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,55 @@
1
+ # mcp-mesh
2
+
3
+ NLM MeSH (Medical Subject Headings) MCP.
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 863+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "mesh": {
20
+ "url": "https://gateway.pipeworx.io/mesh/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 863+ data sources:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "pipeworx": {
32
+ "url": "https://gateway.pipeworx.io/mcp"
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Using with ask_pipeworx
39
+
40
+ Instead of calling tools directly, you can ask questions in plain English:
41
+
42
+ ```
43
+ ask_pipeworx({ question: "your question about Mesh data" })
44
+ ```
45
+
46
+ The gateway picks the right tool and fills the arguments automatically.
47
+
48
+ ## More
49
+
50
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
51
+ - [pipeworx.io](https://pipeworx.io)
52
+
53
+ ## License
54
+
55
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-mesh",
3
+ "version": "0.1.0",
4
+ "description": "NLM MeSH (Medical Subject Headings) MCP.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "mesh"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-mesh"
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/mesh",
4
+ "title": "Mesh",
5
+ "description": "NLM MeSH (Medical Subject Headings) MCP.",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/mesh",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-mesh",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/mesh/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,201 @@
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
+ * NLM MeSH (Medical Subject Headings) MCP.
21
+ *
22
+ * Keyless RDF lookup against id.nlm.nih.gov/mesh — resolve free-text
23
+ * biomedical terms (diseases, drugs, concepts) to MeSH descriptors, the
24
+ * controlled vocabulary NLM uses to index PubMed. Map everyday synonyms to
25
+ * canonical MeSH headings for precise literature searching.
26
+ */
27
+
28
+
29
+ const BASE = 'https://id.nlm.nih.gov/mesh';
30
+ const UA = 'pipeworx/1.0 (+https://pipeworx.io)';
31
+
32
+ /** Last path segment of a MeSH resource URL, e.g. ".../D003920" -> "D003920". */
33
+ function meshId(resource: unknown): string {
34
+ if (typeof resource !== 'string') return '';
35
+ const trimmed = resource.replace(/\/+$/, '');
36
+ const seg = trimmed.split('/').pop() ?? '';
37
+ return seg;
38
+ }
39
+
40
+ /** GET against the MeSH lookup API, returning parsed JSON or throwing. */
41
+ async function meshGet(path: string, params: Record<string, string | number | undefined>): Promise<unknown> {
42
+ const qs = Object.entries(params)
43
+ .filter(([, v]) => v !== undefined && v !== '')
44
+ .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
45
+ .join('&');
46
+ const url = `${BASE}${path}${qs ? `?${qs}` : ''}`;
47
+ const res = await fetch(url, { headers: { Accept: 'application/json', 'User-Agent': UA } });
48
+ if (!res.ok) throw new Error(`MeSH: ${res.status} ${(await res.text()).slice(0, 200)}`);
49
+ return res.json();
50
+ }
51
+
52
+ const MATCH_VALUES = ['exact', 'contains', 'startswith'] as const;
53
+ function normMatch(v: unknown, fallback: string): string {
54
+ return typeof v === 'string' && (MATCH_VALUES as readonly string[]).includes(v) ? v : fallback;
55
+ }
56
+ function normLimit(v: unknown, def: number, max: number): number {
57
+ const n = typeof v === 'number' ? v : typeof v === 'string' ? Number(v) : NaN;
58
+ if (!Number.isFinite(n) || n < 1) return def;
59
+ return Math.min(Math.floor(n), max);
60
+ }
61
+
62
+ const tools: McpToolExport['tools'] = [
63
+ {
64
+ name: 'search_descriptors',
65
+ description:
66
+ 'Search NLM MeSH descriptors by a disease/drug/concept term (e.g. "diabetes", "aspirin", "myocardial infarction"). Returns the matching MeSH descriptor IDs (Dxxxxxxx) — the controlled-vocabulary headings used to index PubMed. The core free-text-to-MeSH lookup. Keyless.',
67
+ inputSchema: {
68
+ type: 'object',
69
+ properties: {
70
+ text: {
71
+ type: 'string',
72
+ description: 'A disease, drug, or biomedical concept term, e.g. "diabetes", "aspirin", "myocardial infarction".',
73
+ },
74
+ match: {
75
+ type: 'string',
76
+ description: 'Match mode against descriptor labels: "exact", "contains", or "startswith". Default "contains".',
77
+ },
78
+ limit: { type: 'number', description: 'Max results (default 10, max 25).' },
79
+ },
80
+ required: ['text'],
81
+ },
82
+ },
83
+ {
84
+ name: 'get_descriptor',
85
+ description:
86
+ 'Get full detail for a MeSH descriptor by its ID (e.g. "D003920" = Diabetes Mellitus): its preferred label, entry terms (synonyms MeSH indexes under it), allowable qualifiers (subheadings like "drug therapy", "epidemiology"), and related see-also headings. Keyless.',
87
+ inputSchema: {
88
+ type: 'object',
89
+ properties: {
90
+ mesh_id: {
91
+ type: 'string',
92
+ description: 'A MeSH descriptor ID, e.g. "D003920" (Diabetes Mellitus) or "D001241" (Aspirin).',
93
+ },
94
+ },
95
+ required: ['mesh_id'],
96
+ },
97
+ },
98
+ {
99
+ name: 'resolve_term',
100
+ description:
101
+ 'Map a free-text term or everyday synonym to its canonical MeSH descriptor(s) — the preferred heading to use when searching PubMed. Tries an exact descriptor match first; if none, falls back to a fuzzy contains match (flagged fuzzy). Keyless.',
102
+ inputSchema: {
103
+ type: 'object',
104
+ properties: {
105
+ text: {
106
+ type: 'string',
107
+ description: 'A term or synonym to canonicalize, e.g. "aspirin", "high blood pressure", "diabetes".',
108
+ },
109
+ limit: { type: 'number', description: 'Max matches (default 10, max 25).' },
110
+ },
111
+ required: ['text'],
112
+ },
113
+ },
114
+ ];
115
+
116
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
117
+ try {
118
+ switch (name) {
119
+ case 'search_descriptors':
120
+ return searchDescriptors(args);
121
+ case 'get_descriptor':
122
+ return getDescriptor(args);
123
+ case 'resolve_term':
124
+ return resolveTerm(args);
125
+ default:
126
+ return { error: `Unknown tool: ${name}` };
127
+ }
128
+ } catch (e) {
129
+ return { error: e instanceof Error ? e.message : String(e) };
130
+ }
131
+ }
132
+
133
+ type LabeledResource = { resource?: unknown; label?: unknown };
134
+
135
+ async function searchDescriptors(args: Record<string, unknown>): Promise<unknown> {
136
+ const text = typeof args.text === 'string' ? args.text.trim() : '';
137
+ if (!text) return { error: 'provide a term in "text"', text: args.text ?? null };
138
+ const match = normMatch(args.match, 'contains');
139
+ const limit = normLimit(args.limit, 10, 25);
140
+
141
+ const arr = (await meshGet('/lookup/descriptor', { label: text, match, limit })) as LabeledResource[];
142
+ const list = Array.isArray(arr) ? arr : [];
143
+ return {
144
+ count: list.length,
145
+ descriptors: list.map((d) => ({
146
+ mesh_id: meshId(d.resource),
147
+ label: d.label,
148
+ url: d.resource,
149
+ })),
150
+ };
151
+ }
152
+
153
+ async function getDescriptor(args: Record<string, unknown>): Promise<unknown> {
154
+ const id = typeof args.mesh_id === 'string' ? args.mesh_id.trim() : '';
155
+ if (!id) return { error: 'provide a descriptor id in "mesh_id"', mesh_id: args.mesh_id ?? null };
156
+
157
+ const d = (await meshGet('/lookup/details', { descriptor: id })) as Record<string, unknown>;
158
+ const terms = (Array.isArray(d.terms) ? d.terms : []) as LabeledResource[];
159
+ const qualifiers = (Array.isArray(d.qualifiers) ? d.qualifiers : []) as LabeledResource[];
160
+ // see-also key casing is lowercase "seealso" in the live API; accept both defensively.
161
+ const seeRaw = (Array.isArray(d.seealso) ? d.seealso : Array.isArray((d as any).seeAlso) ? (d as any).seeAlso : []) as LabeledResource[];
162
+
163
+ // The descriptor's label comes from its preferred entry term.
164
+ const preferred = terms.find((t) => (t as Record<string, unknown>).preferred === true) ?? terms[0];
165
+
166
+ return {
167
+ mesh_id: meshId(d.descriptor),
168
+ label: preferred ? preferred.label : null,
169
+ entry_terms: terms
170
+ .map((t) => t.label)
171
+ .filter((l): l is string => typeof l === 'string')
172
+ .slice(0, 25),
173
+ qualifiers: qualifiers.map((q) => ({ id: meshId(q.resource), label: q.label })),
174
+ see_also: seeRaw.map((s) => ({ id: meshId(s.resource), label: s.label })),
175
+ };
176
+ }
177
+
178
+ async function resolveTerm(args: Record<string, unknown>): Promise<unknown> {
179
+ const text = typeof args.text === 'string' ? args.text.trim() : '';
180
+ if (!text) return { error: 'provide a term in "text"', text: args.text ?? null };
181
+ const limit = normLimit(args.limit, 10, 25);
182
+
183
+ const toMatches = (arr: unknown) =>
184
+ (Array.isArray(arr) ? (arr as LabeledResource[]) : []).map((d) => ({
185
+ mesh_id: meshId(d.resource),
186
+ label: d.label,
187
+ url: d.resource,
188
+ }));
189
+
190
+ // Primary: a synonym often exact-matches a descriptor's preferred label.
191
+ const exact = toMatches(await meshGet('/lookup/descriptor', { label: text, match: 'exact', limit }));
192
+ if (exact.length > 0) {
193
+ return { query: text, matches: exact };
194
+ }
195
+
196
+ // Fallback: fuzzy contains match.
197
+ const fuzzy = toMatches(await meshGet('/lookup/descriptor', { label: text, match: 'contains', limit }));
198
+ return { query: text, fuzzy: true, matches: fuzzy };
199
+ }
200
+
201
+ 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
+ }