rivian_login
Initiate Rivian account authentication to access vehicle data, requiring a verification code sent to your phone or email for completion.
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
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp-server.js:395-424 (registration)Tool registration for rivian_login using server.tool() with empty schema (no parameters) and async handler function that coordinates the login process.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(); 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:399-423 (handler)Handler function that retrieves RIVIAN_EMAIL and RIVIAN_PASSWORD from environment, calls rivian.createCsrfToken() and rivian.login(), saves session, and returns appropriate success or OTP prompt message.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(); 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.js:33-47 (helper)createCsrfToken() helper that makes a GraphQL mutation to obtain a CSRF token and app session token required for authentication.export async function createCsrfToken() { const data = await gql(GRAPHQL_GATEWAY, { operationName: 'CreateCSRFToken', query: `mutation CreateCSRFToken { createCsrfToken { __typename csrfToken appSessionToken } }`, variables: null, }); csrfToken = data.createCsrfToken.csrfToken; appSessionToken = data.createCsrfToken.appSessionToken; }
- lib/rivian.js:49-83 (helper)login(email, password) helper that performs the actual login via GraphQL mutation, handling both MFA (returns mfa: true with otpToken) and direct login (stores access/refresh tokens).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': csrfToken, 'A-Sess': appSessionToken }, ); if (data.login.otpToken) { otpToken = data.login.otpToken; return { mfa: true }; } accessToken = data.login.accessToken; refreshToken = data.login.refreshToken; userSessionToken = data.login.userSessionToken; return { mfa: false }; }
- mcp-server.js:44-50 (helper)saveSession() helper that persists the rivian session state to a JSON file in the user's home directory for restoration across server restarts.function saveSession() { mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 }); chmodSync(CONFIG_DIR, 0o700); const session = { ...rivian.exportSession(), savedAt: Date.now() }; writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2), { mode: 0o600 }); chmodSync(SESSION_FILE, 0o600); }