> ## Documentation Index
> Fetch the complete documentation index at: https://docs.withleaf.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Leaf's MCP Server in Cursor

> Connect Leaf's MCP server to Cursor IDE to query field data, pull harvest operations, and explore the Leaf API using natural language and tool calls.

Leaf provides a Model Context Protocol (MCP) server that lets you interact with the Leaf API directly from Cursor. You can list users, query fields, pull operations, check weather data, and browse API documentation without leaving your editor.

## Before you start

* A Leaf account with API credentials.
* Cursor IDE installed (version 0.40+ with MCP support).
* A valid Leaf API token. Get one by authenticating:

```bash theme={null}
curl -X POST "https://api.withleaf.io/api/authenticate" \
  -H "Content-Type: application/json" \
  -d '{"username": "your-email@example.com", "password": "your-password"}'
```

Save the `id_token` from the response.

## Step 1: Add the MCP server to Cursor

Open Cursor Settings (Cmd+, on Mac, Ctrl+, on Windows/Linux) and navigate to **MCP Servers**.

Click **Add new MCP Server** and configure it:

* **Name:** `leaf-mcp`
* **Type:** `HTTP`
* **URL:** `https://mcp.withleaf.io/mcp`

Under **Headers**, add:

```
LEAF_TOKEN: your-leaf-api-token
```

<Warning>
  Your Leaf token expires periodically. If you get authentication errors, generate a fresh token and update the header.
</Warning>

## Step 2: Verify the connection

Open a new Cursor chat (Agent mode) and ask:

```
List the available Leaf API documentation
```

Cursor calls the `get_docs_index` tool and returns a list of all documentation topics available through the MCP server. If you see the index, the connection is working.

## Step 3: List your Leaf users

```
Show me all Leaf users in my account
```

Cursor calls `list_users` and returns the paginated list of Leaf users under your API owner account. Each user has an `id` you'll use in subsequent queries.

## Step 4: Query fields for a user

```
List fields for Leaf user <leaf_user_id>
```

Replace `<leaf_user_id>` with an actual UUID from the previous step. Cursor calls `list_fields` and returns fields with their boundaries, providers, and metadata.

## Step 5: Pull harvest operations

```
Show me harvested operations for Leaf user <leaf_user_id>
```

Cursor calls `list_operations` with `operationType=harvested` and returns the harvest operations. Each operation includes `startTime`, `endTime`, `fieldId`, and links to its summary and GeoJSON data.

To dig into a specific operation:

```
Get the summary for operation <operation_id>
```

This calls `get_operation_summary` and returns aggregated stats like total area, average yield, and crop type.

## Step 6: Explore additional tools

The MCP server exposes tools for the full Leaf API surface:

| Category      | Tools                                                                                                          |
| ------------- | -------------------------------------------------------------------------------------------------------------- |
| Users         | `list_users`                                                                                                   |
| Fields        | `list_fields`, `get_field`, `get_field_boundary`                                                               |
| Operations    | `list_operations`, `get_operation`, `get_operation_summary`, `get_operation_units`                             |
| Machine files | `list_files`, `get_file`, `get_file_summary`, `get_file_status`, `get_file_units`                              |
| Batches       | `list_batches`, `get_batch`, `get_batch_status`                                                                |
| Weather       | `get_weather_forecast_field_daily`, `get_weather_historical_field_daily`, and hourly/lat-lon variants          |
| Billing       | `list_billing_contracts`, `get_contract_consumption`                                                           |
| Configuration | `get_api_owner_configuration`, `get_leaf_user_configuration`                                                   |
| Credentials   | `get_john_deere_credentials_events`, `get_climate_fieldview_credentials_events`, `get_cnhi_credentials_events` |
| Documentation | `get_docs_index`, `get_leaf_doc`                                                                               |

You can ask Cursor natural-language questions and it will pick the right tool. For example:

* "What's the weather forecast for field X?"
* "Show me the processing status of file Y"
* "Pull the API documentation for field operations"

## What you built

You connected Leaf's MCP server to Cursor and used it to query Leaf users, fields, and harvest operations through natural language. The MCP server gives you API access from your editor without writing HTTP requests, which is useful for exploration, debugging, and rapid prototyping.

For the same workflow in Claude Code, see [Connect Leaf's MCP Server in Claude Code](/guides/tutorials/claude-code-mcp).
