Skip to main content
Glama
README.md
# tpcu-mcp

[![CI](https://github.com/alaner652/tpcu-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/alaner652/tpcu-mcp/actions/workflows/ci.yml)
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg)](LICENSE)
[![Node >= 20](https://img.shields.io/badge/node-%3E%3D20-brightgreen)](package.json)

**English** | [繁體中文](README.zh-TW.md)

An [MCP](https://modelcontextprotocol.io) server for the student information system of TPCU (Taipei City University of Science and Technology).
It exposes the timetable, absences, grades, leave requests and work-study attendance as MCP tools, so an MCP client (Claude Code, Claude Desktop, Codex CLI, Gemini CLI, ...) can query and act on them in a conversation:

> "What classes do I have today?" "Any absences lately?" "Request personal leave for my absences on 10/12." "Fill in this month's work-study hours."

- TypeScript and the official `@modelcontextprotocol/sdk`, stdio transport, no backend of its own.
- Talks HTTP to `siw.tpcu.edu.tw` directly and parses the HTML.
- The AI asks you for your student ID and password through the `login` tool; they stay in memory only and are never written to disk or logs.

> **Unofficial.** This project is not affiliated with TPCU. Read the [security policy](SECURITY.md) and decide for yourself whether to give your credentials to an AI client.

## Install

```bash
git clone https://github.com/alaner652/tpcu-mcp.git
cd tpcu-mcp
npm install
npm run build        # writes dist/
```

Node.js 20 or later is required.

## Connect a client

Replace `/absolute/path/to/tpcu-mcp` with your clone.

### Claude Code

```bash
claude mcp add --scope user tpcu -- node /absolute/path/to/tpcu-mcp/dist/index.js
```

### Claude Desktop

`~/Library/Application Support/Claude/claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "tpcu": {
      "command": "node",
      "args": ["/absolute/path/to/tpcu-mcp/dist/index.js"]
    }
  }
}
```

### Codex CLI

`~/.codex/config.toml`:

```toml
[mcp_servers.tpcu]
command = "node"
args = ["/absolute/path/to/tpcu-mcp/dist/index.js"]
```

### Gemini CLI

`~/.gemini/settings.json`: same JSON as Claude Desktop.

After changing `src/`, run `npm run build` and reconnect the client.

## Example

```
You: Any absences lately?
AI:  (get_session_status -> not signed in -> asks for ID and password -> login -> fetch_absence)
     7 periods in the last 30 days: 10/12 (Mon) periods 6-8, 10/14 (Wed) periods 3-6 ...

You: Request personal leave for 10/12, family matters.
AI:  (get_leave_form -> lists date, periods, leave type and reason for you to confirm)
You: Confirm.
AI:  (apply_leave) Submitted; waiting for your homeroom teacher.
```

## Environment variables (all optional)

| Variable | Default | Meaning |
| --- | --- | --- |
| `SCHOOL_BASE_URL` | `https://siw.tpcu.edu.tw` | School system endpoint |
| `UPSTREAM_TIMEOUT_MS` | `30000` | Timeout per request to the school |
| `LOG_LEVEL` | `info` | `debug` / `info` / `warn` / `error`; logs go to stderr only |
| `TPCU_ATTACHMENT_DIR` | none | When set, `apply_leave` attachments must be inside this directory |

An invalid setting stops the server at start-up with the reason (never the value) on stderr.

## Tools

| Tool | Sign-in | Side effect | Purpose |
| --- | :-: | :-: | --- |
| `login` | - | - | Sign in; returns name, student ID and current semester |
| `logout` | - | - | Clear the in-memory session (only when the user asks) |
| `get_session_status` | - | - | Whether you are signed in, and the current semester |
| `get_current_date` | - | - | Today in Taipei time, AD and ROC |
| `get_semester_options` | yes | - | Semesters available |
| `fetch_schedule` | yes | - | Whole-semester timetable |
| `get_day_schedule` | yes | - | Classes on one day (default today) |
| `get_next_class` | yes | - | The class now or next |
| `fetch_absence` | yes | - | Absences in a date range (default last 30 days) |
| `fetch_grades` | yes | - | Grades for all years |
| `get_leaves` | yes | - | Leave requests and their approval status |
| `get_leave_form` | yes | - | Periods on a date and which have classes |
| `apply_leave` | yes | creates | Submit a leave request (official leave needs an attachment) |
| `delete_leave` | yes | **irreversible** | Withdraw a pending leave request |
| `get_workstudy_master` | yes | - | Work-study months, unit and job codes, status |
| `get_workstudy_month` | yes | - | Existing attendance rows of a month |
| `plan_workstudy` | optional | - | Expand a fixed weekly shift pattern into a month, skipping class times |
| `save_workstudy` | yes | **overwrites month** | Submit a month of work-study attendance |

Every tool carries MCP `annotations` (`readOnlyHint` / `destructiveHint`). Tools with side effects tell the host model to confirm with the user first.

## Quick reference

- **Dates**: tool parameters use ROC compact `YYYMMDD`, e.g. `1150521` = 2026-05-21. AD = ROC + 1911.
- **Semester code**: `114,2` = academic year 114, semester 2.
- **Leave types**: 21 personal, 22 sick, 23 official (military service, court, national exams, department; JPEG or PDF attachment), 24 bereavement, 25 marriage, 26 maternity, 27 nursing, 28 epidemic, 29 menstrual, 31 indigenous.
- **Work-study**: at most 7.5 hours a day and one row per day; saving overwrites the whole month, so rows to keep (with `seq`) must be sent again.

## Errors

A failed tool returns `isError: true` with:

```json
{ "error": { "code": "SESSION_EXPIRED", "message": "學校系統 session 已過期", "hint": "請重新呼叫 login 工具。" } }
```

| code | Meaning |
| --- | --- |
| `INVALID_INPUT` | Bad parameters (usually caught by the schema first) |
| `NOT_LOGGED_IN` | `login` not called yet |
| `LOGIN_FAILED` | Wrong credentials or the school is busy |
| `SESSION_EXPIRED` | The school ended the session; sign in again |
| `UPSTREAM_ERROR` | Connection or HTTP error from the school |
| `PRECONDITION_FAILED` | Missing prerequisite (e.g. no `pay_seqid` for the month, duplicate dates) |
| `LEAVE_CONFLICT` / `MISSING_ATTACHMENT` / `LEAVE_APPROVED` | Leave business errors (in `error_code`) |
| `INTERNAL` | Unexpected; details only on stderr |

## Documentation

See [docs/](docs/README.md): architecture, development, project status.

## Credits and license

The business logic (page flows, field names, parsing rules, shift planning) comes from the author's Agora-AI project (Python / FastAPI), reimplemented here in TypeScript as a standalone MCP server.

[GNU AGPL v3.0 or later](LICENSE) © 2026 small R (alaner652)