@cyanheads/pubmed-mcp-server
Version:
Production-ready PubMed Model Context Protocol (MCP) server that empowers AI agents and research tools with comprehensive access to PubMed's article database. Enables advanced, automated LLM workflows for searching, retrieving, analyzing, and visualizing
68 lines • 3.11 kB
JavaScript
import { BaseErrorCode, McpError } from "../../../types-global/errors.js";
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
import { PubMedGenerateChartInputSchema, pubmedGenerateChartLogic, } from "./logic.js";
export async function registerPubMedGenerateChartTool(server) {
const operation = "registerPubMedGenerateChartTool";
const toolName = "pubmed_generate_chart";
const toolDescription = "Generates a customizable chart (PNG) from structured data. Supports various plot types and requires data values and field mappings for axes. Returns a Base64-encoded PNG image.";
const context = requestContextService.createRequestContext({ operation });
await ErrorHandler.tryCatch(async () => {
server.tool(toolName, toolDescription, PubMedGenerateChartInputSchema.shape, async (input, mcpProvidedContext) => {
const richContext = requestContextService.createRequestContext({
parentRequestId: context.requestId,
operation: "pubmedGenerateChartToolHandler",
mcpToolContext: mcpProvidedContext,
input,
});
try {
const result = await pubmedGenerateChartLogic(input, richContext);
return {
content: [
{
type: "image",
data: result.base64Data,
mimeType: "image/png",
},
],
isError: false,
};
}
catch (error) {
const handledError = ErrorHandler.handleError(error, {
operation: "pubmedGenerateChartToolHandler",
context: richContext,
input,
rethrow: false,
});
const mcpError = handledError instanceof McpError
? handledError
: new McpError(BaseErrorCode.INTERNAL_ERROR, "An unexpected error occurred while generating the chart.", {
originalErrorName: handledError.name,
originalErrorMessage: handledError.message,
});
return {
content: [
{
type: "text",
text: JSON.stringify({
error: {
code: mcpError.code,
message: mcpError.message,
details: mcpError.details,
},
}),
},
],
isError: true,
};
}
});
logger.notice(`Tool '${toolName}' registered.`, context);
}, {
operation,
context,
errorCode: BaseErrorCode.INITIALIZATION_FAILED,
critical: true,
});
}
//# sourceMappingURL=registration.js.map