# LlamaIndex + Dizo

> Load the Dizo MCP tools into a LlamaIndex FunctionAgent with BasicMCPClient and McpToolSpec, and pick exactly which tools it can call.

Type: MCP client — server URL `https://mcp.dizo.ai/mcp`. No native app needed.

## Steps
1. `pip install llama-index-tools-mcp llama-index-llms-openai` and export `DIZO_API_KEY`.
2. Create a `BasicMCPClient` with the Dizo URL and an `Authorization` header.
3. Wrap it in `McpToolSpec`, optionally with `allowed_tools`, and call `to_tool_list_async()`.
4. Pass the tools to a `FunctionAgent` and `await agent.run(...)`.

## Where to go
`BasicMCPClient` (HTTP URL, headers) and `McpToolSpec`.

Open the LlamaIndex MCP reference: https://developers.llamaindex.ai/python/framework-api-reference/tools/mcp/

## agent.py
```
import asyncio, os
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

async def main():
    client = BasicMCPClient(
        "https://mcp.dizo.ai/mcp",
        headers={"Authorization": f"Bearer {os.environ['DIZO_API_KEY']}"},
    )
    spec = McpToolSpec(
        client=client,
        allowed_tools=["dizo_count", "dizo_search", "dizo_find_email", "dizo_quote"],
    )
    tools = await spec.to_tool_list_async()

    agent = FunctionAgent(
        tools=tools,
        llm=OpenAI(model="gpt-5-mini"),
        system_prompt="Count first. Quote with dizo_quote before any job over 100 credits.",
    )
    print(await agent.run("Find 20 data engineering leads at US healthtech companies with emails"))

asyncio.run(main())
```

## Notes
- `allowed_tools` is the simplest guardrail: an agent that never sees `dizo_find_phone` can never spend 10 credits on a number.
- Any LLM that LlamaIndex supports works; only the `llm=` line changes.
- Use a `dz_test_` key in notebooks and CI. It returns synthetic data and never spends credits.

## Related API docs
- [/docs/search](https://dizo.ai/docs/search.md)
- [/docs/count](https://dizo.ai/docs/count.md)
- [/docs/email-find](https://dizo.ai/docs/email-find.md)


## What LlamaIndex is

LlamaIndex is an open-source framework for building applications that combine language models with your own data. It started with retrieval: loading documents, indexing them and querying them with a model. It now covers agents and workflows too, so the same project can hold a vector index over your sales playbook and an agent that decides which tools to call to answer a question.

For Dizo, the relevant package is `llama-index-tools-mcp`. It provides `BasicMCPClient`, which connects to an MCP server over a URL or a local command, and `McpToolSpec`, which turns that server's tools into LlamaIndex `FunctionTool` objects. Those tools behave like any other tool you hand to a `FunctionAgent` or use inside a workflow step, so nothing about your agent's structure has to change to add Dizo.

## Why give a LlamaIndex agent Dizo tools

Retrieval answers questions about documents you already have. Go-to-market work usually needs data you do not have yet: who the head of data is at a target account, what their current work email is, how many companies fit a segment. Dizo supplies that through a hosted [MCP server](/mcp) with 850M professional profiles, 100M+ websites and companies, 800M verified emails and 550M mobiles and direct dials.

The two fit together well. A LlamaIndex agent can read your ideal customer profile and past win notes from an index, then call Dizo to find accounts and people that match. Because each Dizo tool description includes its credit cost, the model can weigh a free count against a paid search, and you can see cost in the trace when you debug a run. Lookups that find nothing are free, so retries on bad inputs do not quietly add up.

## What you can build

These tasks map directly onto Dizo tools and make good first agents or workflow steps:

- Segment sizing: `dizo_count` answers 'how many directors of IT at US hospitals with 500+ staff' for free. To split a segment, run one count per state or seniority; each is still free.
- ICP-driven prospecting: retrieve your ICP from an index, then call `dizo_search` with a plain-English query built from it.
- Contact completion: `dizo_find_email` on each person, 1 credit only when a validated address comes back; a miss is a free `404 not_found`.
- Account briefs: `dizo_enrich_company` plus `dizo_org_chart` for a domain, summarised against your own notes.
- Buying committee mapping: `dizo_best_contact` with a ranked list of titles across many domains.
- Inbound enrichment: `dizo_email_to_profile` on new sign-ups, 2 credits per match.
- Budget checks: `dizo_quote` and `dizo_balance` before a long run.

## Setup walkthrough

Install the MCP tools package and an LLM integration: `pip install llama-index-tools-mcp llama-index-llms-openai`. The example uses OpenAI, but any LLM class that LlamaIndex supports can drive a `FunctionAgent`; the Dizo side stays the same. Export your key as `DIZO_API_KEY` so it never appears in code or notebooks.

Create the client with `BasicMCPClient("https://mcp.dizo.ai/mcp", headers={...})`. The constructor takes the URL as its first argument and accepts a `headers` dict, which is where the `Authorization: Bearer` value goes. It also accepts an `auth` parameter for an OAuth client provider if you would rather run an OAuth flow, plus `timeout` settings for slow networks.

Wrap the client in `McpToolSpec` and call `await spec.to_tool_list_async()`. The example passes `allowed_tools` to load only four tools. Leave it out to load every Dizo tool. Then create a `FunctionAgent` with the tools, an LLM and a system prompt, and `await agent.run(...)`. Because the client is async, run it inside `asyncio.run` or a notebook that supports top-level await; the synchronous `to_tool_list()` raises an error if an event loop is already running.

[Sign up](/signup) for a live `dz_live_` key. Work email signups get 250 free credits. A `dz_test_` key works today with synthetic data.

## Controlling spend

LlamaIndex gives you a guardrail before Dizo even sees a request: `allowed_tools`. If a research agent should never buy phone numbers, leave `dizo_find_phone` out of the list and the model cannot call it. Pair that with a Dizo key whose endpoint allow-list matches, and the restriction holds at both ends.

On the Dizo side, each key can carry a maximum credits per request, a daily cap and a monthly cap, and the account has a monthly USD ceiling that returns `402 monthly_cap_reached` once hit. Alerts fire at 50%, 80% and 100%. The REST endpoints also accept `max_credits` and `dry_run` on every billable call, and over MCP the `dizo_quote` tool gives the same exact quote without spending anything.

Put the spending rule in the system prompt too, as the example does: count first, then quote any job over 100 credits. The model sees tool costs; your prompt decides when it stops to ask. Credit prices by tier are on [pricing](/pricing).

## Example workflows

**ICP to shortlist.** A workflow step retrieves your ICP document, a second step asks the agent to turn it into a Dizo query, and a third calls `dizo_count`. If the count is reasonable, the agent pulls 100 people with `dizo_search`, which costs 4 credits, then finds emails. If 70 are found, the run costs 74 credits, or $1.85 at $0.025 a credit and $0.74 at the $0.010 enterprise rate.

**Account brief with your own context.** Give the agent a domain. It calls `dizo_enrich_company` for firmographics (1 credit if matched), pulls 25 people from `dizo_org_chart` filtered to finance and operations (1 credit), and queries your index of past deals in the same industry. The brief costs about 2 credits and combines public firmographics with your private notes.

**Nightly enrichment.** For anything over about 50 lookups, skip the agent loop and call the REST [batch endpoint](/docs/batch) from a scheduled job, then load the results into a LlamaIndex index for the agent to query. Batch takes up to 10,000 items per job, charges the same per item, and misses stay free.

## MCP tools or REST calls: which to use where

Inside an agent, prefer the MCP tools. The tool schemas, names and cost descriptions come from Dizo's server at load time, so when an endpoint gains a parameter your agent sees it without a code change. Hand-writing a `FunctionTool` around each REST endpoint works, but you then own the schema, the docstring the model reads and the error handling, and they drift.

Outside the agent, plain REST is often the better call. Scheduled enrichment, bulk email finding and list exports are deterministic jobs with no reasoning step, so there is nothing for a model to decide. Call `https://api.dizo.ai/v1` directly with an `Idempotency-Key` header on every POST so retries within 24 hours are never charged twice, and read the `x-dizo-credits-used` header on each response to log cost.

A common split is a nightly REST job that keeps an index fresh, and a LlamaIndex agent that queries that index first and only calls Dizo tools for gaps. The agent then spends credits on new questions, not on records you already paid for. Add your customers and open opportunities to the free [suppression list](/docs/suppression) so neither path pays for contacts you already have.

## Troubleshooting

If `to_tool_list_async()` returns an empty list or raises, check the URL is exactly `https://mcp.dizo.ai/mcp` and that the header value starts with `Bearer `. A 401 means the key is missing, revoked or mistyped. If you passed `allowed_tools`, make sure the names match the Dizo tool names exactly, such as `dizo_search` rather than `search`.

If you see 'event loop is already running', you called the synchronous `to_tool_list()` inside a notebook or async app; switch to the async method. If a tool call returns `402`, a cap was reached: per request, per key or for the account. The error body includes a `fix` field in plain English, and `dizo_whoami` shows remaining budget.

Rate limits apply per key. If an agent fans out many calls at once, slow it down, or move bulk work to batch. Counts are free but limited to five requests per second per key.

## Security practices

Read the key from the environment or a secrets manager, never from a notebook cell that might be shared or committed. Give each agent its own key, scoped to the endpoints it uses, with a daily cap sized to its job. When you retire an agent, revoke its key.

Keep test and live separate. Use `dz_test_` in development, evaluation runs and CI so that synthetic data flows through your pipeline and no credits move. Only production gets a live key. If your agent stores results in an index, treat that index like CRM data: Dizo honours opt-outs within 24 hours, and the [trust page](/trust) explains how data is handled.

## FAQ

### Which LlamaIndex package do I need for Dizo?
`llama-index-tools-mcp`, which provides `BasicMCPClient` and `McpToolSpec`. Add an LLM integration such as `llama-index-llms-openai` for the agent itself.

### How do I pass my Dizo key to BasicMCPClient?
Pass a `headers` dict with `Authorization: Bearer` followed by your key. Read the key from an environment variable rather than writing it into code.

### Can I limit which Dizo tools the agent sees?
Yes. `McpToolSpec` takes an `allowed_tools` list. Only the named tools are converted, so the agent cannot call anything else. Match it with an endpoint allow-list on the Dizo key.

### Does this work in LlamaIndex workflows, not just FunctionAgent?
The tools are ordinary LlamaIndex `FunctionTool` objects, so you can use them in workflow steps or other agent types as well. The example uses `FunctionAgent` because it is the shortest path.

### What happens when a lookup finds nothing?
It is free. Email, phone and profile lookups charge only when data is found, and searches charge only for results returned, at 1 credit per 25.

### Is there a native Dizo reader or tool spec on LlamaHub?
No. Dizo connects through its MCP server, which `McpToolSpec` reads directly. There is no separate Dizo package to install.
