目录
目录README.md

Materials Project (MCP and NLP)

运行前配置

1. 配置环境变量

  • 进入mcp_mp_searcher目录,复制.env.example为新的文件.env
    • # cd mcp_mp_searcher && cp .env.example .env
  • 配置MP_API_KEY,注意使用embedding模型和instruct模型。目前默认是用的siliconflow的模型名称,如果用其他提供商,记得修改EMBEDDING_MODEL和INSTRUCT_MODEL
    • # vim .env

2. mcp基础镜像编译

  • 编译mcp-mp-tools基础镜像(linux),win下不支持&&操作符,请单独执行cd和docker build两个命令

    • # cd mcp_mp_tools && sudo docker build –network=host -t mcp-mp-tools:base -f docker/Dockerfile.base .
  • 编译mcp-mp-searcher基础镜像(linux), win下不支持&&操作符,请单独执行cd和docker build两个命令

    • # cd mcp_mp_searcher && sudo docker build –network=host -t mcp-mp-searcher:base -f docker/Dockerfile.base .

3. 启动mcp服务

  • 调试启动
    • # docker-compose up
  • 后台启动
    • # docker-compose up -d

服务地址

mp-mcp服务地址

mp-restful api 服务地址

mp-restful api 文档地址

自然语言查询mp 文档地址

自然语言查询mp 服务地址

示例

import requests

base_url = "http://localhost:8001"

headers = {
            "Content-Type": "application/json",
            "Authorization": "Bearer sk-28heof8283yhqw9e92h3e9qwofaosd8102375haidfnxcjvw19oksnk"
        }

query = "请筛选出形成能<0 meV/atom、带隙大于0.1eV之间,且二向色性比>3的材料。"

intend = '''{"application_area": [], "material_category": [], "attribute_requirements": {"Formation Energy": {"conditions": {"min": null, "max": 0}, "unit": "meV/atom", "chinese": "形成能"}, "Band Gap": {"conditions": {"min": 0.1, "max": null}, "unit": "eV", "chinese": "带隙"}, "Dichroic Ratio": {"conditions": {"min": 3, "max": null}, "unit": "", "chinese": "二向色性比"}}}'''

json={"query": query, "intent": intend}

response = requests.post(
                f"{base_url}/api/query",
                json=json,
                headers=headers
            )

if response.status_code == 200:
    result = response.json()
    if result["success"]:
        print(f"✅ 查询成功:")
        print(f"  执行方式: {result.get('execution_method', 'N/A')}")
        docs = json.loads(result.get('result', '{}'))
        print(f"  结果: {len(docs)} 条记录")
        for doc in docs[:10]:
            material_id = doc.get("material_id", "N/A")
            formula_pretty = doc.get("formula_pretty", "N/A")
            band_gap = doc.get("band_gap", "N/A")
            formation_energy = doc.get("formation_energy_per_atom", "N/A")
            dichroic_ratio = doc.get("dichroic_ratio", "N/A")
            print(f"    - Material ID: {material_id}, Formula: {formula_pretty}, Band Gap: {band_gap} eV, Formation Energy: {formation_energy} meV/atom, Dichroic Ratio: {dichroic_ratio}")
    
    else:
        logger.warning(f"⚠️ 查询失败: {result.get('error', 'N/A')}")
    else:
    logger.error(f"❌ 查询请求失败: {response.status_code}")
关于
37.0 KB
邀请码