基于 Codeforces Polygon API 的 MCP 工具集
Project description
CF-Polygon-MCP
基于 Codeforces Polygon API 的 MCP 工具集,提供一系列工具函数用于管理 Polygon 平台上的题目。
功能特性
- 获取题目列表,支持多种筛选条件
- 创建新的空题目
- 获取题目详细信息(时限、内存限制等)
- 获取题目描述、题解、输入输出格式等
- 获取和保存题目陈述资源、源文件、辅助文件
- 获取和保存测试脚本、测试点、validator/checker 测试、测试组
- 获取题目解决方案
- 获取题目验证器、额外验证器、检查器、交互器,并支持设置验证器/检查器/交互器
- 获取和保存题目标签、通用描述、通用题解
- 获取历史包、下载包、构建包、提交工作副本
- 提供出题流程辅助工具,包括 readiness 检查、打包等待和发布编排
- 通过 Polygon 账号密码下载 problem package、problem.xml、contest.xml、statements.pdf
- 获取比赛题目列表
- 更新题目信息
- 更新/丢弃工作副本
- 更新题目描述
配置
向 mcp.json 中添加:
"cf-polygon-mcp": {
"command": "uvx",
"args": ["cf-polygon-mcp"],
"env": {
"POLYGON_API_KEY": "your_key",
"POLYGON_API_SECRET": "your_secret",
"POLYGON_LOGIN": "your_login",
"POLYGON_PASSWORD": "your_password"
}
}
在使用前,需要设置 Polygon API 密钥。可在 Polygon 设置页面 获取 API Key 和 Secret。
面向出题人的典型工作流
大多数题目都可以按下面四段来推进:
- 建题与元信息:先用
create_problem创建空题,再用update_problem_info设置时限、内存、输入输出文件名,以及是否为交互题。 - 题面与素材:用
save_problem_statement更新题面,用save_problem_statement_resource上传图片或附加素材,用save_problem_script、save_problem_test管理测试脚本和样例。 - 评测逻辑:用
set_problem_validator、set_problem_checker、set_problem_interactor配置评测组件,再用save_problem_solution上传主解和错误解。 - 收口与发布:先跑
check_problem_readiness,再用build_problem_package_and_wait验证打包流程,最后用prepare_problem_release做完整发布编排。
如果你只是做普通非交互题,最常用的一组工具通常是:
create_problemupdate_problem_infosave_problem_statementsave_problem_scriptsave_problem_testset_problem_validatorsave_problem_solutioncheck_problem_readinessbuild_problem_package_and_wait
写操作和 workflow 工具都会返回结构化结果。最常见的固定字段是 status、action、message、result;workflow 结果还会补充 stage、decision、can_retry、recovery_actions。
从新建题目到发布的完整链路示例
下面示例按“普通非交互题”给出一条最短闭环。示例里的 problem_id 请替换成你自己的题目编号;如果你刚调用过 create_problem,后续一般直接取返回值里的 problem.id 即可。
- 创建空题:
{
"name": "Array Rotation"
}
- 设置题目基础信息:
{
"problem_id": 123456,
"input_file": "stdin",
"output_file": "stdout",
"time_limit": 2000,
"memory_limit": 256,
"interactive": false
}
- 写英文题面:
{
"problem_id": 123456,
"lang": "english",
"name": "Array Rotation",
"legend": "给定一个数组和若干操作,计算最终数组。",
"input": "第一行包含 n 和 q。",
"output": "输出最终数组。",
"notes": "样例中的数组下标从 1 开始。"
}
- 上传测试脚本:
{
"problem_id": 123456,
"testset": "tests",
"source": "gen 5 > $"
}
- 补一个样例测试:
{
"problem_id": 123456,
"testset": "tests",
"test_index": 1,
"test_input": "5 2\n1 2 3 4 5\n1 3\n2 5\n",
"test_use_in_statements": true,
"test_input_for_statements": "5 2\n1 2 3 4 5\n1 3\n2 5\n",
"test_output_for_statements": "3 4 5 1 2\n"
}
- 设置 validator,并上传主解和错误解:
{
"problem_id": 123456,
"validator": "validator.cpp"
}
{
"problem_id": 123456,
"name": "main.cpp",
"local_path": "/path/to/main.cpp",
"tag": "MA"
}
{
"problem_id": 123456,
"name": "wrong.cpp",
"local_path": "/path/to/wrong.cpp",
"tag": "WA"
}
- 运行 readiness 检查:
{
"problem_id": 123456,
"testset": "tests"
}
重点看返回值中的 blocking_issues、warnings 和 details。如果 status 不是成功,或者 blocking_issues 非空,先修题再继续。
- 触发打包并等待结果:
{
"problem_id": 123456,
"full": true,
"verify": true,
"timeout_seconds": 1800,
"poll_interval_seconds": 5.0
}
- 最后执行统一发布流程:
{
"problem_id": 123456,
"testset": "tests",
"full": true,
"verify": true,
"message": "prepare release",
"minor_changes": true
}
如果你只是想单独检查 readiness 或构建,不一定要直接调用 prepare_problem_release。这个 workflow 更适合“准备发布前做一次全链路收口”。
交互题、带分题与测试组题目的常见操作
- 交互题:先用
update_problem_info(problem_id=..., interactive=true)打开交互模式,再调用set_problem_interactor、set_problem_checker,并在save_problem_statement里填写interaction字段。最后用check_problem_readiness检查interactive、interactor、checker和题面interaction是否一致。 - 带分题:先用
enable_problem_points(problem_id=..., enable=true)打开点数模式,再在save_problem_test中填写test_points,同时在save_problem_statement里补scoring。如果只开了点数模式却没写评分说明,check_problem_readiness会给出告警。 - 测试组题:先用
enable_problem_groups(problem_id=..., testset="tests", enable=true),再用save_problem_test_group配置组,例如points_policy="COMPLETE_GROUP"、feedback_policy="ICPC",之后用set_problem_test_group绑定测试。若测试组依赖成环,check_problem_readiness会直接报出 cycle。 - 错误解覆盖:建议至少上传一个主解和若干典型错误解,用
save_problem_solution设置tag="MA"、tag="WA"、tag="TL"等;如果还需要把错误解绑定到某个测试组,可以再调用edit_problem_solution_extra_tags。
错误排查
- 缺少 API 凭证:大多数工具依赖
POLYGON_API_KEY和POLYGON_API_SECRET;下载 problem package、problem.xml、contest.xml、statements.pdf 这类工具还需要POLYGON_LOGIN和POLYGON_PASSWORD。 check_problem_readiness未通过:先看blocking_issues和warnings,再看details中是哪一节失败。这个工具已经会检查题面资源缺失、交互题配置不一致、测试组依赖成环、评分说明缺失、样例缺失、主解/错误解覆盖不足、generator 与脚本漂移等问题。build_problem_package_and_wait失败或超时:优先看stage、decision、package、package_history。如果can_retry=true,通常可以直接使用返回值里的recovery_actions选择下一步。prepare_problem_release被拦下:常见的decision包括update_failed、blocking_issues、warnings_not_allowed、build_failed、commit_failed。这几个分支都会给出recovery_actions,可以按建议先单独修复,再重试完整 workflow。- 样例或资源对不上:如果题面里引用了图片、代码片段或外部资源,但
save_problem_statement_resource没有上传对应文件,readiness 会直接指出缺失文件名。 - 测试脚本和生成器不一致:如果脚本里引用了不存在的生成器文件,或者测试上的
scriptLine已经和当前脚本漂移,readiness 会在details里标出来。
开发
- 确保你已经安装了 Python 3.11 及以上版本。
- 克隆项目:
git clone https://github.com/gsh20040816/cf-polygon-mcp.git
cd cf-polygon-mcp
- 安装依赖:
uv sync
- 运行项目:
uv run mcp dev main.py
- 运行测试:
python -m unittest discover -s tests -v
GitHub 自动发版
仓库包含两个 GitHub Actions 工作流:
- ci.yml:在
push到main或收到pull_request时运行,使用 Python 3.11 安装依赖、执行python -m unittest discover -s tests -v,并构建sdist和wheel - publish.yml:仅在推送版本 tag(如
v0.11.0)时运行,会重新执行测试与构建,校验 tag 与pyproject.toml中的版本一致,并在该版本尚未发布到 PyPI 时上传发行包
推荐的发布流程:
- 更新 pyproject.toml 中的版本号并推送到
main - 等待 ci.yml 通过
- 创建并推送对应版本 tag,例如
git tag v0.11.0 && git push origin v0.11.0
要让自动发布生效,需要先在 PyPI 的 Trusted Publisher 中添加这个 GitHub 仓库:
- Owner:
gsh20040816 - Repository name:
cf-polygon-mcp - Workflow name:
publish.yml - Environment name:
pypi
许可证
说明
本项目由 AI 生成。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cf_polygon_mcp-0.11.0.tar.gz.
File metadata
- Download URL: cf_polygon_mcp-0.11.0.tar.gz
- Upload date:
- Size: 78.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
170c6927b313557723fb073fe96df41210abae4c1344e7b07c5c85b6bcd26f91
|
|
| MD5 |
5d060dc3020e417077674f39df794dc4
|
|
| BLAKE2b-256 |
f64a8d4fadb4f8d308902bffe2154b70b19b30d479c670e257e7a7d3df62e692
|
Provenance
The following attestation bundles were made for cf_polygon_mcp-0.11.0.tar.gz:
Publisher:
publish.yml on gsh20040816/cf-polygon-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cf_polygon_mcp-0.11.0.tar.gz -
Subject digest:
170c6927b313557723fb073fe96df41210abae4c1344e7b07c5c85b6bcd26f91 - Sigstore transparency entry: 1054913259
- Sigstore integration time:
-
Permalink:
gsh20040816/cf-polygon-mcp@7a27a47fb108bed98e8b1775788269100db225f0 -
Branch / Tag:
refs/tags/v0.11.0 - Owner: https://github.com/gsh20040816
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7a27a47fb108bed98e8b1775788269100db225f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cf_polygon_mcp-0.11.0-py3-none-any.whl.
File metadata
- Download URL: cf_polygon_mcp-0.11.0-py3-none-any.whl
- Upload date:
- Size: 91.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54f56cbc79fcd56b640bf5ee9033cc7b807ddfce75e3e396912f9f307bfdeaf5
|
|
| MD5 |
ea589041326ee1574faf79b358901152
|
|
| BLAKE2b-256 |
5a41579bec51811d79129831b2c3f9790a9b3526cdd6624ada6af9fa3225173e
|
Provenance
The following attestation bundles were made for cf_polygon_mcp-0.11.0-py3-none-any.whl:
Publisher:
publish.yml on gsh20040816/cf-polygon-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cf_polygon_mcp-0.11.0-py3-none-any.whl -
Subject digest:
54f56cbc79fcd56b640bf5ee9033cc7b807ddfce75e3e396912f9f307bfdeaf5 - Sigstore transparency entry: 1054913571
- Sigstore integration time:
-
Permalink:
gsh20040816/cf-polygon-mcp@7a27a47fb108bed98e8b1775788269100db225f0 -
Branch / Tag:
refs/tags/v0.11.0 - Owner: https://github.com/gsh20040816
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7a27a47fb108bed98e8b1775788269100db225f0 -
Trigger Event:
push
-
Statement type: