@cyanheads/pubchem-mcp-server 1.0.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 +201 -0
- package/README.md +236 -0
- package/dist/config/index.d.ts +98 -0
- package/dist/config/index.js +326 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +214 -0
- package/dist/mcp-server/server.d.ts +21 -0
- package/dist/mcp-server/server.js +124 -0
- package/dist/mcp-server/tools/fetchAssaySummary/index.d.ts +7 -0
- package/dist/mcp-server/tools/fetchAssaySummary/index.js +7 -0
- package/dist/mcp-server/tools/fetchAssaySummary/logic.d.ts +71 -0
- package/dist/mcp-server/tools/fetchAssaySummary/logic.js +96 -0
- package/dist/mcp-server/tools/fetchAssaySummary/registration.d.ts +12 -0
- package/dist/mcp-server/tools/fetchAssaySummary/registration.js +68 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/index.d.ts +7 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/index.js +7 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/logic.d.ts +131 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/logic.js +100 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/registration.d.ts +13 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/registration.js +52 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/index.d.ts +7 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/index.js +7 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/logic.d.ts +89 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/logic.js +145 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/registration.d.ts +13 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/registration.js +52 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/index.d.ts +7 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/index.js +7 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/logic.d.ts +69 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/logic.js +97 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/registration.d.ts +13 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/registration.js +79 -0
- package/dist/mcp-server/tools/getCompoundImage/index.d.ts +7 -0
- package/dist/mcp-server/tools/getCompoundImage/index.js +7 -0
- package/dist/mcp-server/tools/getCompoundImage/logic.d.ts +42 -0
- package/dist/mcp-server/tools/getCompoundImage/logic.js +68 -0
- package/dist/mcp-server/tools/getCompoundImage/registration.d.ts +12 -0
- package/dist/mcp-server/tools/getCompoundImage/registration.js +57 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/index.js +7 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/logic.d.ts +35 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/logic.js +64 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/registration.d.ts +12 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/registration.js +62 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/index.js +7 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/logic.d.ts +35 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/logic.js +59 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/registration.d.ts +12 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/registration.js +51 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/index.js +7 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/logic.d.ts +38 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/logic.js +75 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/registration.d.ts +12 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/registration.js +62 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/index.js +7 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/logic.d.ts +41 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/logic.js +82 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/registration.d.ts +12 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/registration.js +62 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/index.js +7 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/logic.d.ts +41 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/logic.js +78 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/registration.d.ts +13 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/registration.js +63 -0
- package/dist/mcp-server/transports/auth/core/authContext.d.ts +33 -0
- package/dist/mcp-server/transports/auth/core/authContext.js +24 -0
- package/dist/mcp-server/transports/auth/core/authTypes.d.ts +17 -0
- package/dist/mcp-server/transports/auth/core/authTypes.js +5 -0
- package/dist/mcp-server/transports/auth/core/authUtils.d.ts +18 -0
- package/dist/mcp-server/transports/auth/core/authUtils.js +45 -0
- package/dist/mcp-server/transports/auth/index.d.ts +10 -0
- package/dist/mcp-server/transports/auth/index.js +9 -0
- package/dist/mcp-server/transports/auth/strategies/jwt/jwtMiddleware.d.ts +27 -0
- package/dist/mcp-server/transports/auth/strategies/jwt/jwtMiddleware.js +149 -0
- package/dist/mcp-server/transports/auth/strategies/oauth/oauthMiddleware.d.ts +20 -0
- package/dist/mcp-server/transports/auth/strategies/oauth/oauthMiddleware.js +124 -0
- package/dist/mcp-server/transports/httpErrorHandler.d.ts +26 -0
- package/dist/mcp-server/transports/httpErrorHandler.js +73 -0
- package/dist/mcp-server/transports/httpTransport.d.ts +21 -0
- package/dist/mcp-server/transports/httpTransport.js +208 -0
- package/dist/mcp-server/transports/stdioTransport.d.ts +42 -0
- package/dist/mcp-server/transports/stdioTransport.js +63 -0
- package/dist/services/pubchem/pubchemApiClient.d.ts +52 -0
- package/dist/services/pubchem/pubchemApiClient.js +120 -0
- package/dist/types-global/errors.d.ts +127 -0
- package/dist/types-global/errors.js +126 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/internal/errorHandler.d.ts +176 -0
- package/dist/utils/internal/errorHandler.js +335 -0
- package/dist/utils/internal/index.d.ts +9 -0
- package/dist/utils/internal/index.js +9 -0
- package/dist/utils/internal/logger.d.ts +148 -0
- package/dist/utils/internal/logger.js +430 -0
- package/dist/utils/internal/requestContext.d.ts +83 -0
- package/dist/utils/internal/requestContext.js +72 -0
- package/dist/utils/metrics/index.d.ts +7 -0
- package/dist/utils/metrics/index.js +7 -0
- package/dist/utils/metrics/tokenCounter.d.ts +35 -0
- package/dist/utils/metrics/tokenCounter.js +110 -0
- package/dist/utils/network/fetchWithTimeout.d.ts +21 -0
- package/dist/utils/network/fetchWithTimeout.js +59 -0
- package/dist/utils/network/index.d.ts +6 -0
- package/dist/utils/network/index.js +5 -0
- package/dist/utils/parsing/dateParser.d.ts +73 -0
- package/dist/utils/parsing/dateParser.js +107 -0
- package/dist/utils/parsing/index.d.ts +8 -0
- package/dist/utils/parsing/index.js +8 -0
- package/dist/utils/parsing/jsonParser.d.ts +82 -0
- package/dist/utils/parsing/jsonParser.js +126 -0
- package/dist/utils/scheduling/index.d.ts +6 -0
- package/dist/utils/scheduling/index.js +6 -0
- package/dist/utils/scheduling/scheduler.d.ts +72 -0
- package/dist/utils/scheduling/scheduler.js +152 -0
- package/dist/utils/security/idGenerator.d.ts +137 -0
- package/dist/utils/security/idGenerator.js +215 -0
- package/dist/utils/security/index.d.ts +9 -0
- package/dist/utils/security/index.js +9 -0
- package/dist/utils/security/rateLimiter.d.ts +108 -0
- package/dist/utils/security/rateLimiter.js +179 -0
- package/dist/utils/security/sanitization.d.ts +184 -0
- package/dist/utils/security/sanitization.js +453 -0
- package/package.json +108 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Handles the registration of the `pubchem_fetch_compound_properties` tool.
|
|
3
|
+
* @module src/mcp-server/tools/fetchCompoundProperties/registration
|
|
4
|
+
*/
|
|
5
|
+
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
|
|
6
|
+
import { PubchemFetchCompoundPropertiesInputSchema, pubchemFetchCompoundPropertiesLogic, } from "./logic.js";
|
|
7
|
+
/**
|
|
8
|
+
* Registers the 'pubchem_fetch_compound_properties' tool with the MCP server.
|
|
9
|
+
* This tool fetches a list of specified physicochemical properties for one or more
|
|
10
|
+
* PubChem Compound IDs (CIDs).
|
|
11
|
+
*
|
|
12
|
+
* @param {McpServer} server - The MCP server instance to register the tool with.
|
|
13
|
+
*/
|
|
14
|
+
export const registerPubchemFetchCompoundPropertiesTool = async (server) => {
|
|
15
|
+
const toolName = "pubchem_fetch_compound_properties";
|
|
16
|
+
const toolDescription = "Fetches a list of specified physicochemical properties (e.g., MolecularWeight, XLogP) for one or more PubChem Compound IDs (CIDs). Essential for retrieving detailed chemical data in bulk.";
|
|
17
|
+
server.tool(toolName, toolDescription, PubchemFetchCompoundPropertiesInputSchema.shape, async (params, mcpContext) => {
|
|
18
|
+
const handlerContext = requestContextService.createRequestContext({
|
|
19
|
+
operation: "HandleToolRequest",
|
|
20
|
+
toolName,
|
|
21
|
+
mcpToolContext: mcpContext,
|
|
22
|
+
input: params,
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
logger.info(`Initiating tool request for ${toolName} for ${params.cids.length} CIDs.`, handlerContext);
|
|
26
|
+
const result = await pubchemFetchCompoundPropertiesLogic(params, handlerContext);
|
|
27
|
+
return {
|
|
28
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
29
|
+
isError: false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const handledError = ErrorHandler.handleError(error, {
|
|
34
|
+
operation: "pubchemFetchCompoundPropertiesToolHandler",
|
|
35
|
+
context: handlerContext,
|
|
36
|
+
input: params,
|
|
37
|
+
});
|
|
38
|
+
// No need to log here, handleError already does it.
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: JSON.stringify({
|
|
44
|
+
error: ErrorHandler.formatError(handledError),
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
isError: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for the `pubchem_fetch_compound_xrefs` tool.
|
|
3
|
+
* This file serves as the public interface for the tool module,
|
|
4
|
+
* primarily exporting the `registerPubchemFetchCompoundXrefsTool` function.
|
|
5
|
+
* @module src/mcp-server/tools/fetchCompoundXrefs/index
|
|
6
|
+
*/
|
|
7
|
+
export { registerPubchemFetchCompoundXrefsTool } from "./registration.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for the `pubchem_fetch_compound_xrefs` tool.
|
|
3
|
+
* This file serves as the public interface for the tool module,
|
|
4
|
+
* primarily exporting the `registerPubchemFetchCompoundXrefsTool` function.
|
|
5
|
+
* @module src/mcp-server/tools/fetchCompoundXrefs/index
|
|
6
|
+
*/
|
|
7
|
+
export { registerPubchemFetchCompoundXrefsTool } from "./registration.js";
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Defines the core logic, schemas, and types for the `pubchem_fetch_compound_xrefs` tool.
|
|
3
|
+
* This version includes pagination for large responses.
|
|
4
|
+
* @module src/mcp-server/tools/fetchCompoundXrefs/logic
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { type RequestContext } from "../../../utils/index.js";
|
|
8
|
+
export declare const PubchemXrefTypesEnum: z.ZodEnum<["RegistryID", "RN", "PubMedID", "PatentID", "GeneID", "ProteinGI", "TaxonomyID"]>;
|
|
9
|
+
export declare const PubchemFetchCompoundXrefsInputSchema: z.ZodObject<{
|
|
10
|
+
cid: z.ZodNumber;
|
|
11
|
+
xrefTypes: z.ZodArray<z.ZodEnum<["RegistryID", "RN", "PubMedID", "PatentID", "GeneID", "ProteinGI", "TaxonomyID"]>, "many">;
|
|
12
|
+
page: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
13
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
cid: number;
|
|
16
|
+
xrefTypes: ("RegistryID" | "RN" | "PubMedID" | "PatentID" | "GeneID" | "ProteinGI" | "TaxonomyID")[];
|
|
17
|
+
page: number;
|
|
18
|
+
pageSize: number;
|
|
19
|
+
}, {
|
|
20
|
+
cid: number;
|
|
21
|
+
xrefTypes: ("RegistryID" | "RN" | "PubMedID" | "PatentID" | "GeneID" | "ProteinGI" | "TaxonomyID")[];
|
|
22
|
+
page?: number | undefined;
|
|
23
|
+
pageSize?: number | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export type PubchemFetchCompoundXrefsInput = z.infer<typeof PubchemFetchCompoundXrefsInputSchema>;
|
|
26
|
+
export declare const PubchemFetchCompoundXrefsOutputSchema: z.ZodObject<{
|
|
27
|
+
cid: z.ZodNumber;
|
|
28
|
+
xrefs: z.ZodArray<z.ZodObject<{
|
|
29
|
+
type: z.ZodString;
|
|
30
|
+
ids: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
type: string;
|
|
33
|
+
ids: (string | number)[];
|
|
34
|
+
}, {
|
|
35
|
+
type: string;
|
|
36
|
+
ids: (string | number)[];
|
|
37
|
+
}>, "many">;
|
|
38
|
+
pagination: z.ZodObject<{
|
|
39
|
+
currentPage: z.ZodNumber;
|
|
40
|
+
pageSize: z.ZodNumber;
|
|
41
|
+
totalRecords: z.ZodNumber;
|
|
42
|
+
totalPages: z.ZodNumber;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
pageSize: number;
|
|
45
|
+
currentPage: number;
|
|
46
|
+
totalRecords: number;
|
|
47
|
+
totalPages: number;
|
|
48
|
+
}, {
|
|
49
|
+
pageSize: number;
|
|
50
|
+
currentPage: number;
|
|
51
|
+
totalRecords: number;
|
|
52
|
+
totalPages: number;
|
|
53
|
+
}>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
cid: number;
|
|
56
|
+
xrefs: {
|
|
57
|
+
type: string;
|
|
58
|
+
ids: (string | number)[];
|
|
59
|
+
}[];
|
|
60
|
+
pagination: {
|
|
61
|
+
pageSize: number;
|
|
62
|
+
currentPage: number;
|
|
63
|
+
totalRecords: number;
|
|
64
|
+
totalPages: number;
|
|
65
|
+
};
|
|
66
|
+
}, {
|
|
67
|
+
cid: number;
|
|
68
|
+
xrefs: {
|
|
69
|
+
type: string;
|
|
70
|
+
ids: (string | number)[];
|
|
71
|
+
}[];
|
|
72
|
+
pagination: {
|
|
73
|
+
pageSize: number;
|
|
74
|
+
currentPage: number;
|
|
75
|
+
totalRecords: number;
|
|
76
|
+
totalPages: number;
|
|
77
|
+
};
|
|
78
|
+
}>;
|
|
79
|
+
export type PubchemFetchCompoundXrefsOutput = z.infer<typeof PubchemFetchCompoundXrefsOutputSchema>;
|
|
80
|
+
/**
|
|
81
|
+
* Core logic for the `pubchem_fetch_compound_xrefs` tool. It retrieves a paginated
|
|
82
|
+
* list of external cross-references (XRefs) for a given PubChem Compound ID (CID).
|
|
83
|
+
*
|
|
84
|
+
* @param {PubchemFetchCompoundXrefsInput} params - The validated input parameters.
|
|
85
|
+
* @param {RequestContext} context - The request context for logging, tracing, and error handling.
|
|
86
|
+
* @returns {Promise<PubchemFetchCompoundXrefsOutput>} A promise that resolves with the paginated cross-reference results.
|
|
87
|
+
* @throws {McpError} Throws a structured error if the API request fails, the CID is not found, or the response is malformed.
|
|
88
|
+
*/
|
|
89
|
+
export declare function pubchemFetchCompoundXrefsLogic(params: PubchemFetchCompoundXrefsInput, context: RequestContext): Promise<PubchemFetchCompoundXrefsOutput>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Defines the core logic, schemas, and types for the `pubchem_fetch_compound_xrefs` tool.
|
|
3
|
+
* This version includes pagination for large responses.
|
|
4
|
+
* @module src/mcp-server/tools/fetchCompoundXrefs/logic
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { pubChemApiClient } from "../../../services/pubchem/pubchemApiClient.js";
|
|
8
|
+
import { BaseErrorCode, McpError } from "../../../types-global/errors.js";
|
|
9
|
+
import { logger } from "../../../utils/index.js";
|
|
10
|
+
// 1. Define and export the Zod enum for available cross-reference types
|
|
11
|
+
export const PubchemXrefTypesEnum = z.enum([
|
|
12
|
+
"RegistryID",
|
|
13
|
+
"RN",
|
|
14
|
+
"PubMedID",
|
|
15
|
+
"PatentID",
|
|
16
|
+
"GeneID",
|
|
17
|
+
"ProteinGI",
|
|
18
|
+
"TaxonomyID",
|
|
19
|
+
]);
|
|
20
|
+
// 2. Define and export the Zod schema for input validation
|
|
21
|
+
export const PubchemFetchCompoundXrefsInputSchema = z.object({
|
|
22
|
+
cid: z
|
|
23
|
+
.number()
|
|
24
|
+
.int()
|
|
25
|
+
.positive()
|
|
26
|
+
.describe("The PubChem Compound ID (CID) to find cross-references for. Must be a positive integer."),
|
|
27
|
+
xrefTypes: z
|
|
28
|
+
.array(PubchemXrefTypesEnum)
|
|
29
|
+
.min(1, "At least one cross-reference type is required.")
|
|
30
|
+
.describe("A list of cross-reference types to retrieve."),
|
|
31
|
+
page: z
|
|
32
|
+
.number()
|
|
33
|
+
.int()
|
|
34
|
+
.positive()
|
|
35
|
+
.optional()
|
|
36
|
+
.default(1)
|
|
37
|
+
.describe("The page number for pagination, used when the result set is large. Defaults to 1."),
|
|
38
|
+
pageSize: z
|
|
39
|
+
.number()
|
|
40
|
+
.int()
|
|
41
|
+
.positive()
|
|
42
|
+
.optional()
|
|
43
|
+
.default(50)
|
|
44
|
+
.describe("The number of records to return per page. Defaults to 50."),
|
|
45
|
+
});
|
|
46
|
+
// 4. Define and export the Zod schemas for the tool's output
|
|
47
|
+
const XrefGroupSchema = z.object({
|
|
48
|
+
type: z
|
|
49
|
+
.string()
|
|
50
|
+
.describe("The type of the cross-reference (e.g., 'PubMedID')."),
|
|
51
|
+
ids: z
|
|
52
|
+
.array(z.union([z.string(), z.number()]))
|
|
53
|
+
.describe("A list of identifiers for this type."),
|
|
54
|
+
});
|
|
55
|
+
const PaginationSchema = z.object({
|
|
56
|
+
currentPage: z.number().int().describe("The current page number."),
|
|
57
|
+
pageSize: z.number().int().describe("The number of records per page."),
|
|
58
|
+
totalRecords: z
|
|
59
|
+
.number()
|
|
60
|
+
.int()
|
|
61
|
+
.describe("The total number of records available."),
|
|
62
|
+
totalPages: z.number().int().describe("The total number of pages available."),
|
|
63
|
+
});
|
|
64
|
+
export const PubchemFetchCompoundXrefsOutputSchema = z.object({
|
|
65
|
+
cid: z.number().int().describe("The CID for which xrefs were fetched."),
|
|
66
|
+
xrefs: z
|
|
67
|
+
.array(XrefGroupSchema)
|
|
68
|
+
.describe("A paginated list of cross-references, grouped by type."),
|
|
69
|
+
pagination: PaginationSchema.describe("Pagination details for the result set."),
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* Core logic for the `pubchem_fetch_compound_xrefs` tool. It retrieves a paginated
|
|
73
|
+
* list of external cross-references (XRefs) for a given PubChem Compound ID (CID).
|
|
74
|
+
*
|
|
75
|
+
* @param {PubchemFetchCompoundXrefsInput} params - The validated input parameters.
|
|
76
|
+
* @param {RequestContext} context - The request context for logging, tracing, and error handling.
|
|
77
|
+
* @returns {Promise<PubchemFetchCompoundXrefsOutput>} A promise that resolves with the paginated cross-reference results.
|
|
78
|
+
* @throws {McpError} Throws a structured error if the API request fails, the CID is not found, or the response is malformed.
|
|
79
|
+
*/
|
|
80
|
+
export async function pubchemFetchCompoundXrefsLogic(params, context) {
|
|
81
|
+
logger.debug("Processing pubchem_fetch_compound_xrefs logic...", {
|
|
82
|
+
...context,
|
|
83
|
+
params,
|
|
84
|
+
});
|
|
85
|
+
const { cid, xrefTypes, page, pageSize } = params;
|
|
86
|
+
const allXrefs = [];
|
|
87
|
+
// Fetch each xref type individually to avoid timeouts on large requests
|
|
88
|
+
for (const xrefType of xrefTypes) {
|
|
89
|
+
const path = `/compound/cid/${cid}/xrefs/${xrefType}/JSON`;
|
|
90
|
+
logger.debug(`Fetching xref type: ${xrefType}`, { ...context, cid, path });
|
|
91
|
+
try {
|
|
92
|
+
const response = await pubChemApiClient.get(path, context);
|
|
93
|
+
if (response?.InformationList?.Information) {
|
|
94
|
+
for (const info of response.InformationList.Information) {
|
|
95
|
+
if (info[xrefType] && Array.isArray(info[xrefType])) {
|
|
96
|
+
for (const id of info[xrefType]) {
|
|
97
|
+
allXrefs.push({ type: xrefType, id });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
// Log the error for the specific xref type but continue with others
|
|
105
|
+
logger.warning(`Failed to fetch xref type '${xrefType}' for CID ${cid}`, {
|
|
106
|
+
...context,
|
|
107
|
+
cid,
|
|
108
|
+
error,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (allXrefs.length === 0) {
|
|
113
|
+
throw new McpError(BaseErrorCode.NOT_FOUND, `No cross-references found for CID ${cid} with the specified types.`, { ...context, cid, xrefTypes });
|
|
114
|
+
}
|
|
115
|
+
// Group the flattened list by type
|
|
116
|
+
const groupedXrefs = allXrefs.reduce((acc, { type, id }) => {
|
|
117
|
+
if (!acc[type]) {
|
|
118
|
+
acc[type] = [];
|
|
119
|
+
}
|
|
120
|
+
acc[type].push(id);
|
|
121
|
+
return acc;
|
|
122
|
+
}, {});
|
|
123
|
+
// Convert the grouped map to an array of objects for pagination
|
|
124
|
+
const xrefGroups = Object.entries(groupedXrefs).map(([type, ids]) => ({
|
|
125
|
+
type,
|
|
126
|
+
ids,
|
|
127
|
+
}));
|
|
128
|
+
// Paginate the grouped list
|
|
129
|
+
const totalRecords = xrefGroups.length;
|
|
130
|
+
const totalPages = Math.ceil(totalRecords / pageSize);
|
|
131
|
+
const startIndex = (page - 1) * pageSize;
|
|
132
|
+
const paginatedXrefGroups = xrefGroups.slice(startIndex, startIndex + pageSize);
|
|
133
|
+
const result = {
|
|
134
|
+
cid,
|
|
135
|
+
xrefs: paginatedXrefGroups,
|
|
136
|
+
pagination: {
|
|
137
|
+
currentPage: page,
|
|
138
|
+
pageSize,
|
|
139
|
+
totalRecords,
|
|
140
|
+
totalPages,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
logger.info(`Successfully fetched page ${page}/${totalPages} of xrefs for CID ${cid}.`, context);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Handles the registration of the `pubchem_fetch_compound_xrefs` tool.
|
|
3
|
+
* @module src/mcp-server/tools/fetchCompoundXrefs/registration
|
|
4
|
+
*/
|
|
5
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
/**
|
|
7
|
+
* Registers the 'pubchem_fetch_compound_xrefs' tool with the MCP server.
|
|
8
|
+
* This tool fetches a paginated list of external cross-references (XRefs) for a given
|
|
9
|
+
* PubChem Compound ID (CID).
|
|
10
|
+
*
|
|
11
|
+
* @param {McpServer} server - The MCP server instance to register the tool with.
|
|
12
|
+
*/
|
|
13
|
+
export declare const registerPubchemFetchCompoundXrefsTool: (server: McpServer) => Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Handles the registration of the `pubchem_fetch_compound_xrefs` tool.
|
|
3
|
+
* @module src/mcp-server/tools/fetchCompoundXrefs/registration
|
|
4
|
+
*/
|
|
5
|
+
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
|
|
6
|
+
import { PubchemFetchCompoundXrefsInputSchema, pubchemFetchCompoundXrefsLogic, } from "./logic.js";
|
|
7
|
+
/**
|
|
8
|
+
* Registers the 'pubchem_fetch_compound_xrefs' tool with the MCP server.
|
|
9
|
+
* This tool fetches a paginated list of external cross-references (XRefs) for a given
|
|
10
|
+
* PubChem Compound ID (CID).
|
|
11
|
+
*
|
|
12
|
+
* @param {McpServer} server - The MCP server instance to register the tool with.
|
|
13
|
+
*/
|
|
14
|
+
export const registerPubchemFetchCompoundXrefsTool = async (server) => {
|
|
15
|
+
const toolName = "pubchem_fetch_compound_xrefs";
|
|
16
|
+
const toolDescription = "Fetches external cross-references (XRefs) for a given PubChem Compound ID (CID), such as Registry IDs, Patent IDs, or PubMed IDs. Supports pagination for handling large result sets.";
|
|
17
|
+
server.tool(toolName, toolDescription, PubchemFetchCompoundXrefsInputSchema.shape, async (params, mcpContext) => {
|
|
18
|
+
const handlerContext = requestContextService.createRequestContext({
|
|
19
|
+
operation: "HandleToolRequest",
|
|
20
|
+
toolName,
|
|
21
|
+
mcpToolContext: mcpContext,
|
|
22
|
+
input: params,
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
logger.info(`Initiating tool request for ${toolName} for CID: ${params.cid}`, handlerContext);
|
|
26
|
+
const result = await pubchemFetchCompoundXrefsLogic(params, handlerContext);
|
|
27
|
+
return {
|
|
28
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
29
|
+
isError: false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const handledError = ErrorHandler.handleError(error, {
|
|
34
|
+
operation: "pubchemFetchCompoundXrefsToolHandler",
|
|
35
|
+
context: handlerContext,
|
|
36
|
+
input: params,
|
|
37
|
+
});
|
|
38
|
+
// No need to log here, handleError already does it.
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: JSON.stringify({
|
|
44
|
+
error: ErrorHandler.formatError(handledError),
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
isError: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for the `pubchem_fetch_substance_details` tool.
|
|
3
|
+
* This file serves as the public interface for the tool module,
|
|
4
|
+
* primarily exporting the `registerPubchemFetchSubstanceDetailsTool` function.
|
|
5
|
+
* @module src/mcp-server/tools/fetchSubstanceDetails/index
|
|
6
|
+
*/
|
|
7
|
+
export { registerPubchemFetchSubstanceDetailsTool } from "./registration.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for the `pubchem_fetch_substance_details` tool.
|
|
3
|
+
* This file serves as the public interface for the tool module,
|
|
4
|
+
* primarily exporting the `registerPubchemFetchSubstanceDetailsTool` function.
|
|
5
|
+
* @module src/mcp-server/tools/fetchSubstanceDetails/index
|
|
6
|
+
*/
|
|
7
|
+
export { registerPubchemFetchSubstanceDetailsTool } from "./registration.js";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Defines the core logic, schemas, and types for the `pubchem_fetch_substance_details` tool.
|
|
3
|
+
* @module src/mcp-server/tools/fetchSubstanceDetails/logic
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { type RequestContext } from "../../../utils/index.js";
|
|
7
|
+
export declare const PubchemFetchSubstanceDetailsInputSchema: z.ZodObject<{
|
|
8
|
+
sid: z.ZodNumber;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
sid: number;
|
|
11
|
+
}, {
|
|
12
|
+
sid: number;
|
|
13
|
+
}>;
|
|
14
|
+
export type PubchemFetchSubstanceDetailsInput = z.infer<typeof PubchemFetchSubstanceDetailsInputSchema>;
|
|
15
|
+
export declare const PubchemFetchSubstanceDetailsOutputSchema: z.ZodObject<{
|
|
16
|
+
sid: z.ZodNumber;
|
|
17
|
+
source: z.ZodObject<{
|
|
18
|
+
name: z.ZodString;
|
|
19
|
+
sourceId: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
name: string;
|
|
22
|
+
sourceId?: string | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
name: string;
|
|
25
|
+
sourceId?: string | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
depositionDate: z.ZodString;
|
|
28
|
+
modificationDate: z.ZodString;
|
|
29
|
+
synonyms: z.ZodArray<z.ZodString, "many">;
|
|
30
|
+
relatedCids: z.ZodArray<z.ZodNumber, "many">;
|
|
31
|
+
xrefs: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodString>, "many">>;
|
|
32
|
+
compounds: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
sid: number;
|
|
35
|
+
source: {
|
|
36
|
+
name: string;
|
|
37
|
+
sourceId?: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
depositionDate: string;
|
|
40
|
+
modificationDate: string;
|
|
41
|
+
synonyms: string[];
|
|
42
|
+
relatedCids: number[];
|
|
43
|
+
xrefs?: Record<string, string>[] | undefined;
|
|
44
|
+
compounds?: any[] | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
sid: number;
|
|
47
|
+
source: {
|
|
48
|
+
name: string;
|
|
49
|
+
sourceId?: string | undefined;
|
|
50
|
+
};
|
|
51
|
+
depositionDate: string;
|
|
52
|
+
modificationDate: string;
|
|
53
|
+
synonyms: string[];
|
|
54
|
+
relatedCids: number[];
|
|
55
|
+
xrefs?: Record<string, string>[] | undefined;
|
|
56
|
+
compounds?: any[] | undefined;
|
|
57
|
+
}>;
|
|
58
|
+
export type PubchemFetchSubstanceDetailsOutput = z.infer<typeof PubchemFetchSubstanceDetailsOutputSchema>;
|
|
59
|
+
/**
|
|
60
|
+
* Core logic for the `pubchem_fetch_substance_details` tool. It retrieves detailed
|
|
61
|
+
* information for a given PubChem Substance ID (SID), including its source,
|
|
62
|
+
* synonyms, and any associated Compound IDs (CIDs).
|
|
63
|
+
*
|
|
64
|
+
* @param {PubchemFetchSubstanceDetailsInput} params - The validated input parameters.
|
|
65
|
+
* @param {RequestContext} context - The request context for logging, tracing, and error handling.
|
|
66
|
+
* @returns {Promise<PubchemFetchSubstanceDetailsOutput>} A promise that resolves with the substance details.
|
|
67
|
+
* @throws {McpError} Throws a structured error if the API requests fail, the SID is not found, or the response is malformed.
|
|
68
|
+
*/
|
|
69
|
+
export declare function pubchemFetchSubstanceDetailsLogic(params: PubchemFetchSubstanceDetailsInput, context: RequestContext): Promise<PubchemFetchSubstanceDetailsOutput>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Defines the core logic, schemas, and types for the `pubchem_fetch_substance_details` tool.
|
|
3
|
+
* @module src/mcp-server/tools/fetchSubstanceDetails/logic
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { pubChemApiClient } from "../../../services/pubchem/pubchemApiClient.js";
|
|
7
|
+
import { BaseErrorCode, McpError } from "../../../types-global/errors.js";
|
|
8
|
+
import { logger } from "../../../utils/index.js";
|
|
9
|
+
// 1. Define and export the Zod schema for input validation
|
|
10
|
+
export const PubchemFetchSubstanceDetailsInputSchema = z.object({
|
|
11
|
+
sid: z
|
|
12
|
+
.number()
|
|
13
|
+
.int()
|
|
14
|
+
.positive()
|
|
15
|
+
.describe("The PubChem Substance ID (SID) to retrieve details for. Must be a positive integer."),
|
|
16
|
+
});
|
|
17
|
+
// 3. Define and export the Zod schema for the tool's output
|
|
18
|
+
export const PubchemFetchSubstanceDetailsOutputSchema = z.object({
|
|
19
|
+
sid: z.number().int().describe("The unique PubChem Substance ID (SID)."),
|
|
20
|
+
source: z
|
|
21
|
+
.object({
|
|
22
|
+
name: z.string().describe("The name of the depositor or data source."),
|
|
23
|
+
sourceId: z
|
|
24
|
+
.string()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("The unique identifier for the substance within the source."),
|
|
27
|
+
})
|
|
28
|
+
.describe("The original source of the substance information."),
|
|
29
|
+
depositionDate: z
|
|
30
|
+
.string()
|
|
31
|
+
.describe("The date the substance was originally deposited, in YYYY/MM/DD format."),
|
|
32
|
+
modificationDate: z
|
|
33
|
+
.string()
|
|
34
|
+
.describe("The date the substance record was last modified, in YYYY/MM/DD format."),
|
|
35
|
+
synonyms: z
|
|
36
|
+
.array(z.string())
|
|
37
|
+
.describe("A list of alternative names or identifiers for the substance."),
|
|
38
|
+
relatedCids: z
|
|
39
|
+
.array(z.number().int())
|
|
40
|
+
.describe("A list of standardized PubChem Compound IDs (CIDs) that are structurally related to this substance."),
|
|
41
|
+
xrefs: z
|
|
42
|
+
.array(z.record(z.string()))
|
|
43
|
+
.optional()
|
|
44
|
+
.describe("A list of external cross-references, such as registry IDs or database URLs."),
|
|
45
|
+
compounds: z
|
|
46
|
+
.array(z.any())
|
|
47
|
+
.optional()
|
|
48
|
+
.describe("A list of associated compound structures, including atoms, bonds, and coordinates."),
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Core logic for the `pubchem_fetch_substance_details` tool. It retrieves detailed
|
|
52
|
+
* information for a given PubChem Substance ID (SID), including its source,
|
|
53
|
+
* synonyms, and any associated Compound IDs (CIDs).
|
|
54
|
+
*
|
|
55
|
+
* @param {PubchemFetchSubstanceDetailsInput} params - The validated input parameters.
|
|
56
|
+
* @param {RequestContext} context - The request context for logging, tracing, and error handling.
|
|
57
|
+
* @returns {Promise<PubchemFetchSubstanceDetailsOutput>} A promise that resolves with the substance details.
|
|
58
|
+
* @throws {McpError} Throws a structured error if the API requests fail, the SID is not found, or the response is malformed.
|
|
59
|
+
*/
|
|
60
|
+
export async function pubchemFetchSubstanceDetailsLogic(params, context) {
|
|
61
|
+
logger.debug("Processing pubchem_fetch_substance_details logic...", {
|
|
62
|
+
...context,
|
|
63
|
+
params,
|
|
64
|
+
});
|
|
65
|
+
const { sid } = params;
|
|
66
|
+
// A single API call to get all available substance details.
|
|
67
|
+
const detailsPath = `/substance/sid/${sid}/JSON`;
|
|
68
|
+
const detailsResponse = await pubChemApiClient.get(detailsPath, context);
|
|
69
|
+
logger.debug("Raw PubChem response for pubchem_fetch_substance_details", {
|
|
70
|
+
...context,
|
|
71
|
+
sid,
|
|
72
|
+
detailsResponse,
|
|
73
|
+
});
|
|
74
|
+
if (!detailsResponse || !detailsResponse.PC_Substances?.[0]) {
|
|
75
|
+
throw new McpError(BaseErrorCode.NOT_FOUND, `No substance details found for SID ${sid}, or the response from PubChem was malformed.`, { ...context, sid, response: detailsResponse });
|
|
76
|
+
}
|
|
77
|
+
const substance = detailsResponse.PC_Substances[0];
|
|
78
|
+
// Extract related CIDs directly from the substance details if available.
|
|
79
|
+
const relatedCids = substance.compound
|
|
80
|
+
?.map((c) => c.id?.id?.cid)
|
|
81
|
+
.filter((cid) => typeof cid === "number") || [];
|
|
82
|
+
const result = {
|
|
83
|
+
sid: substance.sid.id,
|
|
84
|
+
source: {
|
|
85
|
+
name: substance.source.db.name,
|
|
86
|
+
sourceId: substance.source.db.source_id?.str,
|
|
87
|
+
},
|
|
88
|
+
depositionDate: substance.dates?.deposition?.date.join("/") || "N/A",
|
|
89
|
+
modificationDate: substance.dates?.modification?.date.join("/") || "N/A",
|
|
90
|
+
synonyms: substance.synonyms || [],
|
|
91
|
+
relatedCids,
|
|
92
|
+
xrefs: substance.xref,
|
|
93
|
+
compounds: substance.compound,
|
|
94
|
+
};
|
|
95
|
+
logger.info(`Successfully fetched details for SID ${sid}.`, context);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Handles the registration of the `pubchem_fetch_substance_details` tool.
|
|
3
|
+
* @module src/mcp-server/tools/fetchSubstanceDetails/registration
|
|
4
|
+
*/
|
|
5
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
/**
|
|
7
|
+
* Registers the 'pubchem_fetch_substance_details' tool with the MCP server.
|
|
8
|
+
* This tool retrieves detailed information for a given PubChem Substance ID (SID),
|
|
9
|
+
* including its source, synonyms, and any associated Compound IDs (CIDs).
|
|
10
|
+
*
|
|
11
|
+
* @param {McpServer} server - The MCP server instance to register the tool with.
|
|
12
|
+
*/
|
|
13
|
+
export declare const registerPubchemFetchSubstanceDetailsTool: (server: McpServer) => Promise<void>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Handles the registration of the `pubchem_fetch_substance_details` tool.
|
|
3
|
+
* @module src/mcp-server/tools/fetchSubstanceDetails/registration
|
|
4
|
+
*/
|
|
5
|
+
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
|
|
6
|
+
import { PubchemFetchSubstanceDetailsInputSchema, pubchemFetchSubstanceDetailsLogic, } from "./logic.js";
|
|
7
|
+
/**
|
|
8
|
+
* Registers the 'pubchem_fetch_substance_details' tool with the MCP server.
|
|
9
|
+
* This tool retrieves detailed information for a given PubChem Substance ID (SID),
|
|
10
|
+
* including its source, synonyms, and any associated Compound IDs (CIDs).
|
|
11
|
+
*
|
|
12
|
+
* @param {McpServer} server - The MCP server instance to register the tool with.
|
|
13
|
+
*/
|
|
14
|
+
export const registerPubchemFetchSubstanceDetailsTool = async (server) => {
|
|
15
|
+
const toolName = "pubchem_fetch_substance_details";
|
|
16
|
+
const toolDescription = "Retrieves details for a given PubChem Substance ID (SID), including its synonyms, source, deposition/modification dates, and any associated standardized Compound IDs (CIDs).";
|
|
17
|
+
server.tool(toolName, toolDescription, PubchemFetchSubstanceDetailsInputSchema.shape, async (params, mcpContext) => {
|
|
18
|
+
const handlerContext = requestContextService.createRequestContext({
|
|
19
|
+
operation: "HandleToolRequest",
|
|
20
|
+
toolName,
|
|
21
|
+
mcpToolContext: mcpContext,
|
|
22
|
+
input: params,
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
logger.info(`Initiating tool request for ${toolName} for SID: ${params.sid}`, handlerContext);
|
|
26
|
+
const result = await pubchemFetchSubstanceDetailsLogic(params, handlerContext);
|
|
27
|
+
// Custom stringify to make large arrays of numbers more compact
|
|
28
|
+
const placeholderPrefix = "##JSON_STRINGIFY_PLACEHOLDER##";
|
|
29
|
+
let placeholderIndex = 0;
|
|
30
|
+
const placeholders = [];
|
|
31
|
+
const replacer = (key, value) => {
|
|
32
|
+
const compactArrayKeys = new Set([
|
|
33
|
+
"aid",
|
|
34
|
+
"element",
|
|
35
|
+
"aid1",
|
|
36
|
+
"aid2",
|
|
37
|
+
"order",
|
|
38
|
+
"x",
|
|
39
|
+
"y",
|
|
40
|
+
]);
|
|
41
|
+
if (compactArrayKeys.has(key) &&
|
|
42
|
+
Array.isArray(value) &&
|
|
43
|
+
value.every((item) => typeof item === "number")) {
|
|
44
|
+
const placeholder = `${placeholderPrefix}${placeholderIndex++}`;
|
|
45
|
+
placeholders.push(JSON.stringify(value));
|
|
46
|
+
return placeholder;
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
let text = JSON.stringify(result, replacer, 2);
|
|
51
|
+
for (let i = 0; i < placeholders.length; i++) {
|
|
52
|
+
text = text.replace(`"${placeholderPrefix}${i}"`, placeholders[i]);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
content: [{ type: "text", text }],
|
|
56
|
+
isError: false,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const handledError = ErrorHandler.handleError(error, {
|
|
61
|
+
operation: "pubchemFetchSubstanceDetailsToolHandler",
|
|
62
|
+
context: handlerContext,
|
|
63
|
+
input: params,
|
|
64
|
+
});
|
|
65
|
+
// No need to log here, handleError already does it.
|
|
66
|
+
return {
|
|
67
|
+
content: [
|
|
68
|
+
{
|
|
69
|
+
type: "text",
|
|
70
|
+
text: JSON.stringify({
|
|
71
|
+
error: ErrorHandler.formatError(handledError),
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
isError: true,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for the `pubchem_get_compound_image` tool.
|
|
3
|
+
* This file serves as the public interface for the tool module,
|
|
4
|
+
* primarily exporting the `registerPubchemGetCompoundImageTool` function.
|
|
5
|
+
* @module src/mcp-server/tools/getCompoundImage/index
|
|
6
|
+
*/
|
|
7
|
+
export { registerPubchemGetCompoundImageTool } from "./registration.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for the `pubchem_get_compound_image` tool.
|
|
3
|
+
* This file serves as the public interface for the tool module,
|
|
4
|
+
* primarily exporting the `registerPubchemGetCompoundImageTool` function.
|
|
5
|
+
* @module src/mcp-server/tools/getCompoundImage/index
|
|
6
|
+
*/
|
|
7
|
+
export { registerPubchemGetCompoundImageTool } from "./registration.js";
|