---
title: MCP
slug: mcp
summary: Connect an AI client to LimiLake over the Model Context Protocol to query your data and call your own Functions as tools.
---

# MCP

LimiLake runs a Model Context Protocol (MCP) server. Connect an MCP client, such as a desktop chat app or a coding agent, and it can list your Lakehouses, read tables with SQL and call the Functions you publish for it. The client acts as you, with exactly your access.

The server address is:

```text
https://app.limilake.com/mcp
```

## What you get

| Tool | What it does |
|---|---|
| `list_lakehouses` | Lists every Lakehouse you can query, with its tables and their row counts, sizes and last write time |
| `describe_table` | Describes one table: column types, null share, value ranges and, for columns with few values, the exact values |
| `query_sql` | Runs read-only SQL across one or more Lakehouses. Returns 100 rows by default and at most 10,000 |
| `ask_limilake` | Answers a question asked in plain language, and returns the SQL it ran and the tables it read. Listed only when Ask LimiLake is turned on for your Tenant |
| Your Functions | Each Function published with `mcp=True` that you can reach appears as its own tool. See [Expose a Function as a tool](#expose-a-function-as-a-tool) |

`query_sql` refuses `INSERT`, `UPDATE` and `DELETE`. To let a client change data, publish a Function that does the write and expose it as a tool.

## Connect a client

You can sign in through OAuth or use a personal access token.

### Sign in with your LimiLake login

Add `https://app.limilake.com/mcp` to your client as a remote MCP server (some clients call it a connector). The client finds the LimiLake sign-in by itself: it registers, opens a LimiLake page in your browser, and you sign in and approve. The client then holds a token and renews it on its own. There is nothing to copy.

LimiLake supports the authorization code flow with PKCE, the device flow for clients without a browser, and dynamic client registration. A client that supports MCP's standard OAuth sign-in needs nothing else.

In the web app, the setup checklist on the home page shows the same address and marks the step done once a client has connected.

### Use a personal access token

If your client cannot do the OAuth sign-in, create a personal access token with the CLI. It is printed once:

```bash
limilake auth token create claude-desktop --days 90
```

A token is valid for 90 days by default and for at most 365. It belongs to the Tenant you are signed in to. Give it to the client as a bearer token in the `Authorization` header. Many clients take a JSON configuration of this shape; the exact keys depend on the client:

```json
{
  "mcpServers": {
    "limilake": {
      "url": "https://app.limilake.com/mcp",
      "headers": {
        "Authorization": "Bearer ll_pat_..."
      }
    }
  }
}
```

The server speaks streamable HTTP and holds no session state. This page gives no steps for a particular client: check your client's documentation for where a remote server and its headers go.

List and revoke your tokens with the CLI:

```bash
limilake auth token list
limilake auth token revoke <token-id>
```

A PAT is a full credential for your account. Keep it in your client's secret store, never in a file you commit.

## What a client can reach

A connected client reaches exactly the Workspaces you are a member of, at your Access Level in each, and nothing more. There are no extra scopes to choose: an OAuth sign-in and a PAT both carry your own access.

- A `viewer` Membership is enough to list Lakehouses, describe tables, run `query_sql`, use `ask_limilake` and call a Function's tool.
- Your Tenant Role adds nothing. A `tenant_admin` with no Membership in a Workspace sees nothing in it.
- Every tool call is checked live on the server. The tool list your client shows is a convenience, not the boundary: a call to a Function you can no longer reach is refused.

## Expose a Function as a tool

Add `mcp=True` to a Function and push it to `main`. This example gives a client a typed lookup tool:

```python
import limilake
from pydantic import BaseModel, Field

fn = limilake.function(
    id="123e4567-e89b-42d3-a456-426614174004",  # keep the id the CLI generated
    name="invoice-lookup",
    description="Look up the open invoices of one customer by customer number.",
    mcp=True,
)


class InvoiceQuery(BaseModel):
    customer_number: str = Field(pattern=r"^[0-9]{1,10}$")
    limit: int = Field(default=20, ge=1, le=200)


@fn.post("/invoices")
def open_invoices(query: InvoiceQuery) -> dict[str, object]:
    rows = limilake.lake.query(
        "select invoice_number, amount, due_date from silver.invoices "
        f"where customer_number = '{query.customer_number}' and status = 'open' "
        "order by due_date",
        limit=query.limit,
    )
    return {"invoices": rows}
```

The pattern on `customer_number` allows only digits, so the value is safe to place in the SQL.

The rules for an `mcp=True` Function:

- **Access.** It must use `access="private"`, the default. Any other access makes the push fail with [`function_declaration_invalid`](./push-rejections.md#function_declaration_invalid). It may run as the caller (the default) or as an assigned identity.
- **HTTP routes.** Every HTTP route must be a POST with exactly one parameter: a Pydantic model or a `dict[str, T]`. A GET, PUT, PATCH or DELETE route, or a POST with no parameter, several parameters, or a scalar or list parameter, makes the push fail with [`function_mcp_method_unsupported`](./push-rejections.md#function_mcp_method_unsupported). The SDK refuses such a route as soon as the module is imported.
- **Actions and syncs.** A Function with `@fn.action` or `@fn.sync` and `mcp=True` also becomes one tool. Its arguments are the run input object, which the client fills in without a field list, so prefer a POST route with a model when you want the client to see named, typed arguments.
- **`mcp=` is a literal** `True` or `False` in the call.

What the tool looks like to the client:

- **Name.** The Function's `name=`, in lowercase with every run of other characters replaced by `_`: `invoice-lookup` becomes `invoice_lookup`. A Function with several POST routes gives one tool per route, named `<name>_<route>`, for example `invoice_lookup_invoices`. If two Functions you can reach produce the same name, or a name equals a built-in tool, LimiLake adds a suffix that tells them apart.
- **Description.** Your `description=`, followed by the route (`Route: POST /invoices.`). Write it for the model: say what the tool does and when to use it.
- **Arguments.** The fields of the body model, with their types, defaults and constraints. A client never chooses the path or the method.

To check that it is published, list your Functions and look for `mcp` among its surfaces:

```bash
git push origin HEAD:main
limilake function list
```

The tool reaches a connected client within about a minute of the push. A client that does not refresh its tool list on its own may need you to reconnect or reload it.

### Calling a Function tool

A call runs the Function with your own access, like any private Function call. A route call waits up to 120 seconds, or the Function's `timeout=` when that is shorter. An action or sync call waits up to 180 seconds. A client that supports MCP tasks gets a task after 15 seconds instead and fetches the result when the run ends. When a wait runs out, the client gets an error, and the run may still finish on the server.

## When access changes or a token expires

- **Your Membership changes.** Calls are checked live, so a removed Membership blocks the next call. The tool list catches up within about a minute.
- **A Function is published, removed or changes access.** The tool list follows within about a minute.
- **An OAuth token expires.** The server answers `401` with `invalid_token`, and the client renews the token by itself. When renewal fails, for example because the 30-day sign-in has expired or you changed your password, the client asks you to sign in again.
- **A PAT expires or is revoked.** Every request answers `401`. Create a new token and update the client.

## Troubleshooting

| What you see | What it means |
|---|---|
| `401` on every request | No `Authorization` header, or the token is expired, revoked or not valid. Sign in again or create a new PAT |
| Your Function is not in the tool list | It lacks `mcp=True`, is not on `main` yet, uses an `access` other than `private`, or is in a Workspace you are not a member of. Wait a minute after the push, then reconnect |
| `ask_limilake` is missing | Ask LimiLake is not turned on for your Tenant |
| `CATALOG_UNAVAILABLE` from a Function tool | LimiLake could not read your Function list for a moment. Try again |
| `INVALID_PARAMS` naming a tool | The client is holding a tool name that no longer exists. Reload the tool list |
| `... exceeded the 120s invoke limit` | The Function took longer than the call can wait. It may still finish; make it faster or move the work to a run |
| A tool call result says `403` or `404` | You can no longer reach that Workspace, Lakehouse or Function |

## Next steps

- [Functions](./functions.md): write and publish the Functions you expose as tools.
- [Lakehouses and SQL](./querying-data.md): Lakehouses, schemas and SQL.
- [Agents](./agents.md): run an agent from your own code inside LimiLake.
