本文档提供 AutoCode MCP Server 的常见问题和解决方案。
错误信息:
Compiler not found: g++
Compilation failed with error
解决方案:
-
Windows 平台:
-
Linux/macOS:
- 安装
g++:sudo apt install g++或brew install gcc
- 安装
-
验证安装:
g++ --version
错误信息:
error: 'c++2c' is not a valid standard
解决方案:
-
升级到 GCC 14+:
gcc --version # 需要 14.0 或更高 -
或降级到 C++20:
- 修改
compiler.py中的std参数默认值
- 修改
错误信息:
Compilation timeout after 30s
解决方案:
- 检查代码复杂度,可能有模板递归展开
- 增加
compile_cpp()的timeout参数 - 检查是否有头文件循环依赖
错误信息:
Binary not found: /path/to/binary
解决方案:
- 确保已运行
*_build工具 - 检查文件扩展名:
- Windows:需要
.exe - Linux/macOS:无扩展名
- Windows:需要
- 验证编译是否成功(检查
compile_result.success)
错误信息:
Execution timeout after 30s
解决方案:
- 增加超时时间
- 优化算法复杂度
- 检查是否有死循环或低效代码
错误信息:
Binary not found or prlimit unavailable
解决方案:
- 安装
prlimit:sudo apt install util-linux
- Windows 平台内存限制不支持,仅依赖超时控制
可能原因:
- Generator 失败:检查
gen.cpp生成逻辑 - sol 失败:检查
sol.cpp代码正确性 - brute 失败:检查
brute.cpp代码正确性 - Validator 失败:检查
val.cpp验证逻辑
调试步骤:
- 运行单轮测试(设置
trials=1) - 检查失败的输入数据
- 比较
sol和brute的输出差异
症状:
- 预期
expected_valid=True,但实际返回非零退出码 - 或相反情况
解决方案:
- 检查 Validator 使用
quitf(_ok, ...)或quitf(_wa, ...) - 确保退出码正确:
_ok→ exit 0_wa或其他 → exit 非 0
症状:
OSError: [WinError 32] The process cannot access the file
解决方案:
- 确保路径使用正斜杠
/或双反斜杠\\ - 避免使用保留名称(如
con,prn,aux) - 检查文件是否被其他进程占用
错误信息:
PermissionError: [Errno 13] Permission denied
解决方案:
- 关闭可能占用文件的程序
- 以管理员身份运行
- 检查文件是否设置为只读
优化建议:
- 使用
test_count参数限制测试数量 - 调整
max_attempts系数(默认test_count * 10) - 优化
gen.cpp生成算法复杂度
优化建议:
- 减小
n_max参数(默认 100) - 减少
trials轮数 - 优化
brute.cpp暴力解法复杂度
检查清单:
- 确认
autocode-mcp命令可执行 - 检查 MCP 客户端配置
- 验证 Python 虚拟环境已激活
调试步骤:
- 查看 Server 日志的完整错误信息
- 验证
input_schema参数是否正确 - 检查
problem_dir路径是否存在且有写权限
如果遇到未在本文档中列出的问题:
- 查看测试用例:
tests/目录 - 检查工具文档:
src/autocode_mcp/tools/源代码注释 - 运行测试验证环境:
pytest tests/ -v - 提交 Issue:GitHub Issues