moodle mcp <subcommand> runs and manages moodle-cli’s MCP (Model Context Protocol) server — the interface an AI agent uses to read your Moodle data. This page covers what each subcommand does on your machine. For connecting a specific client app (Claude Code, Claude Desktop, Codex, VS Code, Cursor, and others) once a server is running, see MCP servers, How it works and the client pages under Connect a client.

Local: mcp serve

Runs an MCP server using your local session — no Cloudflare account, deployment, or network exposure required. This is what a locally-run client (Claude Code, Claude Desktop, Codex, Cursor) talks to directly. The local server exposes one tool the managed remote server does not: submit, which uploads local files into an assignment. It only appears locally because the remote server has no filesystem to read files from. Calling it without explicitly asking for an upload only gets the plan, never an upload, matching the CLI’s own plan-first behavior described in Submit. See the full list of tools it exposes, with their parameters and read/write status, at Moodle MCP tool catalog.

Managed deployment: mcp deploy

Deploys (or updates) a private MCP server to your own Cloudflare account, so hosted clients that can’t run a local process (like claude.ai) can reach it. This needs a Cloudflare account; Cloudflare’s free tier covers it within its usage limits. deploy runs through these steps, in order:
  1. Validating your Moodle session
  2. Checking Cloudflare access
  3. Preparing a Worker release
  4. Uploading private credentials
  5. Deploying the new version
  6. Uploading your Moodle session
  7. Running MCP and Moodle checks
  8. Installing renewal and connecting your local client
Two credentials come out of this: an MCP access token (what clients use to read data from the deployed server) and a session sync token (what this computer uses to push a fresh Moodle session to it later). Both are stored in your OS’s credential manager — Keychain on macOS, the Secret Service on Linux, or Credential Manager on Windows — never in logs or project files. Where none of those is available, moodle-cli falls back to a permission-restricted local file, encrypted on Windows. Flags: Each deployment serves one Moodle account. Uploading a session for a different account is refused; deploy a separate server for that account. The remote server is read-only. Its file tool returns files up to 16 MiB inside the response, so a client never needs a signed-in Moodle link of its own. --rotate-key re-encrypts the active session with a new key, checks it, then retires the old key. --repair brings the deployment back in line after an upload was interrupted.

Managing the deployment tool

deploy needs a small companion tool to manage the Worker on your Cloudflare account. moodle-cli uses one already on your system if it’s a compatible version; otherwise it downloads the right version once, with your confirmation, into ~/.config/moodle-cli/tools/wrangler@<version> and reuses it from there on every later deploy.

mcp status

Reports local and remote Moodle MCP readiness. --verbose includes sanitized deployment diagnostics; --logs includes sanitized recent Worker logs.

mcp login

Gets a fresh Moodle session locally and uploads it to your deployed server, using the session sync token from mcp deploy. Run this after your Moodle session expires and the deployed copy has gone stale — mcp session push and the renewal job (below) are the other two ways a deployed session gets refreshed.

mcp connect

Connects a supported MCP client by writing (or updating) that client’s own configuration file. The supported clients are codex, claude-desktop (also matched by plain claude), claude-code, vscode (also matched by vs-code), and cursor. Passed with no argument, connect targets whichever supported clients it detects installed. --mode is bridge (the default) or remote:
  • bridge writes a command invocation (moodle mcp bridge --profile ...) into the client’s config. No token is ever written to disk in the client’s own file — the bridge process reads the access token from your OS credential manager at connect time and attaches it to each request itself.
  • remote writes the deployed server’s address and the access token directly into the client’s config, for clients that connect to a remote MCP server directly.
--show-token reveals the access token once, after you confirm — useful for a client connect doesn’t have a built-in setup for; see Other clients.

mcp bridge

Runs the process that mcp connect --mode bridge wires into a client’s config. It reads MCP requests from the local client, forwards them to the managed remote server with the access token attached, and streams the response back — the client process never sees or stores the token itself.

mcp pair

Opens a pairing window so claude.ai, Claude Desktop or another client that signs in with OAuth can connect to your deployed server. It prints the connector URL and a one-time code. Add the URL as a custom connector in the client, sign in when the client opens the approval page, and enter the code. The window lasts 10 minutes and the code is good for one approval; run mcp pair again for a new one. While no pairing window is open, the approval page refuses every request. The client then keeps its own token that renews itself, not your access token. The approval page also offers Sign in with Moodle. It opens Moodle in a browser that runs in your own Cloudflare account. Signing in there as the deployment’s Moodle account approves the client without a code and renews the deployed session at the same time. Any other Moodle account is refused.

Set up without a local browser

From a cloud sandbox or any machine without a signed-in desktop browser:
  1. Without a terminal, Cloudflare sign-in prints a dash.cloudflare.com link. Approve it in any browser; no API token is needed.
  2. The command deploys the server without a Moodle session and prints a sign-in link valid for 10 minutes.
  3. Open the link and sign in to Moodle in the remote browser. The deployment now belongs to that Moodle account.
  4. Add the printed URL as a custom connector. In the same browser the approval page already knows you; elsewhere, Sign in with Moodle does the same.
If the link expires first, run moodle mcp pair on the same machine for a new one. Until Moodle is signed in, and whenever the session expires, the connector stays connected and its tools answer with the sign-in link instead of data. Each remote sign-in uses about two minutes of browser time; the Cloudflare free plan allows ten minutes a day.

Staying signed in

Where your Moodle site turns on its mobile app service, the deployed server needs one sign-in only. Whenever it receives a session, it also asks Moodle for a mobile app key, keeps it encrypted next to the session, and uses it to open a fresh session when the old one expires. moodle mcp status shows which path your server is on: renewal: mobile_token, or sign_in when the site has the mobile service off or you are a site administrator. You can revoke the key at any time in Moodle under Preferences, then Security keys.

mcp clients and mcp revoke

clients lists pending and approved OAuth clients on your deployed server. revoke removes one client by id, or every client, token, pending authorization and pairing window at once with --all. A client that registered but was never approved expires after 10 minutes, and up to 20 clients can be approved at once.

mcp session push and mcp renewal run

session push uploads a Moodle cookie from stdin directly, an advanced path for scripting a session refresh without a browser. renewal run is what the installed background renewal job (set up during mcp deploy’s last step) actually runs: it checks the deployed session’s freshness and renews it if needed.

mcp remove

Removes one managed Moodle MCP deployment: deletes the Worker, the local renewal job, client registrations, and deployment credentials; keeps your local Moodle configuration but clears its matching authentication cache. Without --yes, it asks you to type the Worker’s name to confirm — required, since deleting the Worker can’t be undone; --yes skips the prompt. For removing everything moodle-cli has installed locally, including background jobs and configuration, see Uninstall.