mcp_oi_assistant
A secure MCP server for competitive programming that compiles, runs, and tests C++ code with safety features like directory isolation and resource limits.
README
mcp_oi_assistant
一个为编程竞赛(OI)选手设计的 MCP 服务器,能够安全地编译、运行并测试 C++ 代码。
📋 功能列表
核心功能
- ✅ 编译 C++ 代码:调用 MinGW-w64 的
g++编译器 - ✅ 运行程序:提供输入数据,获取程序输出
- ✅ 输出比较:自动比对实际输出与预期输出
- ✅ GDB 调试:支持使用 GDB 进行代码调试
- ✅ 测试用例管理:读取预设的测试用例文件
安全特性
- ✅ 目录隔离:所有文件操作限制在
./tmp/目录内 - ✅ 命令过滤:阻止执行危险系统命令
- ✅ 资源限制:自动限制运行时间、内存和输出大小
- ✅ 文件名消毒:防止路径遍历攻击
🛠️ 依赖的命令行工具
C++ 编译器 : MinGW-w64
- 将文件夹命名为mingw64放在项目目录下
🚀 快速开始
# 进入项目目录
cd mcp_oi_-_assistant
# 安装依赖
pip install -r requirements.txt
# 直接启动
python main.py
方法二:配置到 AI 客户端
MCP 服务器需要配合支持 MCP 协议的 AI 客户端使用,如 Claude Desktop、Cursor、CherryStudio 等。
配置示例
编辑配置文件 oimcp.json:
{
"mcpServers": {
"oi-assistant": {
"command": "python",
"args": ["你的路径/mcp_oi_assistant/main.py"]
}
}
}
配置完成后,重启 AI 客户端,即可在对话中直接使用编译运行等工具。
目录结构
mcp_oi_assistant/
├── main.py # 启动入口
├── mcp_server.py # 服务器核心
├── runner.py # 代码运行器
├── security.py # 安全模块
├── config.yaml # 配置文件
├── requirements.txt # Python依赖
├── tmp/ # 临时工作区
└── mingw64/ # MinGW 工具链(需自行放置)
⚙️ 配置文件
config.yaml 主要配置项:
# 编译设置
compilation:
compiler_path: "./mingw64/bin/g++.exe" # g++路径
cpp_standard: "c++17" # C++标准
optimization_level: "-O2" # 优化级别
# 运行限制
execution:
max_time: 5000 # 最大运行时间(毫秒)
max_memory: 256 # 最大内存(MB)
max_output_size: 1048576 # 最大输出(1MB)
# 路径设置
paths:
temp_dir: "./tmp" # 临时文件目录
mingw_dir: "./mingw64" # MinGW目录
📁 文件存储
程序运行时会自动在 ./tmp/ 下创建以下子目录:
tmp/
├── sources/ # 源代码文件(*.cpp)
├── execute/ # 可执行文件(*.exe)
├── inputs/ # 输入数据文件(*.in)
├── outputs/ # 程序输出文件(*.out)
└── tests/ # 测试用例文件(*.txt)
📄 许可证
MIT License
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.