@pipeworx/mcp-cactus 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 +55 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +169 -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,55 @@
|
|
|
1
|
+
# mcp-cactus
|
|
2
|
+
|
|
3
|
+
NCI CACTUS Chemical Identifier Resolver MCP.
|
|
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
|
+
"cactus": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/cactus/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 Cactus 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-cactus",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "NCI CACTUS Chemical Identifier Resolver MCP.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "cactus"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-cactus"
|
|
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/cactus",
|
|
4
|
+
"title": "Cactus",
|
|
5
|
+
"description": "NCI CACTUS Chemical Identifier Resolver MCP.",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/cactus",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-cactus",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/cactus/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
* NCI CACTUS Chemical Identifier Resolver MCP.
|
|
21
|
+
*
|
|
22
|
+
* Keyless, plain-text API (NOT JSON). Converts between chemical identifiers
|
|
23
|
+
* (name, CAS, SMILES, InChI, InChIKey) and computes basic properties.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const BASE = 'https://cactus.nci.nih.gov/chemical/structure';
|
|
28
|
+
const UA = 'pipeworx/1.0 (+https://pipeworx.io)';
|
|
29
|
+
|
|
30
|
+
const REPRESENTATIONS = [
|
|
31
|
+
'smiles',
|
|
32
|
+
'stdinchi',
|
|
33
|
+
'stdinchikey',
|
|
34
|
+
'iupac_name',
|
|
35
|
+
'names',
|
|
36
|
+
'formula',
|
|
37
|
+
'mw',
|
|
38
|
+
'cas',
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const tools: McpToolExport['tools'] = [
|
|
42
|
+
{
|
|
43
|
+
name: 'resolve',
|
|
44
|
+
description:
|
|
45
|
+
'NCI CACTUS chemical identifier resolver. Convert one chemical identifier (a drug/chemical name, CAS number, SMILES, InChI, or InChIKey) into a single representation: smiles (canonical SMILES), stdinchi (standard InChI), stdinchikey (standard InChIKey), iupac_name, names (synonym list), formula (molecular formula), mw (molecular weight), or cas (CAS registry number(s)). Keyless, plain-text API.',
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
identifier: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'Chemical name, CAS number, SMILES, InChI, or InChIKey (e.g. "aspirin", "50-78-2", "CC(=O)Oc1ccccc1C(O)=O").',
|
|
52
|
+
},
|
|
53
|
+
representation: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'One of: smiles, stdinchi, stdinchikey, iupac_name, names, formula, mw, cas.',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ['identifier', 'representation'],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'identify',
|
|
63
|
+
description:
|
|
64
|
+
'NCI CACTUS one-shot lookup: given any chemical identifier (name, CAS, SMILES, InChI, or InChIKey), return SMILES, InChIKey, IUPAC name, molecular formula, molecular weight, and CAS number in a single call. Fields that cannot be resolved are returned as null. Keyless, plain-text API.',
|
|
65
|
+
inputSchema: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties: {
|
|
68
|
+
identifier: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
description: 'Chemical name, CAS number, SMILES, InChI, or InChIKey (e.g. "ibuprofen", "15687-27-1").',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
required: ['identifier'],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
79
|
+
try {
|
|
80
|
+
switch (name) {
|
|
81
|
+
case 'resolve':
|
|
82
|
+
return await resolve(args);
|
|
83
|
+
case 'identify':
|
|
84
|
+
return await identify(args);
|
|
85
|
+
default:
|
|
86
|
+
return { error: `Unknown tool: ${name}` };
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return { error: e instanceof Error ? e.message : String(e) };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function resolve(args: Record<string, unknown>): Promise<unknown> {
|
|
94
|
+
const identifier = args.identifier;
|
|
95
|
+
if (typeof identifier !== 'string' || !identifier.trim()) {
|
|
96
|
+
return { error: 'identifier is required (a chemical name, CAS, SMILES, InChI, or InChIKey)' };
|
|
97
|
+
}
|
|
98
|
+
const representation = args.representation;
|
|
99
|
+
if (typeof representation !== 'string' || !REPRESENTATIONS.includes(representation)) {
|
|
100
|
+
return { error: 'invalid representation', valid: REPRESENTATIONS };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const text = await fetchRep(identifier, representation);
|
|
104
|
+
if (text === null) {
|
|
105
|
+
return { error: 'could not resolve', identifier, representation };
|
|
106
|
+
}
|
|
107
|
+
const value = text.trim();
|
|
108
|
+
if (representation === 'names' || representation === 'cas') {
|
|
109
|
+
const values = value.split('\n').map((s) => s.trim()).filter(Boolean);
|
|
110
|
+
return { identifier, representation, value: values.join('\n'), values };
|
|
111
|
+
}
|
|
112
|
+
return { identifier, representation, value };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function identify(args: Record<string, unknown>): Promise<unknown> {
|
|
116
|
+
const identifier = args.identifier;
|
|
117
|
+
if (typeof identifier !== 'string' || !identifier.trim()) {
|
|
118
|
+
return { error: 'identifier is required (a chemical name, CAS, SMILES, InChI, or InChIKey)' };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const reps = ['smiles', 'stdinchikey', 'iupac_name', 'formula', 'mw', 'cas'] as const;
|
|
122
|
+
const settled = await Promise.allSettled(reps.map((rep) => fetchRep(identifier, rep)));
|
|
123
|
+
|
|
124
|
+
const get = (i: number): string | null => {
|
|
125
|
+
const r = settled[i];
|
|
126
|
+
if (r.status !== 'fulfilled' || r.value === null) return null;
|
|
127
|
+
const v = r.value.trim();
|
|
128
|
+
return v ? v : null;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const smiles = get(0);
|
|
132
|
+
let inchikey = get(1);
|
|
133
|
+
if (inchikey && inchikey.startsWith('InChIKey=')) inchikey = inchikey.slice('InChIKey='.length);
|
|
134
|
+
const iupac_name = get(2);
|
|
135
|
+
const formula = get(3);
|
|
136
|
+
const mwRaw = get(4);
|
|
137
|
+
const casRaw = get(5);
|
|
138
|
+
|
|
139
|
+
if (smiles === null && inchikey === null && iupac_name === null && formula === null && mwRaw === null && casRaw === null) {
|
|
140
|
+
return { error: 'could not resolve any properties', identifier };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let mw: number | string | null = null;
|
|
144
|
+
if (mwRaw !== null) {
|
|
145
|
+
const n = Number(mwRaw);
|
|
146
|
+
mw = Number.isFinite(n) ? n : mwRaw;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const cas = casRaw !== null ? casRaw.split('\n')[0].trim() || null : null;
|
|
150
|
+
|
|
151
|
+
return { identifier, smiles, inchikey, iupac_name, formula, mw, cas };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Fetch a single representation as plain text. Returns the text on HTTP 200,
|
|
156
|
+
* or null on any non-200 (not resolvable) or fetch/parse error.
|
|
157
|
+
*/
|
|
158
|
+
async function fetchRep(identifier: string, representation: string): Promise<string | null> {
|
|
159
|
+
try {
|
|
160
|
+
const url = `${BASE}/${encodeURIComponent(identifier)}/${representation}`;
|
|
161
|
+
const res = await fetch(url, { headers: { 'User-Agent': UA } });
|
|
162
|
+
if (!res.ok) return null;
|
|
163
|
+
return await res.text();
|
|
164
|
+
} catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
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
|
+
}
|