ADIOS2 BP5 MCP服务器
该项目提供了一个模型上下文协议(MCP)服务器,用于与ADIOS2 BP5文件进行交互。它允许像Claude Desktop或自定义代理这样的LLM客户端检查元数据、读取数据切片,并理解以BP5格式存储的科学数据集的内容。
特性
- 列出变量:发现BP5文件中的所有变量,包括它们的类型、形状和可用步骤。
- 描述变量:获取任何变量的详细分解信息,显示每个步骤的块级统计数据(最小/最大)。
- 读取数据:从任何变量读取数据,支持切片维度和选择特定步骤。
- 检查属性:列出并读取全局和变量特定的属性。
- 双重运输:支持两者
stdio用于本地集成(例如,Claude Desktop)和流媒体HTTP基于网络的客户端接口。
安装
建议使用 uv 用于管理Python环境。
- 克隆存储库:
git clone https://github.com/your-username/adios2-mcp-server.git
cd adios2-mcp-server- 创建虚拟环境并安装依赖项:
uv venv
source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`
uv pip install -e .用法
服务器可以使用两种不同的传输方式运行: stdio 或 http.
1.标准I/O(stdio)传输
这是与Claude Desktop或MCP Inspector等客户端进行本地集成的标准。
直接运行:
python src/adios_mcp_server/server.py使用 mcp 用于开发和测试的CLI: MCP检查器是调试服务器的强大工具。
# Start the server in development mode with the MCP Inspector
mcp dev src/adios_mcp_server/server.py
# To test with a specific file:
mcp dev src/adios_mcp_server/server.py -- --file-path /path/to/your/data.bp2.流式HTTP传输
这通过HTTP公开了服务器,允许网络客户端连接。
使用Uvicorn启动服务器:
uvicorn adios_mcp_server.server:app --host 0.0.0.0 --port 8000MCP SSE端点将在 http://localhost:8000/。你可以用 curl:
# Example: Send an `initialize` request
curl -X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","clientInfo":{"name":"curl-test"},"capabilities":{}}}' \
http://localhost:8000/工具参考
服务器公开了以下工具:
| 工具名称 | 描述 | 参数 | 返回 |
|---|---|---|---|
list_variables | 列出所有变量及其元数据。 | filepath: str | 变量元数据的JSON字符串。 |
describe_variable | 提供变量的详细块级分解信息。 | filepath: str, variable_name: str | 所有步骤中块信息的JSON字符串。 |
read_data | 从变量中读取数据,支持切片。 | filepath: str, variable_name: str, start: Optional[list], count: Optional[list], step_start: Optional[int], step_count: Optional[int] | 包含数据数组及其形状的JSON字符串 |
list_attributes | 列出文件中的所有属性。 | filepath: str | 属性元数据的JSON字符串。 |
read_attribute | 读取单个属性的值。 | filepath: str, attribute_name: str | 属性值和类型的JSON字符串。 |
测试
要运行测试套件,请执行以下操作:
# Install test dependencies
pip install pytest
# Run tests
pytest tests/这些测试创建了示例BP5文件,并验证了所有MCP工具在各种数据类型和配置下都能正常工作。
例子
示例1:基本变量检查
# List all variables in a BP5 file
result = list_variables("/path/to/simulation.bp")
print(result)
# Get detailed info about a specific variable
result = describe_variable("/path/to/simulation.bp", "temperature")
print(result)示例2:读取数据片段
# Read full data for all steps
result = read_data("/path/to/simulation.bp", "temperature")
# Read a specific spatial slice from step 10-20
result = read_data(
"/path/to/simulation.bp",
"temperature",
start=[0, 0, 50],
count=[100, 100, 50],
step_start=10,
step_count=10
)示例3:属性检查
# List all attributes
result = list_attributes("/path/to/simulation.bp")
# Read a specific attribute
result = read_attribute("/path/to/simulation.bp", "simulation_time")配置
Claude桌面集成
要将此服务器与Claude Desktop一起使用,请将以下内容添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"adios2-bp5": {
"command": "python",
"args": ["/path/to/adios2-mcp-server/src/adios_mcp_server/server.py"],
"env": {}
}
}
}环境变量
您可以使用环境变量配置服务器:
ADIOS2_MCP_LOG_LEVEL:设置日志记录级别(调试、信息、警告、错误)ADIOS2_MCP_MAX_ARRAY_SIZE:JSON中返回的最大数组大小(默认值:10000个元素)
贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
