searchByAuthor
Find scientific papers in the Crossref database by entering an author's name. Specify the number of results to retrieve structured metadata for research publications efficiently.
Instructions
Search for scientific papers by author in Crossref
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| author | Yes | The author name to search for | |
| rows | No | Number of results to return |
Implementation Reference
- mcp-server.js:121-195 (handler)Core execution logic for the searchByAuthor tool: queries Crossref API with author name, handles response, formats results using formatWorkToJson, and returns structured JSON content.async ({ author, rows }) => { try { const url = `${CROSSREF_API_BASE}/works?query.author=${encodeURIComponent( author )}&rows=${rows}&select=${CROSSREF_SELECT_FIELDS}`; const response = await fetch(url, { headers: { "User-Agent": "Crossref MCP Server", }, }); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const data = await response.json(); const works = data.message?.items || []; if (works.length === 0) { return { content: [ { type: "text", text: JSON.stringify( { status: "no_results", query: { author, rows }, results: [], }, null, 2 ), }, ], }; } const formattedWorks = works.map((work) => formatWorkToJson(work)); return { content: [ { type: "text", text: JSON.stringify( { status: "success", query: { author, rows }, count: formattedWorks.length, results: formattedWorks, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { status: "error", message: error.message, query: { author, rows }, }, null, 2 ), }, ], }; } }
- mcp-server.js:113-120 (schema)Zod schema defining input parameters for the searchByAuthor tool: author (string) and optional rows (number, default 5).{ author: z.string().describe("The author name to search for"), rows: z .number() .optional() .default(5) .describe("Number of results to return"), },
- mcp-server.js:110-196 (registration)MCP server.tool call that registers the searchByAuthor tool, including description, input schema, and handler function.server.tool( "searchByAuthor", "Search for scientific papers by author in Crossref", { author: z.string().describe("The author name to search for"), rows: z .number() .optional() .default(5) .describe("Number of results to return"), }, async ({ author, rows }) => { try { const url = `${CROSSREF_API_BASE}/works?query.author=${encodeURIComponent( author )}&rows=${rows}&select=${CROSSREF_SELECT_FIELDS}`; const response = await fetch(url, { headers: { "User-Agent": "Crossref MCP Server", }, }); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const data = await response.json(); const works = data.message?.items || []; if (works.length === 0) { return { content: [ { type: "text", text: JSON.stringify( { status: "no_results", query: { author, rows }, results: [], }, null, 2 ), }, ], }; } const formattedWorks = works.map((work) => formatWorkToJson(work)); return { content: [ { type: "text", text: JSON.stringify( { status: "success", query: { author, rows }, count: formattedWorks.length, results: formattedWorks, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { status: "error", message: error.message, query: { author, rows }, }, null, 2 ), }, ], }; } } );
- mcp-server-utils.js:2-29 (helper)Utility function to format individual Crossref work objects into a standardized JSON structure, used by the searchByAuthor handler to process API results.export const formatWorkToJson = (work) => { if (!work) return { error: "No data available" }; return { title: work.title?.[0] || null, authors: work.author ? work.author.map((a) => ({ given: a.given || null, family: a.family || null, name: `${a.given || ""} ${a.family || ""}`.trim(), })) : [], published: work.published ? { dateParts: work.published["date-parts"]?.[0] || [], dateString: work.published["date-parts"]?.[0]?.join("-") || null, } : null, type: work.type || null, doi: work.DOI || null, url: work.URL || null, container: work["container-title"]?.[0] || null, publisher: work.publisher || null, issue: work.issue || null, volume: work.volume || null, abstract: work.abstract || null, }; };
- mcp-server-test-handlers.js:84-158 (handler)Test implementation of searchByAuthor handler, nearly identical to main but used for testing purposes.searchByAuthor: async ({ author, rows = 5 }) => { try { const url = `https://api.crossref.org/works?query.author=${encodeURIComponent( author )}&rows=${rows}`; const response = await fetch(url, { headers: { "User-Agent": "Crossref MCP Server Test", }, }); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const data = await response.json(); const works = data.message?.items || []; if (works.length === 0) { return { content: [ { type: "text", text: JSON.stringify( { status: "no_results", query: { author, rows }, results: [], }, null, 2 ), }, ], }; } const formattedWorks = works.map((work) => formatWorkToJson(work)); return { content: [ { type: "text", text: JSON.stringify( { status: "success", query: { author, rows }, count: formattedWorks.length, results: formattedWorks, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { status: "error", message: error.message, query: { author, rows }, }, null, 2 ), }, ], }; } },