rivian_login
Sends a verification code to your registered phone or email to initiate Rivian account login.
Instructions
Log in to your Rivian account. Rivian will send a verification code to your phone or email — use rivian_submit_otp to complete sign-in.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp-server.js:68-97 (registration)The 'rivian_login' tool is registered via server.tool() on the McpServer instance. It reads RIVIAN_EMAIL and RIVIAN_PASSWORD from env, calls rivian.createCsrfToken() then rivian.login(), and saves the session.
server.tool( 'rivian_login', 'Log in to your Rivian account. Rivian will send a verification code to your phone or email — use rivian_submit_otp to complete sign-in.', {}, async () => { const email = process.env.RIVIAN_EMAIL const password = process.env.RIVIAN_PASSWORD if (!email || !password) { return text( 'Rivian credentials are not configured. Set RIVIAN_EMAIL and RIVIAN_PASSWORD in your MCP server settings.', ) } try { await rivian.createCsrfToken() const { mfa } = await rivian.login(email, password) saveSession(rivian) if (mfa) { return text( "A verification code has been sent to your phone or email. Tell me the code and I'll complete the sign-in.", ) } return text('Signed in to Rivian successfully.') } catch (err) { return text(`Couldn't sign in: ${err.message}`) } }, ) - mcp-server.js:68-97 (handler)The async handler function that executes the rivian_login logic: checks env credentials, creates CSRF token, performs login via the Rivian API, and returns a text response indicating success or OTP requirement.
server.tool( 'rivian_login', 'Log in to your Rivian account. Rivian will send a verification code to your phone or email — use rivian_submit_otp to complete sign-in.', {}, async () => { const email = process.env.RIVIAN_EMAIL const password = process.env.RIVIAN_PASSWORD if (!email || !password) { return text( 'Rivian credentials are not configured. Set RIVIAN_EMAIL and RIVIAN_PASSWORD in your MCP server settings.', ) } try { await rivian.createCsrfToken() const { mfa } = await rivian.login(email, password) saveSession(rivian) if (mfa) { return text( "A verification code has been sent to your phone or email. Tell me the code and I'll complete the sign-in.", ) } return text('Signed in to Rivian successfully.') } catch (err) { return text(`Couldn't sign in: ${err.message}`) } }, ) - lib/rivian-api.js:51-85 (helper)The login() function called by rivian_login handler. Sends a Login GraphQL mutation, stores access/refresh tokens on success, or stores otpToken and returns {mfa: true} if MFA is needed.
export async function login(email, password) { const data = await gql( GRAPHQL_GATEWAY, { operationName: 'Login', query: `mutation Login($email: String!, $password: String!) { login(email: $email, password: $password) { __typename ... on MobileLoginResponse { __typename accessToken refreshToken userSessionToken } ... on MobileMFALoginResponse { __typename otpToken } } }`, variables: { email, password }, }, { 'Csrf-Token': session.csrfToken, 'A-Sess': session.appSessionToken }, ) if (data.login.otpToken) { session.otpToken = data.login.otpToken return { mfa: true } } session.accessToken = data.login.accessToken session.refreshToken = data.login.refreshToken session.userSessionToken = data.login.userSessionToken return { mfa: false } } - lib/rivian-api.js:35-49 (helper)The createCsrfToken() function called before login. Fetches a CSRF token and app session token needed for the subsequent login request.
export async function createCsrfToken() { const data = await gql(GRAPHQL_GATEWAY, { operationName: 'CreateCSRFToken', query: `mutation CreateCSRFToken { createCsrfToken { __typename csrfToken appSessionToken } }`, variables: null, }) session.csrfToken = data.createCsrfToken.csrfToken session.appSessionToken = data.createCsrfToken.appSessionToken } - lib/session.js:45-51 (helper)The saveSession() function called after login to persist authentication tokens to disk (~/.rivian-mcp/session.json).
export function saveSession(rivianApi) { mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 }) chmodSync(CONFIG_DIR, 0o700) const session = { ...rivianApi.exportSession(), savedAt: Date.now() } writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2), { mode: 0o600 }) chmodSync(SESSION_FILE, 0o600) }