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
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
deploy runs through these steps, in order:
- Validating your Moodle session
- Checking Cloudflare access
- Preparing a Worker release
- Uploading private credentials
- Deploying the new version
- Uploading your Moodle session
- Running MCP and Moodle checks
- Installing renewal and connecting your local client
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
--verbose includes sanitized deployment diagnostics; --logs includes sanitized recent Worker logs.
mcp login
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
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:
bridgewrites 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.remotewrites 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
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
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:- Without a terminal, Cloudflare sign-in prints a
dash.cloudflare.comlink. Approve it in any browser; no API token is needed. - The command deploys the server without a Moodle session and prints a sign-in link valid for 10 minutes.
- Open the link and sign in to Moodle in the remote browser. The deployment now belongs to that Moodle account.
- 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.
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
--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.