@pipeworx/mcp-cbioportal 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-cbioportal
2
+
3
+ cBioPortal MCP — cancer genomics portal.
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 808+ 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
+ "cbioportal": {
20
+ "url": "https://gateway.pipeworx.io/cbioportal/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 808+ 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 Cbioportal 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-cbioportal",
3
+ "version": "0.1.0",
4
+ "description": "cBioPortal MCP — cancer genomics portal.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "cbioportal"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-cbioportal"
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/cbioportal",
4
+ "title": "Cbioportal",
5
+ "description": "cBioPortal MCP — cancer genomics portal.",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/cbioportal",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-cbioportal",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/cbioportal/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,246 @@
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
+ * cBioPortal MCP — cancer genomics portal.
21
+ *
22
+ * Search public cancer studies (TCGA / CPTAC / etc.) by keyword, get study
23
+ * details + sample counts, resolve a gene symbol to an Entrez id, and list
24
+ * cancer types. Complements the GDC pack. Keyless, open data.
25
+ *
26
+ * Wraps the public cBioPortal REST API (https://www.cbioportal.org/api),
27
+ * which returns plain JSON arrays/objects (no envelope).
28
+ */
29
+
30
+
31
+ const BASE = 'https://www.cbioportal.org/api';
32
+ const UA = 'pipeworx/1.0 (+https://pipeworx.io)';
33
+
34
+ const tools: McpToolExport['tools'] = [
35
+ {
36
+ name: 'search_studies',
37
+ description:
38
+ 'Search public cancer genomics studies in cBioPortal (TCGA, CPTAC, MSK, etc.) by keyword. Matches study name, study id, or cancer-type id (case-insensitive). Returns study ids, names, cancer types, and sample counts. Keyless, open data.',
39
+ inputSchema: {
40
+ type: 'object',
41
+ properties: {
42
+ query: { type: 'string', description: 'Keyword to match against study name / id / cancer type (e.g. "breast", "tcga", "glioma"). Omit to list studies.' },
43
+ limit: { type: 'number', description: 'Max studies to return (default 25, max 100).' },
44
+ },
45
+ },
46
+ },
47
+ {
48
+ name: 'get_study',
49
+ description:
50
+ 'Get full details for one cBioPortal cancer study by its study id (e.g. "brca_tcga_pub", "glioma_mskcc_2019"), including description, cancer type, sample count, PMID, and citation.',
51
+ inputSchema: {
52
+ type: 'object',
53
+ properties: {
54
+ study_id: { type: 'string', description: 'cBioPortal study id, e.g. "brca_tcga_pub".' },
55
+ },
56
+ required: ['study_id'],
57
+ },
58
+ },
59
+ {
60
+ name: 'get_gene',
61
+ description:
62
+ 'Resolve a gene to its Entrez gene id and canonical info via cBioPortal. Accepts a HUGO symbol (e.g. "TP53", "BRCA1") or an Entrez gene id. Returns entrez_gene_id, symbol, and type.',
63
+ inputSchema: {
64
+ type: 'object',
65
+ properties: {
66
+ gene: { type: 'string', description: 'HUGO gene symbol (e.g. "TP53") or Entrez gene id.' },
67
+ },
68
+ required: ['gene'],
69
+ },
70
+ },
71
+ {
72
+ name: 'list_cancer_types',
73
+ description:
74
+ 'List cancer types defined in cBioPortal (id, display name, parent type). Useful for resolving cancer-type ids used by studies.',
75
+ inputSchema: {
76
+ type: 'object',
77
+ properties: {
78
+ limit: { type: 'number', description: 'Max cancer types to return (default 50, max 200).' },
79
+ },
80
+ },
81
+ },
82
+ ];
83
+
84
+ interface CbioStudy {
85
+ studyId?: string;
86
+ name?: string;
87
+ description?: string;
88
+ cancerTypeId?: string;
89
+ allSampleCount?: number;
90
+ publicStudy?: boolean;
91
+ pmid?: string;
92
+ citation?: string;
93
+ referenceGenome?: string;
94
+ }
95
+
96
+ interface CbioGene {
97
+ entrezGeneId?: number;
98
+ hugoGeneSymbol?: string;
99
+ type?: string;
100
+ }
101
+
102
+ interface CbioCancerType {
103
+ cancerTypeId?: string;
104
+ name?: string;
105
+ dedicatedColor?: string;
106
+ parent?: string;
107
+ }
108
+
109
+ function clampNum(v: unknown, def: number, min: number, max: number): number {
110
+ const n = typeof v === 'number' && Number.isFinite(v) ? Math.floor(v) : def;
111
+ return Math.max(min, Math.min(max, n));
112
+ }
113
+
114
+ function reqStr(args: Record<string, unknown>, key: string): string {
115
+ const v = args[key];
116
+ if (typeof v !== 'string' || !v.trim()) {
117
+ throw new Error(`Required argument "${key}" is missing.`);
118
+ }
119
+ return v.trim();
120
+ }
121
+
122
+ async function cbioGet(path: string): Promise<{ ok: boolean; status: number; data: unknown }> {
123
+ const res = await fetch(`${BASE}${path}`, {
124
+ headers: { Accept: 'application/json', 'User-Agent': UA },
125
+ });
126
+ let data: unknown = null;
127
+ try {
128
+ data = await res.json();
129
+ } catch {
130
+ data = null;
131
+ }
132
+ return { ok: res.ok, status: res.status, data };
133
+ }
134
+
135
+ function mapStudy(s: CbioStudy) {
136
+ return {
137
+ study_id: s.studyId,
138
+ name: s.name,
139
+ cancer_type: s.cancerTypeId,
140
+ samples: s.allSampleCount,
141
+ pmid: s.pmid,
142
+ reference_genome: s.referenceGenome,
143
+ };
144
+ }
145
+
146
+ async function searchStudies(args: Record<string, unknown>): Promise<unknown> {
147
+ const limit = clampNum(args.limit, 25, 1, 100);
148
+ const query = typeof args.query === 'string' ? args.query.trim().toLowerCase() : '';
149
+
150
+ // Fetch a large page and filter client-side (API has no keyword search).
151
+ let resp = await cbioGet('/studies?pageSize=500&pageNumber=0&direction=ASC&projection=SUMMARY');
152
+ if (!resp.ok || !Array.isArray(resp.data)) {
153
+ // Fall back to a smaller page if the large fetch failed.
154
+ resp = await cbioGet('/studies?pageSize=100&pageNumber=0&direction=ASC&projection=SUMMARY');
155
+ }
156
+ if (!resp.ok) {
157
+ return { error: `cBioPortal: ${resp.status}` };
158
+ }
159
+ const all = Array.isArray(resp.data) ? (resp.data as CbioStudy[]) : [];
160
+
161
+ let filtered = all;
162
+ if (query) {
163
+ filtered = all.filter((s) => {
164
+ const hay = `${s.name ?? ''} ${s.studyId ?? ''} ${s.cancerTypeId ?? ''}`.toLowerCase();
165
+ return hay.includes(query);
166
+ });
167
+ }
168
+
169
+ const studies = filtered.slice(0, limit).map(mapStudy);
170
+ return { count: studies.length, studies };
171
+ }
172
+
173
+ async function getStudy(args: Record<string, unknown>): Promise<unknown> {
174
+ const studyId = reqStr(args, 'study_id');
175
+ const resp = await cbioGet(`/studies/${encodeURIComponent(studyId)}`);
176
+ if (resp.status === 404) {
177
+ return { error: 'study not found', study_id: studyId };
178
+ }
179
+ if (!resp.ok || !resp.data || typeof resp.data !== 'object') {
180
+ return { error: `cBioPortal: ${resp.status}`, study_id: studyId };
181
+ }
182
+ const s = resp.data as CbioStudy;
183
+ return {
184
+ study_id: s.studyId,
185
+ name: s.name,
186
+ description: s.description,
187
+ cancer_type: s.cancerTypeId,
188
+ samples: s.allSampleCount,
189
+ pmid: s.pmid,
190
+ citation: s.citation,
191
+ reference_genome: s.referenceGenome,
192
+ };
193
+ }
194
+
195
+ async function getGene(args: Record<string, unknown>): Promise<unknown> {
196
+ const gene = reqStr(args, 'gene');
197
+ const resp = await cbioGet(`/genes/${encodeURIComponent(gene)}`);
198
+ if (resp.status === 404) {
199
+ return { error: 'gene not found', gene };
200
+ }
201
+ if (!resp.ok || !resp.data || typeof resp.data !== 'object') {
202
+ return { error: `cBioPortal: ${resp.status}`, gene };
203
+ }
204
+ const g = resp.data as CbioGene;
205
+ return {
206
+ entrez_gene_id: g.entrezGeneId,
207
+ symbol: g.hugoGeneSymbol,
208
+ type: g.type,
209
+ };
210
+ }
211
+
212
+ async function listCancerTypes(args: Record<string, unknown>): Promise<unknown> {
213
+ const limit = clampNum(args.limit, 50, 1, 200);
214
+ const resp = await cbioGet(`/cancer-types?pageSize=${encodeURIComponent(String(limit))}`);
215
+ if (!resp.ok) {
216
+ return { error: `cBioPortal: ${resp.status}` };
217
+ }
218
+ const arr = Array.isArray(resp.data) ? (resp.data as CbioCancerType[]) : [];
219
+ const cancer_types = arr.slice(0, limit).map((c) => ({
220
+ id: c.cancerTypeId,
221
+ name: c.name,
222
+ parent: c.parent,
223
+ }));
224
+ return { count: cancer_types.length, cancer_types };
225
+ }
226
+
227
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
228
+ try {
229
+ switch (name) {
230
+ case 'search_studies':
231
+ return await searchStudies(args);
232
+ case 'get_study':
233
+ return await getStudy(args);
234
+ case 'get_gene':
235
+ return await getGene(args);
236
+ case 'list_cancer_types':
237
+ return await listCancerTypes(args);
238
+ default:
239
+ return { error: `Unknown tool: ${name}` };
240
+ }
241
+ } catch (err) {
242
+ return { error: err instanceof Error ? err.message : String(err) };
243
+ }
244
+ }
245
+
246
+ 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
+ }