Skip to main content
Glama
README.md
<div align="center">

# 🧑‍💻 vnoi-mcp

**Let AI read problems, write code, and submit on [VNOI Online Judge](https://oj.vnoi.info).**

An MCP server that connects Claude, LM Studio, Cursor, and other MCP clients to VNOJ: read statements, submit solutions, and get per-test verdicts, all without leaving the chat.

![Python](https://img.shields.io/badge/python-3.12%2B-blue) ![MCP](https://img.shields.io/badge/MCP-server-purple) ![uv](https://img.shields.io/badge/managed%20by-uv-orange) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)

</div>

---

## ✨ What it does

One prompt is all it takes:

> *"Solve contest `vnoicup25_r1`: read each problem, write a C++17 solution, submit it, and if it fails, read the verdict, fix it, and resubmit."*

The model then loops on its own:

```
list_problems ─► get_problem ─► write code ─► submit
                                    ▲            │
                                    └─ WA/TLE ◄──┘
```

It's especially handy for **problem setters**: have the AI solve your problems independently and submit, to surface weak tests, wrong tests, or ambiguous statements.

## 🧰 Tools

| Tool | Arguments | Returns |
|---|---|---|
| `vnoi_list_problems` | `contest_id` | Problems in a contest: code, name, time limit, memory limit, points |
| `vnoi_get_problem` | `problem_code` | Full statement as Markdown: limits, description, I/O format, subtasks, samples |
| `vnoi_submit` | `problem_code`, `code`, `language` | Submits, **waits for judging to finish**, returns per-test results (grouped by batch if any) |
| `vnoi_get_result` | `submission_id` | Results of an existing submission |

Example `vnoi_submit` output:

```
Submission ID: 1234567
Batch #1 (25/25 points)
  Test 1: AC | 0.009s | 680.00 KB
  Test 2: AC | 0.010s | 672.00 KB
Batch #2 (0/25 points)
  Test 1: TLE | >1.000s | 660.00 KB
```

<details>
<summary>Language IDs (<code>language</code>)</summary>

| Language | ID | | Language | ID |
|---|---|---|---|---|
| **C++17** (default) | `4` | | Python 3 | `9` |
| C++20 | `14` | | PyPy 3 | `17` |
| C++23 | `23` | | Java 25 | `18` |
| C | `5` | | Rust | `22` |

</details>

## 🚀 Quick start

**Requirements:** Python 3.12+ and [uv](https://docs.astral.sh/uv/getting-started/installation/).

```bash
git clone https://github.com/RMQuan/vnoi-mcp.git
cd vnoi-mcp
uv sync
cp .env.example .env
```

### 1. Get your session cookie

1. Log in to [oj.vnoi.info](https://oj.vnoi.info) in your browser.
2. Open DevTools (`Cmd + Option + I` / `F12`) → **Application** → **Cookies** → `https://oj.vnoi.info`.
3. Copy the value of `sessionid` into `.env`:

```env
VNOI_SESSION=paste_your_sessionid_here
```

> [!WARNING]
> `sessionid` grants **full access to your VNOI account**, just like a password. Never share or commit it. `.env` is already in `.gitignore`.

### 2. Test it

```bash
uv run mcp dev server.py
```

The MCP Inspector opens in your browser → **Connect** → **Tools** → try `vnoi_get_problem` with `problem_code = post`.

### 3. Connect a client

**Claude Code**

```bash
claude mcp add vnoi -- uv --directory /path/to/vnoi-mcp run server.py
```

**LM Studio / Cursor / Claude Desktop** (`mcp.json`)

```json
{
  "mcpServers": {
    "vnoi": {
      "command": "uv",
      "args": ["--directory", "/path/to/vnoi-mcp", "run", "server.py"]
    }
  }
}
```

> [!TIP]
> If a macOS app can't find `uv`, replace `"uv"` with its full path from `which uv` (e.g. `/opt/homebrew/bin/uv`).

## ⚙️ How it works

VNOJ (a fork of [DMOJ](https://github.com/DMOJ/online-judge)) has no submission API, so the server **acts like a browser**:

```
GET  /problem/<code>/submit  → grab csrfmiddlewaretoken (HTML) + csrftoken cookie
POST /problem/<code>/submit  → source, language, token → 302 → /submission/<id>
GET  /submission/<id>        → poll until grading ends, then parse the results table
```

| File | Role |
|---|---|
| `server.py` | Declares the MCP tools and turns errors into readable messages for the model |
| `vnoi_session.py` | Logged-in session (cookie from `.env`) and CSRF token handling |
| `vnoi_read_problem.py` | Lists problems in a contest |
| `vnoi_read_statement.py` | Converts a problem statement to Markdown |
| `vnoi_submit.py` | Submits, waits for judging, parses results (with or without batches) |

## 🩺 Troubleshooting

| Error | Fix |
|---|---|
| `Chưa có VNOI_SESSION trong .env` (no session cookie) | Create `.env` and fill in your cookie (step 1) |
| Cookie expired / redirected to the login page | Log in again in your browser and copy the new `sessionid` |
| `Không thấy danh sách bài của contest…` (contest problems not found) | Check the contest code and make sure you have **joined** the contest |
| `Submit thất bại, status_code=403` (submit failed) | Possibly blocked by Cloudflare; retry later or refresh your cookie |
| `Hết …s mà bài … vẫn đang chấm` (still judging after timeout) | The judge queue is busy; call `vnoi_get_result` with that ID a bit later |

## 🔒 Limitations

The server acts **as your VNOI account**, so it can only see and do what you can in your browser:

- **Contests:** you must have **joined** a contest before `vnoi_list_problems` and `vnoi_get_problem` can read its problems. Contests that haven't started, or whose problems are hidden from you, return an error.
- **Hidden / private problems:** only accessible if your account has author, tester, or curator permissions on them.
- **Submissions:** subject to the same rules as manual submissions: per-problem submission limits, allowed languages, and the contest's time window.
- **Results:** `vnoi_get_result` can only read submissions your account is allowed to view.
- **Session lifetime:** the cookie expires when you log out or after a period of inactivity; you'll need to refresh `VNOI_SESSION` then.
- **One account:** the server uses a single cookie from `.env`; there is no multi-account support.
- **No official API:** results come from parsing VNOJ's HTML. Compile-error output and unusual verdict layouts are handled on a best-effort basis.

## ⚠️ Use responsibly

- **Do not use this in live rated contests.** Letting an AI solve problems for you is cheating and violates VNOI's rules.
- Intended for practice, virtual contests, and **testing problem sets as a setter**.
- Don't spam submissions: VNOI's judges are a shared community resource.
- The tool parses HTML, so it may break if VNOI changes its layout. Please open an issue if it does.

## 📄 License

[MIT](LICENSE) © 2026 RMQuan. Provided "as is", without warranty of any kind; use at your own risk.

---

<div align="center">
Made with ☕ by <a href="https://github.com/RMQuan">RMQuan</a>
</div>

TDQS

A3.9/5.0

Scored across 4 tools

Disambiguation4/5

Each tool targets a distinct step: listing problems in a contest, fetching a full problem statement, submitting code, and retrieving a past submission. The only potential overlap is vnoi_submit vs vnoi_get_result, since both return judging results, but the descriptions explicitly state get_result is the fallback when submit times out. That clarification makes misselection unlikely.

Naming Consistency5/5

All four tools use a uniform vnoi_ prefix with snake_case verb_noun structure (list_problems, get_problem, submit, get_result). vnoi_submit drops the object noun, but the verb is unambiguous and the pattern reads consistently across the set.

Tool Count5/5

Four tools map cleanly onto the four steps of the judge workflow (enumerate → read → submit → verify), with no redundant or speculative tools. The surface is minimal but every tool earns its place for the competitive-programming-judge domain.

Completeness3/5

The core solve-a-problem loop is covered end to end, but there is no way to discover contest IDs (no list_contests) or browse a problem archive, so an agent must already know a contest code. There is also no submission-history or user-status tool, which leaves notable gaps beyond the happy path.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues