get_citations
Find articles that cite a specific PubMed publication to track forward citations and discover related research.
Instructions
Get articles that cite a given PubMed article (PMID). Useful for forward citation tracking.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pmid | Yes | PubMed ID to find citing articles for |
Implementation Reference
- src/tools.ts:80-102 (handler)The getCitations function that executes the tool logic. It queries NCBI's elink API to find articles that cite a given PMID, fetches article details for up to 20 citing articles, and returns a JSON response with the citing count and article summaries.
export async function getCitations(args: z.infer<typeof getCitationsSchema>): Promise<string> { const result = await client.elink([args.pmid], "pubmed_pubmed_citedin") as { linksets?: Array<{ linksetdbs?: Array<{ links?: string[] }> }>; }; const links = result.linksets?.[0]?.linksetdbs?.[0]?.links || []; if (links.length === 0) { return JSON.stringify({ pmid: args.pmid, citing_count: 0, citing_articles: [] }, null, 2); } // Fetch summaries for citing articles (max 20) const fetchIds = links.slice(0, 20); const xml = await client.efetch(fetchIds); const articles = parseArticles(xml); return JSON.stringify({ pmid: args.pmid, citing_count: links.length, showing: articles.length, citing_articles: articles.map(formatArticleSummary), }, null, 2); } - src/tools.ts:21-23 (schema)The getCitationsSchema defines input validation for the tool, accepting a single 'pmid' string parameter (PubMed ID to find citing articles for).
export const getCitationsSchema = z.object({ pmid: z.string().describe("PubMed ID to find citing articles for"), }); - src/index.ts:43-50 (registration)The get_citations tool is registered with the MCP server, mapping the schema shape to the getCitations handler function with a description explaining its forward citation tracking purpose.
server.tool( "get_citations", "Get articles that cite a given PubMed article (PMID). Useful for forward citation tracking.", getCitationsSchema.shape, async (args) => ({ content: [{ type: "text", text: await getCitations(getCitationsSchema.parse(args)) }], }) ); - src/tools.ts:223-233 (helper)The formatArticleSummary helper function used by getCitations to format article metadata (PMID, title, authors, journal, publication date, DOI, and abstract) into a concise summary object.
function formatArticleSummary(a: ArticleMetadata) { return { pmid: a.pmid, title: a.title, authors: a.authors.slice(0, 5).join(", ") + (a.authors.length > 5 ? " et al." : ""), journal: a.journal, pub_date: a.pubDate, doi: a.doi || undefined, abstract: a.abstract.length > 500 ? a.abstract.slice(0, 500) + "..." : a.abstract, }; }