rivian_get_charging_session
Monitor active charging sessions to track power usage, battery level, time remaining, and cost for your Rivian vehicle.
Instructions
Check on an active charging session — power, battery level, time remaining, and cost.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| vehicle_id | Yes | Vehicle ID from your account info |
Implementation Reference
- lib/rivian.js:193-222 (handler)The core implementation of getLiveChargingSession that executes a GraphQL query to the Rivian charging API, retrieving live charging session data including power, battery level, time remaining, cost, and other charging metrics.export async function getLiveChargingSession(vehicleId) { const body = { operationName: 'getLiveSessionData', query: `query getLiveSessionData($vehicleId: ID!) { getLiveSessionData(vehicleId: $vehicleId) { __typename chargerId current { __typename value updatedAt } currentCurrency currentMiles { __typename value updatedAt } currentPrice isFreeSession isRivianCharger kilometersChargedPerHour { __typename value updatedAt } locationId power { __typename value updatedAt } rangeAddedThisSession { __typename value updatedAt } soc { __typename value updatedAt } startTime timeElapsed timeRemaining { __typename value updatedAt } totalChargedEnergy { __typename value updatedAt } vehicleChargerState { __typename value updatedAt } } }`, variables: { vehicleId }, }; return (await gql(GRAPHQL_CHARGING, body, chargingHeaders())).getLiveSessionData; }
- mcp-server.js:505-519 (registration)The MCP server tool registration for 'rivian_get_charging_session', defining the tool schema (accepts vehicle_id parameter) and the handler function that authenticates, calls getLiveChargingSession, and formats the response.server.tool( 'rivian_get_charging_session', 'Check on an active charging session — power, battery level, time remaining, and cost.', { vehicle_id: z.string().describe('Vehicle ID from your account info'), }, async ({ vehicle_id }) => { try { requireAuth(); return text(formatChargingSession(await rivian.getLiveChargingSession(vehicle_id))); } catch (err) { return text(err.message); } }, );
- mcp-server.js:317-345 (helper)The formatChargingSession helper function that formats the raw charging session data from the API into a human-readable text format with battery level, power, range added, energy charged, time, cost, and charger state.function formatChargingSession(data) { if (!data) return 'No active charging session.'; const lines = ['Charging Session']; const add = (label, entry, suffix = '') => { const value = entry?.value; if (value !== undefined && value !== null) lines.push(` ${label}: ${value}${suffix}`); }; add('Battery', data.soc, '%'); add('Power', data.power, ' kW'); add('Range added', data.rangeAddedThisSession, ' miles'); add('Energy charged', data.totalChargedEnergy, ' kWh'); add('Current', data.current, ' A'); if (data.timeElapsed) lines.push(` Time elapsed: ${data.timeElapsed}`); add('Time remaining', data.timeRemaining, ' min'); if (data.isRivianCharger) lines.push(' Network: Rivian Adventure Network'); if (data.isFreeSession) { lines.push(' Cost: Free'); } else if (data.currentPrice) { lines.push(` Cost so far: ${data.currentCurrency || '$'}${data.currentPrice}`); } add('Charger state', data.vehicleChargerState); return lines.join('\n'); }
- lib/rivian.js:280-282 (helper)The chargingHeaders helper function that provides the authentication headers required for API calls to the Rivian charging GraphQL endpoint.function chargingHeaders() { return { 'U-Sess': userSessionToken }; }