NIH研究项目查询服务

一个提供程序化访问NIH Reporter API的MCP服务器,用于搜索和检索NIH资助的研究项目信息。

  • by jhalsey87
  • HTML
  • 本地部署
  • 更新于
在 GitHub 查看 jhalsey87/MCP_NIH_Reporter

使用说明

NIH报告MCP服务器

模型上下文协议(MCP)服务器,提供对NIH Reporter API的程序访问,用于搜索和检索NIH资助的研究项目的信息。

概述

此MCP服务器允许AI助手和其他MCP客户端搜索和检索有关NIH资助的研究资助的详细信息,包括:

  • 项目详情和资金信息
  • 主要研究者信息
  • 组织详细信息
  • 项目摘要和公共卫生相关性
  • 奖励金额和日期
  • 研究部分和审查信息

特性

可用工具

  1. 搜索_项目 -使用多个标准搜索NIH项目:

    • 财政年度
    • 美国国立卫生研究院/中心(IC代码)
    • 活动代码(R01、P01等)
    • 组织名称
    • 主要研究者姓名
    • 项目编号
    • 奖励金额范围
    • 日期范围
    • 标题/摘要中的关键字
  2. get_project_details -按项目编号或应用程序ID获取特定项目的全面详细信息

  3. search_recent_awards -在指定天数内查找最近授予的项目

  4. 搜索_调查员 -由特定首席研究员搜索所有项目

  5. 获取_支出_类别 -获取有关NIH支出类别的信息

先决条件

  • 已安装Docker和Docker Compose
  • 对MCP(模型上下文协议)的基本理解

快速开始

1.构建Docker镜像

docker-compose build

2.运行服务器

docker-compose up

服务器将启动并通过stdin/stdout监听MCP请求。

3.替代方案:仅使用Docker构建和运行

# Build the image
docker build -t nih-reporter-mcp .

# Run the container
docker run -i nih-reporter-mcp

Claude桌面配置

要将此MCP服务器与Claude Desktop一起使用,请将其添加到您的Claude配置文件中:

在macOS/Linux上: ~/Library/Application Support/Claude/claude_desktop_config.json

在Windows上: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "nih-reporter": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "nih-reporter-mcp"]
    }
  }
}

添加此配置后,重新启动Claude Desktop。

使用示例

一旦连接到MCP客户端(如Claude Desktop),您就可以使用自然语言与NIH Reporter API进行交互:

示例1:搜索最近的癌症研究

"Find recent NIH cancer research projects from the National Cancer Institute awarded in 2025"

这将使用 search_projects 工具包括:

  • 机构:[“NCI”]
  • 财政年度:[2025]

示例2:按调查员查找项目

"Show me all NIH projects where John Smith is the principal investigator"

这将使用 search_by_investigator 工具。

示例3:获取项目详细信息

"Get detailed information about project R01CA123456"

这将使用 get_project_details 工具。

示例4:搜索最近的奖项

"What are the newest NIH awards from the last 7 days?"

这将使用 search_recent_awards 工具。

与Azure OpenAI响应API一起使用

您可以使用函数调用将此MCP服务器与Azure OpenAI的Responses API集成。以下是展示如何用不同语言定义工具的片段:

python

from openai import AzureOpenAI
from azure.identity import DefaultAzureCredential, get_bearer_token_provider

# Configure Azure AD authentication
token_provider = get_bearer_token_provider(
    DefaultAzureCredential(),
    "https://cognitiveservices.azure.com/.default"
)

client = AzureOpenAI(
    base_url="https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
    azure_ad_token_provider=token_provider,
    api_version="preview"
)

# Define NIH Reporter search tool
tools = [
    {
        "type": "function",
        "function": {
            "name": "search_projects",
            "description": "Search for NIH-funded research projects using multiple criteria including fiscal years, agencies, activity codes, and keywords",
            "parameters": {
                "type": "object",
                "properties": {
                    "fiscal_years": {
                        "type": "array",
                        "items": {"type": "integer"},
                        "description": "Fiscal years to search (e.g., [2024, 2025])"
                    },
                    "agencies": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "NIH Institute/Center codes (e.g., ['NCI', 'NHLBI'])"
                    },
                    "activity_codes": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "Grant activity codes (e.g., ['R01', 'K99'])"
                    },
                    "pi_names": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "Principal investigator names"
                    },
                    "keywords": {
                        "type": "string",
                        "description": "Search keywords for project titles/abstracts"
                    }
                }
            }
        }
    }
]

response = client.responses.create(
    model="gpt-4.1",
    tools=tools,
    input="What recent NIH projects were targeted at early career researchers?"
)

print(response.output_text)

C

using Azure.AI.OpenAI;
using Azure.Identity;

var credential = new DefaultAzureCredential();
var client = new AzureOpenAIClient(
    new Uri("https://YOUR-RESOURCE-NAME.openai.azure.com/"),
    credential
);

var tools = new[]
{
    new
    {
        type = "function",
        function = new
        {
            name = "search_projects",
            description = "Search for NIH-funded research projects using multiple criteria",
            parameters = new
            {
                type = "object",
                properties = new
                {
                    fiscal_years = new
                    {
                        type = "array",
                        items = new { type = "integer" },
                        description = "Fiscal years to search (e.g., [2024, 2025])"
                    },
                    agencies = new
                    {
                        type = "array",
                        items = new { type = "string" },
                        description = "NIH Institute/Center codes (e.g., ['NCI', 'NHLBI'])"
                    },
                    activity_codes = new
                    {
                        type = "array",
                        items = new { type = "string" },
                        description = "Grant activity codes (e.g., ['R01', 'K99'])"
                    },
                    keywords = new
                    {
                        type = "string",
                        description = "Search keywords for project titles/abstracts"
                    }
                }
            }
        }
    }
};

var response = await client.GetResponsesClient("gpt-4.1").CreateAsync(new()
{
    Tools = tools,
    Input = "What recent NIH projects were targeted at early career researchers?"
});

Console.WriteLine(response.Value.OutputText);

PHP

<?php
require 'vendor/autoload.php';

use OpenAI\Azure\Client;

$client = Client::factory()
    ->withBaseUri('https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/')
    ->withAzureAdToken(getAzureAdToken())
    ->withApiVersion('preview')
    ->make();

$tools = [
    [
        'type' => 'function',
        'function' => [
            'name' => 'search_projects',
            'description' => 'Search for NIH-funded research projects using multiple criteria',
            'parameters' => [
                'type' => 'object',
                'properties' => [
                    'fiscal_years' => [
                        'type' => 'array',
                        'items' => ['type' => 'integer'],
                        'description' => 'Fiscal years to search'
                    ],
                    'agencies' => [
                        'type' => 'array',
                        'items' => ['type' => 'string'],
                        'description' => 'NIH Institute/Center codes'
                    ],
                    'activity_codes' => [
                        'type' => 'array',
                        'items' => ['type' => 'string'],
                        'description' => 'Grant activity codes'
                    ],
                    'keywords' => [
                        'type' => 'string',
                        'description' => 'Search keywords'
                    ]
                ]
            ]
        ]
    ]
];

$response = $client->responses()->create([
    'model' => 'gpt-4.1',
    'tools' => $tools,
    'input' => 'What recent NIH projects were targeted at early career researchers?'
]);

echo $response['output_text'];
?>

集成说明:

要将这些工具连接到MCP服务器后端:

  1. 启动Docker容器: docker run -i --rm nih-reporter-mcp
  2. 当Azure OpenAI调用您的函数时,拦截该函数调用
  3. 通过stdin向Docker容器发送相应的MCP协议消息
  4. 从stdout解析JSON-RPC响应
  5. 将结果返回给Azure OpenAI以生成最终响应

可用工具:

  • search_projects -使用多个条件搜索
  • get_project_details -按项目编号获取详细信息
  • search_recent_awards -按天数查找最近的奖项
  • search_by_investigator -按PI名称搜索
  • get_spending_categories -获取NIH支出类别

API 参考

美国国立卫生研究院/中心代码

您可以在搜索中使用的常见IC代码:

  • NCI 的 -国家癌症研究所
  • 尼达 -国家药物滥用研究所
  • 国家心肺血液研究所 -国家心肺血液研究所
  • 从未 -国家过敏和传染病研究所
  • 国家心理健康研究所 -国家心理健康研究所
  • 国家情报院 -国家老龄化研究所
  • 人类发展 -国家儿童健康与人类发展研究所
  • 研究所 -国家糖尿病、消化和肾脏疾病研究所

请参阅文档PDF以获取完整列表。

常见活动代码

  • R01 -研究项目资助
  • R21 -探索性/发展性研究补助金
  • R03 -小额研究资助
  • P01 -研究项目资助
  • U01 -研究项目合作协议
  • K01-K99 -职业发展奖
  • T32 -机构培训补助金
  • F31-F33 -个人博士前/博士后奖学金

发展

项目结构

.
├── server.py           # Main MCP server implementation
├── requirements.txt    # Python dependencies
├── Dockerfile         # Docker container definition
├── docker-compose.yml # Docker Compose configuration
├── README.md          # This file
└── [PDF documentation files]

本地开发(无Docker)

  1. 安装依赖项:
pip install -r requirements.txt
  1. 运行服务器:
python server.py

修改服务器

服务器代码位于 server.py.关键部分:

  • 工具定义: list_tools() 函数
  • 工具操作员:每个工具都有单独的异步函数
  • API集成: make_nih_api_request() 函数

更改后,重建Docker镜像:

docker-compose build

故障排除

服务器未响应

  1. 检查容器是否正在运行:
docker ps
  1. 查看日志:
docker-compose logs -f

API错误

美国国立卫生研究院API报告器有时可能运行缓慢或不可用。服务器包括API请求的30秒超时。

连接问题

确保:

  • Docker正在运行
  • 该集装箱可以通过互联网访问api.reporter.nih.gov
  • 没有防火墙阻止出站HTTPS连接

数据源

此服务器使用NIH Reporter API v2:

  • API基本URL:https://api.reporter.nih.gov/v2
  • 文档:此目录中包含PDF文件

局限性

  • 每个查询最多500个结果(API限制)
  • 每个API请求30秒超时
  • 速率限制可能适用(由NIH Reporter API强制执行)

许可证

此MCP服务器实现以i的形式提供,供NIH Reporter公共API使用。

贡献

欢迎投稿!请确保:

  • 代码遵循Python最佳实践
  • 所有工具都有适当的记录
  • Docker容器构建成功
  • README已更新以获取新功能

支持

关于以下问题:

  • 此MCP服务器:检查日志和故障排除部分
  • 美国国立卫生研究院API报告员:请参阅NIH Reporter官方文件
  • MCP协议:请参阅模型上下文协议文档

版本

当前版本:1.0.0

鸣谢

构建使用:

  • MCP Python SDK
  • 美国国立卫生研究院报告员API v2
  • Docker用于容器化