@cyanheads/pubchem-mcp-server 0.1.1
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 +190 -0
- package/README.md +198 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-bioactivity.tool.d.ts +33 -0
- package/dist/mcp-server/tools/definitions/get-bioactivity.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-bioactivity.tool.js +115 -0
- package/dist/mcp-server/tools/definitions/get-bioactivity.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-compound-details.tool.d.ts +22 -0
- package/dist/mcp-server/tools/definitions/get-compound-details.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-compound-details.tool.js +190 -0
- package/dist/mcp-server/tools/definitions/get-compound-details.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-compound-image.tool.d.ts +19 -0
- package/dist/mcp-server/tools/definitions/get-compound-image.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-compound-image.tool.js +57 -0
- package/dist/mcp-server/tools/definitions/get-compound-image.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-compound-safety.tool.d.ts +25 -0
- package/dist/mcp-server/tools/definitions/get-compound-safety.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-compound-safety.tool.js +94 -0
- package/dist/mcp-server/tools/definitions/get-compound-safety.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-compound-xrefs.tool.d.ts +21 -0
- package/dist/mcp-server/tools/definitions/get-compound-xrefs.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-compound-xrefs.tool.js +90 -0
- package/dist/mcp-server/tools/definitions/get-compound-xrefs.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-summary.tool.d.ts +23 -0
- package/dist/mcp-server/tools/definitions/get-summary.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-summary.tool.js +143 -0
- package/dist/mcp-server/tools/definitions/get-summary.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/index.d.ts +152 -0
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/index.js +23 -0
- package/dist/mcp-server/tools/definitions/index.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-assays.tool.d.ts +22 -0
- package/dist/mcp-server/tools/definitions/search-assays.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/search-assays.tool.js +76 -0
- package/dist/mcp-server/tools/definitions/search-assays.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-compounds.tool.d.ts +42 -0
- package/dist/mcp-server/tools/definitions/search-compounds.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/search-compounds.tool.js +204 -0
- package/dist/mcp-server/tools/definitions/search-compounds.tool.js.map +1 -0
- package/dist/services/pubchem/pubchem-client.d.ts +37 -0
- package/dist/services/pubchem/pubchem-client.d.ts.map +1 -0
- package/dist/services/pubchem/pubchem-client.js +546 -0
- package/dist/services/pubchem/pubchem-client.js.map +1 -0
- package/dist/services/pubchem/types.d.ts +133 -0
- package/dist/services/pubchem/types.d.ts.map +1 -0
- package/dist/services/pubchem/types.js +68 -0
- package/dist/services/pubchem/types.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Search PubChem for chemical compounds by name, SMILES, InChIKey,
|
|
3
|
+
* formula, substructure, superstructure, or 2D similarity.
|
|
4
|
+
* @module mcp-server/tools/definitions/search-compounds
|
|
5
|
+
*/
|
|
6
|
+
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
7
|
+
import { getPubChemClient } from '../../../services/pubchem/pubchem-client.js';
|
|
8
|
+
import { COMPOUND_PROPERTIES } from '../../../services/pubchem/types.js';
|
|
9
|
+
const searchTypeEnum = z.enum([
|
|
10
|
+
'identifier',
|
|
11
|
+
'formula',
|
|
12
|
+
'substructure',
|
|
13
|
+
'superstructure',
|
|
14
|
+
'similarity',
|
|
15
|
+
]);
|
|
16
|
+
const identifierTypeEnum = z.enum(['name', 'smiles', 'inchikey']);
|
|
17
|
+
const queryTypeEnum = z.enum(['smiles', 'cid']);
|
|
18
|
+
const propertyEnum = z.enum(COMPOUND_PROPERTIES);
|
|
19
|
+
export const searchCompounds = tool('pubchem_search_compounds', {
|
|
20
|
+
title: 'Search Compounds',
|
|
21
|
+
description: `Search PubChem for chemical compounds. Five search modes:\n` +
|
|
22
|
+
`- identifier: Resolve compound names, SMILES, or InChIKeys to CIDs (batch up to 25)\n` +
|
|
23
|
+
`- formula: Find compounds by molecular formula (Hill notation, e.g. "C6H12O6")\n` +
|
|
24
|
+
`- substructure: Find compounds containing a substructure (SMILES or CID)\n` +
|
|
25
|
+
`- superstructure: Find compounds that are substructures of the query\n` +
|
|
26
|
+
`- similarity: Find structurally similar compounds by 2D Tanimoto similarity\n\n` +
|
|
27
|
+
`Optionally hydrate results with properties to avoid a follow-up details call.`,
|
|
28
|
+
annotations: {
|
|
29
|
+
readOnlyHint: true,
|
|
30
|
+
destructiveHint: false,
|
|
31
|
+
idempotentHint: true,
|
|
32
|
+
openWorldHint: true,
|
|
33
|
+
},
|
|
34
|
+
input: z.object({
|
|
35
|
+
searchType: searchTypeEnum.describe('Search strategy: "identifier" (name/SMILES/InChIKey lookup), "formula", "substructure", "superstructure", or "similarity".'),
|
|
36
|
+
identifierType: identifierTypeEnum
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('Required for identifier search. Type of chemical identifier: "name", "smiles", or "inchikey".'),
|
|
39
|
+
identifiers: z
|
|
40
|
+
.array(z.string())
|
|
41
|
+
.min(1)
|
|
42
|
+
.max(25)
|
|
43
|
+
.optional()
|
|
44
|
+
.describe('Required for identifier search. Array of identifiers to resolve (1-25). ' +
|
|
45
|
+
'Examples: ["aspirin", "ibuprofen"] for name, ["CC(=O)OC1=CC=CC=C1C(=O)O"] for SMILES.'),
|
|
46
|
+
formula: z
|
|
47
|
+
.string()
|
|
48
|
+
.optional()
|
|
49
|
+
.describe('Required for formula search. Molecular formula in Hill notation (e.g. "C6H12O6", "CaH2O2").'),
|
|
50
|
+
allowOtherElements: z
|
|
51
|
+
.boolean()
|
|
52
|
+
.default(false)
|
|
53
|
+
.describe('Formula search only. When true, includes compounds with additional elements beyond the formula.'),
|
|
54
|
+
query: z
|
|
55
|
+
.string()
|
|
56
|
+
.optional()
|
|
57
|
+
.describe('Required for substructure/superstructure/similarity searches. ' +
|
|
58
|
+
'A SMILES string or PubChem CID (as string) for the query structure.'),
|
|
59
|
+
queryType: queryTypeEnum
|
|
60
|
+
.optional()
|
|
61
|
+
.describe('Required for structure/similarity searches. Format of the query: "smiles" or "cid".'),
|
|
62
|
+
threshold: z
|
|
63
|
+
.number()
|
|
64
|
+
.min(70)
|
|
65
|
+
.max(100)
|
|
66
|
+
.default(90)
|
|
67
|
+
.describe('Similarity search only. Minimum Tanimoto similarity (70-100). ' +
|
|
68
|
+
'90+ for close analogs, 70-80 for scaffold hops. Default: 90.'),
|
|
69
|
+
maxResults: z
|
|
70
|
+
.number()
|
|
71
|
+
.min(1)
|
|
72
|
+
.max(200)
|
|
73
|
+
.default(20)
|
|
74
|
+
.describe('Maximum CIDs to return (1-200). Default: 20.'),
|
|
75
|
+
properties: z
|
|
76
|
+
.array(propertyEnum)
|
|
77
|
+
.optional()
|
|
78
|
+
.describe('Optional: fetch these properties for each result, avoiding a follow-up details call. ' +
|
|
79
|
+
'E.g. ["MolecularFormula", "MolecularWeight", "CanonicalSMILES"].'),
|
|
80
|
+
}),
|
|
81
|
+
output: z.object({
|
|
82
|
+
searchType: z.string().describe('The search strategy used.'),
|
|
83
|
+
totalFound: z.number().describe('Total CIDs found (before maxResults cap).'),
|
|
84
|
+
results: z
|
|
85
|
+
.array(z.object({
|
|
86
|
+
cid: z.number().describe('PubChem Compound ID.'),
|
|
87
|
+
identifier: z
|
|
88
|
+
.string()
|
|
89
|
+
.optional()
|
|
90
|
+
.describe('Echoed input identifier (identifier mode only).'),
|
|
91
|
+
properties: z
|
|
92
|
+
.record(z.string(), z.unknown())
|
|
93
|
+
.optional()
|
|
94
|
+
.describe('Compound properties when requested.'),
|
|
95
|
+
}))
|
|
96
|
+
.describe('Matching compounds.'),
|
|
97
|
+
}),
|
|
98
|
+
async handler(input, ctx) {
|
|
99
|
+
const client = getPubChemClient();
|
|
100
|
+
let allCids = [];
|
|
101
|
+
const identifierMap = new Map();
|
|
102
|
+
switch (input.searchType) {
|
|
103
|
+
case 'identifier': {
|
|
104
|
+
const { identifierType, identifiers } = input;
|
|
105
|
+
if (!identifierType || !identifiers) {
|
|
106
|
+
throw new Error('identifierType and identifiers are required for identifier search');
|
|
107
|
+
}
|
|
108
|
+
const lookups = identifiers.map(async (id) => {
|
|
109
|
+
let cids;
|
|
110
|
+
switch (identifierType) {
|
|
111
|
+
case 'name':
|
|
112
|
+
cids = await client.searchByName(id);
|
|
113
|
+
break;
|
|
114
|
+
case 'smiles':
|
|
115
|
+
cids = await client.searchBySmiles(id);
|
|
116
|
+
break;
|
|
117
|
+
case 'inchikey':
|
|
118
|
+
cids = await client.searchByInchiKey(id);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
for (const cid of cids)
|
|
122
|
+
identifierMap.set(cid, id);
|
|
123
|
+
return cids;
|
|
124
|
+
});
|
|
125
|
+
const results = await Promise.all(lookups);
|
|
126
|
+
allCids = results.flat();
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case 'formula': {
|
|
130
|
+
if (!input.formula)
|
|
131
|
+
throw new Error('formula is required for formula search');
|
|
132
|
+
allCids = await client.searchByFormula(input.formula, input.allowOtherElements);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'substructure':
|
|
136
|
+
case 'superstructure':
|
|
137
|
+
case 'similarity': {
|
|
138
|
+
if (!input.query || !input.queryType) {
|
|
139
|
+
throw new Error('query and queryType are required for structure/similarity searches');
|
|
140
|
+
}
|
|
141
|
+
allCids = await client.searchByStructure(input.searchType, input.query, input.queryType, input.threshold);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Deduplicate and cap
|
|
146
|
+
const uniqueCids = [...new Set(allCids)];
|
|
147
|
+
const totalFound = uniqueCids.length;
|
|
148
|
+
const cappedCids = uniqueCids.slice(0, input.maxResults);
|
|
149
|
+
ctx.log.info('Search completed', {
|
|
150
|
+
searchType: input.searchType,
|
|
151
|
+
totalFound,
|
|
152
|
+
returned: cappedCids.length,
|
|
153
|
+
});
|
|
154
|
+
// Optionally hydrate with properties
|
|
155
|
+
let propsMap;
|
|
156
|
+
if (input.properties && input.properties.length > 0 && cappedCids.length > 0) {
|
|
157
|
+
const rows = await client.getProperties(cappedCids, input.properties);
|
|
158
|
+
propsMap = new Map(rows.map((r) => [r.CID, r]));
|
|
159
|
+
}
|
|
160
|
+
const results = cappedCids.map((cid) => {
|
|
161
|
+
const result = { cid };
|
|
162
|
+
const identifier = identifierMap.get(cid);
|
|
163
|
+
if (identifier)
|
|
164
|
+
result.identifier = identifier;
|
|
165
|
+
const rawProps = propsMap?.get(cid);
|
|
166
|
+
if (rawProps) {
|
|
167
|
+
const props = { ...rawProps };
|
|
168
|
+
delete props.CID;
|
|
169
|
+
result.properties = props;
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
});
|
|
173
|
+
return { searchType: input.searchType, totalFound, results };
|
|
174
|
+
},
|
|
175
|
+
format(result) {
|
|
176
|
+
const lines = [];
|
|
177
|
+
const count = result.results.length;
|
|
178
|
+
const truncated = result.totalFound > count ? ` (showing ${count} of ${result.totalFound})` : '';
|
|
179
|
+
lines.push(`Found ${result.totalFound} compound${result.totalFound !== 1 ? 's' : ''}${truncated} — ${result.searchType} search`);
|
|
180
|
+
lines.push('');
|
|
181
|
+
if (result.results.length === 0) {
|
|
182
|
+
lines.push('No results.');
|
|
183
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
184
|
+
}
|
|
185
|
+
const hasProps = result.results.some((r) => r.properties);
|
|
186
|
+
if (hasProps) {
|
|
187
|
+
for (const r of result.results) {
|
|
188
|
+
const label = r.identifier ? `CID ${r.cid} — ${r.identifier}` : `CID ${r.cid}`;
|
|
189
|
+
lines.push(`**${label}**`);
|
|
190
|
+
if (r.properties) {
|
|
191
|
+
const entries = Object.entries(r.properties);
|
|
192
|
+
lines.push(entries.map(([k, v]) => ` ${k}: ${v}`).join('\n'));
|
|
193
|
+
}
|
|
194
|
+
lines.push('');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const items = result.results.map((r) => r.identifier ? `${r.cid} (${r.identifier})` : String(r.cid));
|
|
199
|
+
lines.push(`CIDs: ${items.join(', ')}`);
|
|
200
|
+
}
|
|
201
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
//# sourceMappingURL=search-compounds.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-compounds.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/search-compounds.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC;IAC5B,YAAY;IACZ,SAAS;IACT,cAAc;IACd,gBAAgB;IAChB,YAAY;CACb,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAA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,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAC5D,CAAC;YACF,KAAK,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;QAED,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview PubChem API client with rate limiting, retry, and response parsing.
|
|
3
|
+
* Wraps both PUG REST and PUG View APIs behind a shared rate limiter.
|
|
4
|
+
* @module services/pubchem/pubchem-client
|
|
5
|
+
*/
|
|
6
|
+
import type { BioactivityRow, GHSClassification } from './types.js';
|
|
7
|
+
export declare class PubChemClient {
|
|
8
|
+
private readonly pugBase;
|
|
9
|
+
private readonly viewBase;
|
|
10
|
+
private readonly rateLimiter;
|
|
11
|
+
private fetchJson;
|
|
12
|
+
private fetchBinary;
|
|
13
|
+
/** Fetch CID list, with automatic ListKey polling for async searches */
|
|
14
|
+
private fetchCids;
|
|
15
|
+
/** Poll a PubChem ListKey until results are ready */
|
|
16
|
+
private pollListKey;
|
|
17
|
+
searchByName(name: string): Promise<number[]>;
|
|
18
|
+
searchBySmiles(smiles: string): Promise<number[]>;
|
|
19
|
+
searchByInchiKey(inchikey: string): Promise<number[]>;
|
|
20
|
+
searchByFormula(formula: string, allowOther?: boolean): Promise<number[]>;
|
|
21
|
+
searchByStructure(mode: 'substructure' | 'superstructure' | 'similarity', query: string, queryType: 'smiles' | 'cid', threshold?: number): Promise<number[]>;
|
|
22
|
+
getProperties(cids: number[], properties: string[]): Promise<Array<Record<string, unknown> & {
|
|
23
|
+
CID: number;
|
|
24
|
+
}>>;
|
|
25
|
+
getSynonyms(cid: number): Promise<string[]>;
|
|
26
|
+
getImage(cid: number, size?: 'small' | 'large'): Promise<ArrayBuffer>;
|
|
27
|
+
getXrefs(cid: number, xrefType: string): Promise<(string | number)[]>;
|
|
28
|
+
getDescription(cid: number): Promise<string | null>;
|
|
29
|
+
getSafetyData(cid: number): Promise<GHSClassification | null>;
|
|
30
|
+
getAssaySummary(cid: number): Promise<BioactivityRow[]>;
|
|
31
|
+
private parseAssayTable;
|
|
32
|
+
searchAssaysByTarget(targetType: string, query: string): Promise<number[]>;
|
|
33
|
+
getEntitySummary(entityType: string, identifier: string | number): Promise<Record<string, unknown> | null>;
|
|
34
|
+
}
|
|
35
|
+
export declare function initPubChemClient(): void;
|
|
36
|
+
export declare function getPubChemClient(): PubChemClient;
|
|
37
|
+
//# sourceMappingURL=pubchem-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pubchem-client.d.ts","sourceRoot":"","sources":["../../../src/services/pubchem/pubchem-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAGV,cAAc,EAEd,iBAAiB,EAQlB,MAAM,YAAY,CAAC;AAuJpB,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+C;IACvE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoD;IAC7E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;YAIpC,SAAS;YAgDT,WAAW;IAwBzB,wEAAwE;YAC1D,SAAS;IAWvB,qDAAqD;YACvC,WAAW;IAgBzB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI7C,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQjD,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAMrD,eAAe,CAAC,OAAO,EAAE,MAAM,EAA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