交叉引用MCP服务器
用于与Crossref API交互的模型上下文协议(MCP)服务器。
特性
- 按标题搜索作品
- 按作者搜索作品
- 按DOI获取工作详细信息
安装
{
"mcpServers": {
"crossref": {
"command": "npx",
"args": [
"-y",
"@botanicastudios/crossref-mcp"
]
}
}
}用法
服务器提供三个主要工具:
1.按标题搜索
在Crossref中按标题搜索作品:
// Example: Search for works containing "quantum computing" in the title
{
"title": "quantum computing",
"rows": 5 // Optional, defaults to 5
}2.按作者搜索
按作者在Crossref中搜索作品:
// Example: Search for works by "Einstein"
{
"author": "Einstein",
"rows": 5 // Optional, defaults to 5
}3.通过DOI获得工作
使用DOI检索特定作品:
// Example: Get work with DOI "10.1088/1742-6596/1398/1/012023"
{
"doi": "10.1088/1742-6596/1398/1/012023"
}响应格式
所有响应都以结构化JSON对象的形式返回,格式如下:
成功搜索:
{
"status": "success",
"query": {
/* the original query parameters */
},
"count": 5,
"results": [
{
"title": "Work title",
"authors": [
{
"given": "First name",
"family": "Last name",
"name": "First name Last name"
}
],
"published": {
"dateParts": [2023, 1, 15],
"dateString": "2023-1-15"
},
"type": "journal-article",
"doi": "10.xxxx/xxxxx",
"url": "https://doi.org/10.xxxx/xxxxx",
"container": "Journal Name",
"publisher": "Publisher Name",
"issue": "1",
"volume": "42",
"abstract": "This is the abstract of the work, if available."
}
// additional results...
]
}对于单DOI查找:
{
"status": "success",
"query": { "doi": "10.xxxx/xxxxx" },
"result": {
// work details as shown above
}
}对于错误或无结果:
{
"status": "error" | "no_results" | "not_found",
"message": "Error message" | null,
"query": { /* the original query parameters */ }
}测试
该服务器附带了一个使用Vitest的全面测试套件。测试涵盖了所有可用的工具,并包括各种场景,包括成功响应、空结果和错误处理。
运行测试
npm test测试结构
测试使用Vitest的模拟功能来模拟Crossref API响应,而不进行实际的网络请求。测试结构包括:
- 模拟数据:标题搜索、作者搜索和DOI查找的示例响应
- 模拟处理器:测试中处理程序函数的版本
mcp-server-test-handlers.js - 测试用例:所有工具的测试包括:
- API成功响应 - 空结果集 - 错误处理和网络故障
扩展测试
要添加更多测试用例,请执行以下操作:
- 如果需要,将新的模拟数据添加到测试文件中
- 在相关描述块中创建其他测试用例
- 使用
mockFetchResponse()模拟API响应的助手
例子:
it("should handle a new edge case", async () => {
// Mock the response
mockFetchResponse({
// Your sample response data
});
// Call the handler
const result = await handlers.searchByTitle({ title: "example" });
// Assert the expected results
expect(result).toMatchObject({
// Expected response structure
});
});