searchByTitle
Search for scientific papers by title using Crossref metadata. Input a title and specify the number of results to retrieve structured information about relevant academic publications.
Instructions
Search for scientific papers by title in Crossref
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | No | Number of results to return | |
| title | Yes | The title to search for |
Implementation Reference
- mcp-server.js:32-106 (handler)The core handler function for the searchByTitle tool. It makes a fetch request to the Crossref API searching by title, processes the results using formatWorkToJson, and returns a structured JSON response via content array.async ({ title, rows }) => { try { const url = `${CROSSREF_API_BASE}/works?query.title=${encodeURIComponent( title )}&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: { title, rows }, results: [], }, null, 2 ), }, ], }; } const formattedWorks = works.map((work) => formatWorkToJson(work)); return { content: [ { type: "text", text: JSON.stringify( { status: "success", query: { title, rows }, count: formattedWorks.length, results: formattedWorks, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { status: "error", message: error.message, query: { title, rows }, }, null, 2 ), }, ], }; } }
- mcp-server.js:24-31 (schema)Zod schema defining the input parameters for searchByTitle: title (required string), rows (optional number, default 5).{ title: z.string().describe("The title to search for"), rows: z .number() .optional() .default(5) .describe("Number of results to return"), },
- mcp-server.js:21-107 (registration)Registers the searchByTitle tool with the MCP server using server.tool(), providing name, description, input schema, and handler function.server.tool( "searchByTitle", "Search for scientific papers by title in Crossref", { title: z.string().describe("The title to search for"), rows: z .number() .optional() .default(5) .describe("Number of results to return"), }, async ({ title, rows }) => { try { const url = `${CROSSREF_API_BASE}/works?query.title=${encodeURIComponent( title )}&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: { title, rows }, results: [], }, null, 2 ), }, ], }; } const formattedWorks = works.map((work) => formatWorkToJson(work)); return { content: [ { type: "text", text: JSON.stringify( { status: "success", query: { title, rows }, count: formattedWorks.length, results: formattedWorks, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { status: "error", message: error.message, query: { title, rows }, }, null, 2 ), }, ], }; } } );
- mcp-server-utils.js:2-29 (helper)Helper function formatWorkToJson that formats a Crossref work object into a simplified JSON structure, used by the searchByTitle 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, }; };