Skip to main content
Glama
ncukondo

PubMed MCP Server

by ncukondo

search_pubmed

Search for scientific articles in PubMed using customizable queries, filters, and sorting options to find relevant research publications.

Instructions

Search PubMed for scientific articles.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query for PubMed
searchOptionsNoOptional search parameters

Implementation Reference

  • src/index.ts:120-158 (registration)
    Registers the 'search_pubmed' MCP tool with input schema (using Zod) and a thin wrapper handler that delegates to searchHandler.search and formats results as JSON text.
    server.registerTool( 'search_pubmed', { title: 'PubMed Search', description: 'Search PubMed for scientific articles.', inputSchema: { query: z.string().describe('Search query for PubMed'), searchOptions: z.object({ retMax: z.number().optional().describe('Maximum number of results to return'), retStart: z.number().optional().describe('Starting index for results'), sort: z.enum(['relevance', 'pub_date', 'author', 'journal']).optional().describe('Sort order for results'), dateFrom: z.string().optional().describe('Start date filter (YYYY/MM/DD format)'), dateTo: z.string().optional().describe('End date filter (YYYY/MM/DD format)'), }).optional().describe('Optional search parameters') } }, async ({ query, searchOptions }) => { try { const results = await searchHandler.search(query, searchOptions); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error searching PubMed: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], }; } } );
  • Core handler factory createSearchHandler that creates the search function, which calls PubMed API's searchAndFetch and maps results to simplified format (pmid, title, pubDate).
    export function createSearchHandler(pubmedOptions: PubMedOptions): SearchHandler { const pubmedApi = createPubMedAPI(pubmedOptions); return { async search(query: string, searchOptions?: SearchOptions): Promise<SearchResultItem[]> { const articles = await pubmedApi.searchAndFetch(query, searchOptions); return articles.map(article => ({ pmid: article.pmid, title: article.title, pubDate: article.pubDate })); } }; }
  • TypeScript interface SearchOptions defining the structure for search parameters, matching the Zod schema in tool registration.
    export interface SearchOptions { retMax?: number; retStart?: number; sort?: 'relevance' | 'pub_date' | 'author' | 'journal'; dateFrom?: string; dateTo?: string; }
  • Helper function searchAndFetch in PubMed API that performs the actual PubMed search via ESearch and fetches article summaries via EFetch.
    const searchAndFetch = async (query: string, options: SearchAndFetchOptions = {}): Promise<Article[]> => { const { maxResults = 20, ...searchOptions } = options; const searchResult = await search(query, { ...searchOptions, retMax: maxResults }); return fetchArticles(searchResult.idList); };

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ncukondo/pubmed-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server