Skip to main content
Glama

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
NameRequiredDescriptionDefault

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}`);
        }
      },
    );
  • 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}`);
      }
    },
  • 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;
    }
  • 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 };
    }
  • 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);
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PatrickHeneise/rivian-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server