# msr327/iitkgp-erp-mcp architecture

> Architecture diagram of the GitHub repository msr327/iitkgp-erp-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/msr327/iitkgp-erp-mcp
- Repository: https://github.com/msr327/iitkgp-erp-mcp

## Overview

#### Purpose and Entry Points
This package exposes IIT Kharagpur ERP data and workflows as a local MCP server for AI-agent clients. The primary runtime entry point is `src/server.py`; installation/setup behavior is defined through `pyproject.toml` and `src/setup.py`. MCP communication is local stdio, while ERP interaction targets `erp.iitkgp.ac.in`.

#### MCP Tool Boundary
`src/server.py` is the orchestration boundary between MCP tool calls and ERP-backed operations. It presents tools for grades/GPA analysis, attendance decisions, elective recommendations, timetable/calendar use, notices/placements, and freeform ERP navigation. Tool handlers should remain responsible for input validation, session requirements, and formatting agent-facing results, delegating ERP retrieval to scraper modules.

#### Authentication and Session Lifecycle
Authentication is isolated under `src/auth/login.py` and `src/auth/credentials.py`. Setup stores credentials in the OS keychain; login handles live OTP without persistence. An authenticated ERP session is then consumed by scraper operations, and logout terminates it. This is the main security boundary: credentials and OTP remain local, while only authenticated requests/browser activity reach the ERP.

#### ERP Retrieval Layer
The scraper package encapsulates ERP page navigation, HTTP extraction, and HTML parsing. Domain-specific modules include `src/scrapers/grades.py`, `src/scrapers/attendance.py`, `src/scrapers/timetable.py`, `src/scrapers/electives.py`, `src/scrapers/placements.py`, `src/scrapers/notices.py`, and `src/scrapers/registration.py`. These modules form the volatile integration boundary because ERP selector and page-layout changes should be contained here.

#### Browser and Transport Strategy
`src/scrapers/browser.py` provides the browser automation path for JavaScript-heavy or interactive ERP pages, using Playwright Chromium. Conventional retrieval uses requests plus BeautifulSoup according to the documented architecture. The server/selectors should choose the least expensive mechanism: direct parsed requests for stable content, browser automation for rendered pages or interactive exploration.

#### Derived Academic and Scheduling Features
Retrieved grade records feed server-level calculations such as CGPA/SGPA, trends, comparisons, projections, grade distributions, and elective recommendations. Attendance records drive alerts and “can I skip” calculations. Timetable data supports day filtering, professor lookup, and ICS calendar export. These are local transformations over scraper output rather than separate remote services; their public behavior is surfaced through `src/server.py` and sourced mainly from `src/scrapers/grades.py`, `src/scrapers/attendance.py`, and `src/scrapers/timetable.py`.

#### Local State and Operations
`src/utils/cache.py` owns locally cached ERP-derived data, reducing repeated authenticated retrieval and providing the clear-cache capability. Environment-sensitive values are represented by `.env.example`; credentials are explicitly not committed. Runtime dependencies materially include Python, MCP-compatible clients, OS keychain support, requests/BeautifulSoup, and Playwright Chromium.

Main entry points: [`src/server.py`](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/server.py) (MCP tool server), [`src/auth/login.py`](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/auth/login.py) (Login & session), [`src/scrapers/grades.py`](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/grades.py) (Grades retrieval), [`src/scrapers/attendance.py`](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/attendance.py) (Attendance retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mcp["MCP Server"]
  node_server["MCP tool server<br/>Python runtime<br/>[server.py]"]
  node_packaging["Install &amp; setup<br/>package setup<br/>[pyproject.toml]"]
  node_derived["Academic &amp; schedule analysis<br/>local transformations<br/>[server.py]"]
end

subgraph group_auth["Authentication"]
  node_setup["Credential setup<br/>setup module<br/>[setup.py]"]
  node_credentials["Credential store<br/>keychain adapter<br/>[credentials.py]"]
  node_login["Login &amp; session<br/>auth module<br/>[login.py]"]
end

subgraph group_scrapers["ERP Retrieval"]
  node_grades["Grades retrieval<br/>scraper<br/>[grades.py]"]
  node_attendance["Attendance retrieval<br/>scraper<br/>[attendance.py]"]
  node_timetable["Timetable retrieval<br/>scraper<br/>[timetable.py]"]
  node_electives["Electives retrieval<br/>scraper<br/>[electives.py]"]
  node_campus["Notices &amp; placements<br/>scrapers<br/>[notices.py]"]
  node_registration["Registration retrieval<br/>scraper<br/>[registration.py]"]
  node_browser["Browser automation<br/>Playwright Chromium<br/>[browser.py]"]
end

subgraph group_local["Local State"]
  node_cache[("ERP cache<br/>local cache<br/>[cache.py]")]
  node_env["Environment template<br/>env example<br/>[.env.example]"]
end

subgraph group_external["External Systems"]
  node_agent(("AI-agent client<br/>MCP client"))
  node_erp{{"IITKGP ERP<br/>remote ERP"}}
end

node_agent -->|"local stdio MCP"| node_server
node_packaging -->|"installs setup flow"| node_setup
node_setup -->|"stores credentials"| node_credentials
node_env -.->|"runtime values"| node_server
node_server -->|"requires session"| node_login
node_login -->|"reads credentials"| node_credentials
node_login -->|"OTP login / logout"| node_erp
node_server -->|"reads and clears"| node_cache
node_server -->|"grade tools"| node_grades
node_server -->|"attendance tools"| node_attendance
node_server -->|"timetable &amp; calendar tools"| node_timetable
node_server -->|"recommendation data"| node_electives
node_server -->|"notices &amp; placements"| node_campus
node_server -->|"ERP navigation"| node_registration
node_grades -->|"grade records"| node_derived
node_attendance -->|"attendance records"| node_derived
node_timetable -->|"schedule records"| node_derived
node_derived -->|"agent-facing results"| node_server
node_grades -.->|"uses session"| node_login
node_attendance -.->|"uses session"| node_login
node_timetable -.->|"uses session"| node_login
node_grades -->|"parsed requests"| node_erp
node_attendance -->|"parsed requests"| node_erp
node_timetable -->|"parsed requests"| node_erp
node_browser -->|"interactive pages"| node_erp
node_server -.->|"rendered-page fallback"| node_browser

click node_server "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/server.py"
click node_packaging "https://github.com/msr327/iitkgp-erp-mcp/blob/main/pyproject.toml"
click node_setup "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/setup.py"
click node_credentials "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/auth/credentials.py"
click node_login "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/auth/login.py"
click node_cache "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/utils/cache.py"
click node_grades "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/grades.py"
click node_attendance "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/attendance.py"
click node_timetable "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/timetable.py"
click node_electives "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/electives.py"
click node_campus "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/notices.py"
click node_registration "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/registration.py"
click node_browser "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/browser.py"
click node_env "https://github.com/msr327/iitkgp-erp-mcp/blob/main/.env.example"
click node_derived "https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/server.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_packaging,node_derived toneBlue
class node_setup,node_credentials,node_login toneAmber
class node_grades,node_attendance,node_timetable,node_electives,node_campus,node_registration,node_browser toneMint
class node_cache,node_env toneRose
class node_agent,node_erp toneIndigo
```

## Components

### MCP Server

- [MCP tool server](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/server.py): Python runtime · Validates tool inputs, manages sessions, and formats agent results. · `src/server.py`
- [Install & setup](https://github.com/msr327/iitkgp-erp-mcp/blob/main/pyproject.toml): package setup · Defines installation and setup behavior. · `pyproject.toml`
- [Academic & schedule analysis](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/server.py): local transformations · Calculates GPA, attendance decisions, recommendations, and calendar output. · `src/server.py`

### Authentication

Local credential handling and authenticated ERP sessions.

- [Credential setup](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/setup.py): setup module · Stores credentials in the OS keychain. · `src/setup.py`
- [Credential store](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/auth/credentials.py): keychain adapter · Keeps ERP credentials local in the OS keychain. · `src/auth/credentials.py`
- [Login & session](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/auth/login.py): auth module · Handles live OTP and authenticated session lifecycle. · `src/auth/login.py`

### ERP Retrieval

Volatile ERP navigation and parsing boundary.

- [Grades retrieval](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/grades.py): scraper · `src/scrapers/grades.py`
- [Attendance retrieval](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/attendance.py): scraper · `src/scrapers/attendance.py`
- [Timetable retrieval](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/timetable.py): scraper · `src/scrapers/timetable.py`
- [Electives retrieval](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/electives.py): scraper · `src/scrapers/electives.py`
- [Notices & placements](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/notices.py): scrapers · `src/scrapers/notices.py`
- [Registration retrieval](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/registration.py): scraper · `src/scrapers/registration.py`
- [Browser automation](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/scrapers/browser.py): Playwright Chromium · Used for rendered or interactive ERP pages. · `src/scrapers/browser.py`

### Local State

- [ERP cache](https://github.com/msr327/iitkgp-erp-mcp/blob/main/src/utils/cache.py): local cache · Caches ERP-derived data and supports clearing it. · `src/utils/cache.py`
- [Environment template](https://github.com/msr327/iitkgp-erp-mcp/blob/main/.env.example): env example · Documents environment-sensitive values without committed credentials. · `.env.example`

### External Systems

- **AI-agent client**: MCP client
- **IITKGP ERP**: remote ERP · Authenticated ERP site at erp.iitkgp.ac.in.

## Connections

- AI-agent client → MCP tool server: local stdio MCP
- Install & setup → Credential setup: installs setup flow
- Credential setup → Credential store: stores credentials
- Environment template → MCP tool server: runtime values
- MCP tool server → Login & session: requires session
- Login & session → Credential store: reads credentials
- Login & session → IITKGP ERP: OTP login / logout
- MCP tool server → ERP cache: reads and clears
- MCP tool server → Grades retrieval: grade tools
- MCP tool server → Attendance retrieval: attendance tools
- MCP tool server → Timetable retrieval: timetable & calendar tools
- MCP tool server → Electives retrieval: recommendation data
- MCP tool server → Notices & placements: notices & placements
- MCP tool server → Registration retrieval: ERP navigation
- Grades retrieval → Academic & schedule analysis: grade records
- Attendance retrieval → Academic & schedule analysis: attendance records
- Timetable retrieval → Academic & schedule analysis: schedule records
- Academic & schedule analysis → MCP tool server: agent-facing results
- Grades retrieval → Login & session: uses session
- Attendance retrieval → Login & session: uses session
- Timetable retrieval → Login & session: uses session
- Grades retrieval → IITKGP ERP: parsed requests
- Attendance retrieval → IITKGP ERP: parsed requests
- Timetable retrieval → IITKGP ERP: parsed requests
- Browser automation → IITKGP ERP: interactive pages
- MCP tool server → Browser automation: rendered-page fallback
