@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
73 lines • 3.86 kB
JavaScript
/**
* @fileoverview Registration for the pubmed_research_agent tool.
* @module pubmedResearchAgent/registration
*/
import { BaseErrorCode, McpError } from "../../../types-global/errors.js";
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
import { pubmedResearchAgentLogic } from "./logic.js";
import { PubMedResearchAgentInputSchema, } from "./logic/index.js";
/**
* Registers the pubmed_research_agent tool with the MCP server.
* @param server - The McpServer instance.
*/
export async function registerPubMedResearchAgentTool(server) {
const operation = "registerPubMedResearchAgentTool";
const toolName = "pubmed_research_agent";
const toolDescription = "Generates a standardized JSON research plan outline from component details you provide. It accepts granular inputs for all research phases (conception, data collection, analysis, dissemination, cross-cutting concerns). If `include_detailed_prompts_for_agent` is true, the output plan will embed instructive prompts and detailed guidance notes to aid the research agent. The tool's primary function is to organize and structure your rough ideas into a formal, machine-readable plan. This plan is intended for further processing; as the research agent, you should then utilize your full suite of tools (e.g., file manipulation, `get_pubmed_article_connections` for literature/data search via PMID) to execute the outlined research, tailored to the user's request.";
const context = requestContextService.createRequestContext({ operation });
await ErrorHandler.tryCatch(async () => {
server.tool(toolName, toolDescription, PubMedResearchAgentInputSchema.shape, async (input, mcpProvidedContext) => {
const richContext = requestContextService.createRequestContext({
parentRequestId: context.requestId,
operation: "pubmedResearchAgentToolHandler",
mcpToolContext: mcpProvidedContext,
input,
});
try {
const result = await pubmedResearchAgentLogic(input, richContext);
return {
content: [
{ type: "text", text: JSON.stringify(result, null, 2) },
],
isError: false,
};
}
catch (error) {
const handledError = ErrorHandler.handleError(error, {
operation: "pubmedResearchAgentToolHandler",
context: richContext,
input,
rethrow: false,
});
const mcpError = handledError instanceof McpError
? handledError
: new McpError(BaseErrorCode.INTERNAL_ERROR, "An unexpected error occurred while generating the research plan.", {
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