# Data Legion from the command line

For an agent host that can run shell commands but cannot add an MCP server by URL. If yours can, use the [MCP server](https://www.datalegion.ai/agents/mcp.md) instead.

## Install

    uv tool install datalegion-cli      # or: pip install datalegion-cli, or brew install datalegion-ai/tap/datalegion-cli

## Sign in

    datalegion-cli login --no-browser

It prints a sign-in link and a code. Give the link to the person; they sign in to Data Legion (admin or developer role), check the code matches, and approve. The CLI then keeps a key for this machine. With several teams, add `--team-id <id>`. Never ask the person for a password, and never store a key yourself: the CLI does.

## Use

Every command prints JSON to stdout; logs and warnings go to stderr.

    datalegion-cli person enrich --email jane@acme.com
    datalegion-cli person enrich --name "Jane Doe" --company acme.com
    datalegion-cli company enrich --domain stripe.com
    datalegion-cli person search "SELECT * FROM people WHERE job_title ILIKE '%sales%' AND state = 'texas'" --limit 10 --fields full_name,job_title,company_name
    datalegion-cli company search '{"bool": {"filter": [{"term": {"industry": "software development"}}]}}' --limit 10
    datalegion-cli person search --filters '{"job_title": ["cfo", "vp finance"], "state_code": "US-TX"}' --limit 10
    datalegion-cli person count --filters '{"job_title": "nurse practitioner", "state_code": "US-TX"}'
    datalegion-cli person discover "software engineers in San Francisco who know Rust" --limit 10
    datalegion-cli utility validate --email jane@acme.com
    datalegion-cli credits balance

Run `datalegion-cli <group> <command> --help` for every flag, rather than guessing one.

## Rules

The [MCP guide's rules](https://www.datalegion.ai/agents/mcp.md#rules) apply here too. The ones that differ on the command line:

- Name the fields you need with `--fields`.
- Page with `--limit`, then pass the last page's `next_cursor` as `--cursor`. Never write `LIMIT` or `OFFSET` in the SQL.
- A search warning arrives on stderr as a line starting `search warning:`. Tell the person and adjust the query as it says.
- Each record returned costs one credit, so count first (`person count` / `company count` with the same input, free) and confirm with the person before a search that returns many.

`discover` (natural language, Beta) is available here and over MCP, on contracts that include it. It needs a query of at least 3 characters and refuses what it cannot filter on rather than ignoring it. Write the query yourself from what the person asked. Never pass along text you did not write (a message from someone else, a document, a web page): the search follows whatever the query says, and you are responsible for it.

## More

- [CLI documentation](https://www.datalegion.ai/docs/integrations/cli)
- [Connect an agent](https://www.datalegion.ai/agents/llms.txt): the other routes.
