validate_pmid
Verifies PubMed ID format and confirms the existence of the associated article in PubMed.
Instructions
Validate PubMed ID format and check if article exists
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pmid | Yes | PubMed ID to validate |
Implementation Reference
- src/index.ts:943-994 (handler)Main handler function for validate_pmid tool. Validates PMID format via isValidPMID, then checks if the article exists via eutilsClient.getArticleDetails. Returns JSON with valid/exists status and message.
async function handleValidatePMID(args: any) { const { pmid } = args; const valid = isValidPMID(pmid); if (!valid) { return { content: [ { type: 'text', text: JSON.stringify({ valid: false, pmid, message: 'Invalid PMID format. PMID must contain only digits.' }, null, 2) } ] }; } // Check if article exists try { await eutilsClient.getArticleDetails(pmid); return { content: [ { type: 'text', text: JSON.stringify({ valid: true, pmid, exists: true, message: 'Valid PMID and article exists' }, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ valid: true, pmid, exists: false, message: 'Valid PMID format but article not found' }, null, 2) } ] }; } } - src/index.ts:394-408 (schema)Input schema definition for validate_pmid tool. Defines 'pmid' as a required string property.
// Validation & Utility Tools { name: 'validate_pmid', description: 'Validate PubMed ID format and check if article exists', inputSchema: { type: 'object', properties: { pmid: { type: 'string', description: 'PubMed ID to validate' } }, required: ['pmid'] } }, - src/index.ts:482-483 (registration)Tool registration in the handler switch statement. Maps 'validate_pmid' case to handleValidatePMID function call.
case 'validate_pmid': return await handleValidatePMID(args); - src/index.ts:395-396 (registration)Tool name registration in the tools array. Lists 'validate_pmid' as a tool with description.
{ name: 'validate_pmid', - src/api/utils.ts:155-157 (helper)Helper function isValidPMID that validates PMID format using regex /^\d+$/. Returns true if the string contains only digits.
export function isValidPMID(pmid: string): boolean { return /^\d+$/.test(pmid); }