searchByAuthor
Find scientific papers by author name using Crossref's database, returning structured metadata for academic research.
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-196 (handler)The primary handler function that executes the searchByAuthor tool logic: queries Crossref API with author name, fetches works, formats them using formatWorkToJson, and returns JSON-structured 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 input schema defining parameters for the searchByAuthor tool: required '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-197 (registration)Registration of the 'searchByAuthor' tool via McpServer.tool() method, specifying name, 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-test-handlers.js:84-158 (handler)Test handler for searchByAuthor, identical logic for use in testing contexts.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 ), }, ], }; } },