MCP 服务器实现
姓名:Esteban Nicolas 学生 ID:A20593170
一、已实现的MCP功能
1 数据资源 1.1 HDF5 文件清单
- 列出目录结构中的模拟 HDF5 文件
- 参数:
path_pattern
(可选文件路径模式)
2 工具 2.1 Slurm 作业提交
- 模拟向 Slurm 调度程序提交作业
- 参数:
script_path
(必需)、cores
(可选,默认值=1)
2.2 CPU 核心报告
- 报告系统上可用的 CPU 核心数
- 无需参数
2.3 CSV可视化
- 从 CSV 文件中绘制两列(默认为前两列)
- 参数:
csv_path
(必需)、column x
、column y
(均为可选)
II. 设置说明
- 创建虚拟环境
uv venv -p python3.10 .venv\Scripts\activate # 在 Unix 上:source .venv/bin/activate
- 安装依赖项
紫外线同步 紫外线锁定
- 环境配置本项目使用 pyproject.toml 进行依赖管理,主要依赖包括:
快速API
优维康
派丹蒂克
熊猫
Matplotlib
Pytest
Pytest-ascyncio
- 运行 MCP 服务器
启动服务器 cd src uvicorn server:app --reload
该服务器将在以下位置可用:
API 端点: http://localhost:8000/mcp健康检查: http://localhost:8000/health
三、测试
- 运行所有测试:
pytest 测试/运行特定的测试文件:
pytest 测试/test_capabilities_plot_vis.py pytest 测试/test_capabilities_hdf5.py pytest 测试/test_capabilities_cpu_core.py pytest 测试/test_capabilities_slurm.py pytest 测试/test_mcp_handler.py
- 示例请求 2.1 列出可用资源
curl -X POST http://localhost:8000/mcp
-H“内容类型:application/json”
-d '{“jsonrpc”:“2.0”,“method”:“mcp/listResources”,“id”:1}'
2.2 列出 HDF5 文件
curl -X POST http://localhost:8000/mcp
-H“内容类型:application/json”
-d'{“jsonrpc”:“2.0”,“方法”:“mcp / callTool”,“params”:{“工具”:“hdf5_file_listing”,“path_pattern”:“/ data / sim_run_123”},“id”:2}'
2.3 提交 Slurm 作业
curl -X POST http://localhost:8000/mcp
-H“内容类型:application/json”
-d '{“jsonrpc”:“2.0”,“method”:“mcp / callTool”,“params”:{“tool”:“slurm_job_submission”,“script_path”:“/jobs/analysis.sh”,“cores”:4},“id”:3}'
2.4 绘制 CSV 列
curl -X POST http://localhost:8000/mcp
-H“内容类型:application/json”
-d '{“jsonrpc”:“2.0”,“method”:“mcp/callTool”,“params”:{“tool”:“plot_vis_columns”,“csv_path”:“data.csv”,“column x”:“时间”,“column y”:“温度”},“id”:4}'
四、实施说明
- 模拟实现:
-HDF5 文件列表使用模拟目录结构 -Slurm 作业提交生成模拟作业 ID -CPU 核心报告使用 os.cpu_count()
- CSV 可视化:
- 在 plots_results 目录中创建图表 - 如果未指定,则默认为前两列 - 返回生成的 PNG 文件的路径
- 错误处理:
-正确的 JSON-RPC 2.0 错误响应 -所有参数的输入验证 -优雅地处理丢失的文件/无效路径
GITHUB: https://github.com/EstebanIIT/cs550\ _MCP.git
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
基于 FastAPI 的 JSON-RPC 2.0 服务器实现,使用户能够处理 HDF5 文件、提交 Slurm 作业、检索 CPU 信息以及通过标准化 API 端点可视化 CSV 数据。
Related MCP Servers
- -securityAlicense-qualityThe server integrates with the free IMF data API and provides various features to facilitate data retrieval and analysis. The server is built using the FastMCP framework and offers the following functionalities:Last updated -PythonApache 2.0
- -securityAlicense-qualityA server that enables interaction with WordPress sites through REST API, allowing users to create, retrieve, and update posts using JSON-RPC 2.0 protocol.Last updated -1JavaScriptMIT License
- -security-license-qualityA server implementing Model Coupling Protocol for HDF5 file operations, Slurm job management, hardware monitoring, and data compression.Last updated -PythonMIT License
- -security-license-qualityA JSON-RPC 2.0 compliant server that enables interaction with HDF5 data files and Slurm job scheduling through standardized API endpoints.Last updated -Python