openalex-mcp
Version:
A Model Context Protocol (MCP) server that provides access to the OpenAlex API - a fully open catalog of the global research system covering over 240 million scholarly works.
38 lines (37 loc) • 1.49 kB
JavaScript
import { makeOpenAlexRequest } from "../utils.js";
export async function searchWorks(args) {
const { view, ...searchArgs } = args;
if (view === 'summary') {
// Define the fields for the summary view
searchArgs.select = 'id,doi,title,publication_year,type,cited_by_count,authorships,concepts,primary_location,open_access,best_oa_location';
const data = await makeOpenAlexRequest("/works", searchArgs);
// Process the results to create the summary
const summarizedResults = data.results.map((work) => {
// Limit authorships
if (work.authorships && work.authorships.length > 5) {
work.authorships = work.authorships.slice(0, 5);
}
// Limit concepts
if (work.concepts && work.concepts.length > 3) {
// Assuming concepts are sorted by score, which is typical.
// If not, we might need to sort them first.
work.concepts = work.concepts.slice(0, 3);
}
return work;
});
return {
content: [{
type: "text",
text: JSON.stringify({ ...data, results: summarizedResults }, null, 2)
}]
};
}
else {
return {
content: [{
type: "text",
text: JSON.stringify(await makeOpenAlexRequest("/works", args), null, 2)
}]
};
}
}