Tesla Fleet API MCP server

Integrates with the Tesla Fleet API to enable vehicle monitoring and control through OAuth 2.0 authentication, allowing for wake-up commands, information retrieval, and real-time data refreshing of Tesla vehicles.
Back to servers
Provider
scald
Release date
Mar 08, 2025
Language
TypeScript
Stats
6 stars

The Tesla MCP Server allows you to control your Tesla vehicle using Claude and other AI assistants that support the Model Context Protocol (MCP). It connects to the Tesla Fleet API to provide a bridge between your AI assistant and your Tesla vehicle's systems.

Requirements

  • Node.js 18+
  • pnpm (preferred) or npm
  • Tesla account with at least one vehicle
  • Tesla API credentials (Client ID and Client Secret)
  • Ngrok (for development and registration)

Installation

1. Clone the repository

git clone https://github.com/yourusername/tesla-mcp.git
cd tesla-mcp

2. Install dependencies

pnpm install

3. Set up environment variables

Create a .env file in the root directory:

TESLA_CLIENT_ID=your_client_id
TESLA_CLIENT_SECRET=your_client_secret
TESLA_REFRESH_TOKEN=your_refresh_token

4. Get a refresh token (if needed)

pnpm get-token

5. Register your application with Tesla's API

pnpm register

Follow the instructions provided by the script.

6. Build the server

pnpm build

7. Run the server

pnpm start

Authentication Setup

The Tesla MCP Server uses Tesla's Fleet API OAuth 2.0 authentication flow to connect to your Tesla account.

Getting Authentication Credentials

  1. Obtain a Client ID and Client Secret from the Tesla Developer Portal
  2. Run the provided utility to get a refresh token:
    pnpm get-token
    
    This will:
    • Open a browser for you to log in with your Tesla credentials
    • Perform the OAuth flow
    • Store the refresh token in your .env file

Setting Up Ngrok (Required for Registration)

  1. Install ngrok from ngrok.com/download
  2. Create a free account at ngrok.com
  3. Get your auth token from the ngrok dashboard
  4. Authenticate ngrok:
    ngrok authtoken YOUR_AUTH_TOKEN
    

Configuring Claude to Use the MCP Server

  1. Create the Claude configuration directory:

    mkdir -p ~/Library/Application\ Support/Claude
    
  2. Create or edit the configuration file:

    nano ~/Library/Application\ Support/Claude/claude_desktop_config.json
    
  3. Add the following configuration (adjust the path as needed):

    {
      "mcpServers": {
        "tesla-mcp-server": {
          "command": "/absolute/path/to/tesla-mcp/run-mcp.js"
        }
      }
    }
    
  4. Make the run-mcp.js script executable:

    chmod +x run-mcp.js
    
  5. Restart Claude completely

Available MCP Tools

The server provides the following tools that Claude can use:

wake_up

Wakes up a Tesla vehicle from sleep mode.

  • Takes vehicle_id as a required parameter
  • Returns the current state of the vehicle

refresh_vehicles

Refreshes the list of Tesla vehicles.

  • No parameters required
  • Updates the internal cache of vehicles

debug_vehicles

Shows detailed information about available vehicles.

  • No parameters required
  • Returns ID, vehicle_id, VIN, and state information

Using the MCP Server with Claude

Once configured, you can ask Claude:

  • "What Tesla vehicles do I have?"
  • "Can you wake up my Tesla?"
  • "Show me debug information about my Tesla vehicles"

Troubleshooting

Environment Variables Issues

  • Ensure your .env file contains valid credentials
  • Run pnpm get-token to refresh your token if needed

Server Connection Problems

  • Check that the server is running (pnpm start)
  • Verify Claude's configuration points to the correct file path

Vehicle Connectivity Issues

  • Vehicle might be offline or asleep
  • Try waking up the vehicle first with the wake_up command

Using Debug Mode

  • Use the debug_vehicles command to get detailed information
  • Check the server logs in the terminal where you're running the MCP server

Helpful Command Line Tools

  • pnpm build: Compile the TypeScript code
  • pnpm start: Run the server using the run-mcp.js script
  • pnpm register: Register your app with Tesla's API
  • pnpm get-token: Get a refresh token from Tesla
  • pnpm test-api: Test your connection to the Tesla API
  • pnpm inspector: Run the server with the MCP Inspector for debugging

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later