# Haystack + Dizo

> Add Dizo to a Haystack Agent or pipeline with MCPToolset and StreamableHttpServerInfo, with the key held as a Secret.

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

## Steps
1. `pip install mcp-haystack` and export `DIZO_API_KEY`.
2. Create `StreamableHttpServerInfo` with the Dizo URL and `token=Secret.from_env_var("DIZO_API_KEY")`.
3. Wrap it in `MCPToolset` with a `tool_names` list.
4. Pass the toolset to a Haystack `Agent` (it warms up the tools) and run it with a `ChatMessage`.

## Where to go
`MCPTool` / `MCPToolset` with `StreamableHttpServerInfo`.

Open the Haystack MCP docs: https://docs.haystack.deepset.ai/docs/mcptool

## agent.py
```
from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret
from haystack_integrations.tools.mcp import MCPToolset, StreamableHttpServerInfo

dizo = MCPToolset(
    server_info=StreamableHttpServerInfo(
        url="https://mcp.dizo.ai/mcp",
        token=Secret.from_env_var("DIZO_API_KEY"),  # sent as Authorization: Bearer
    ),
    tool_names=["dizo_enrich_company", "dizo_org_chart", "dizo_quote", "dizo_whoami"],
)

agent = Agent(chat_generator=OpenAIChatGenerator(), tools=dizo, exit_conditions=["text"])
res = agent.run(messages=[ChatMessage.from_user("Profile ledgerline.io and list its finance leaders.")])
print(res["messages"][-1].text)
```

## Notes
- Always set `tool_names`. Loading every tool from a server can crowd the model's context.
- `token` builds the `Authorization: Bearer` header for you. If you also pass `headers`, those take precedence.

## Related API docs
- [/docs/company-enrich](https://dizo.ai/docs/company-enrich.md)
- [/docs/org-chart](https://dizo.ai/docs/org-chart.md)
- [/docs/me](https://dizo.ai/docs/me.md)


## Haystack in brief, and where Dizo fits

Haystack is deepset's open-source Python framework for building LLM applications out of components: retrievers, generators, converters, routers and agents, wired together into pipelines. It is widely used for retrieval-augmented generation, and its `Agent` component adds tool calling on top of a chat generator, so an LLM can decide when to call a tool and loop until it has an answer.

Tools from MCP servers come in through the `mcp-haystack` integration. Its `MCPToolset` connects to a server described by a server-info object; for remote servers over streamable HTTP, that object is `StreamableHttpServerInfo`. Point it at `https://mcp.dizo.ai/mcp` with your key, and a Haystack Agent can call Dizo tools for company enrichment, org charts, people search and verified emails, inside the same pipeline that handles your documents and retrieval.

## Why connect a Haystack pipeline to Dizo

Haystack applications often answer questions from your own knowledge: support tickets, call notes, product docs. Many GTM questions need outside facts as well, such as who leads finance at an account, how large the company is, or which technologies it uses. Without a data tool, the model either refuses or invents an answer. With Dizo, the agent can look up the account and its people and combine that with what your documents say.

Dizo's pricing suits pipeline work because it is predictable per call. Every tool description carries its credit cost, `dizo_quote` returns an exact quote for free, lookups that find nothing cost nothing and searches charge only for results returned. A pipeline that enriches every new account in a nightly job therefore has a cost you can estimate in advance. The tool list and prices are on the [MCP server page](/mcp).

## What a Haystack agent can do with Dizo

Examples that combine Dizo with typical Haystack work:

- Answer "Tell me about ledgerline.io" by calling `dizo_enrich_company` and merging the profile with your own call notes from a retriever.
- Prepare a meeting brief: enrich the company, then list finance leaders with `dizo_org_chart`.
- Route an inbound lead: resolve the sender with `dizo_email_to_profile` and pass seniority to a router component.
- Build a short target list with `dizo_company_search` from a natural-language description in a chat app.
- Find a verified work email for a named contact with `dizo_find_email` before a writer component drafts outreach.
- Report remaining budget with `dizo_whoami`, which is free.

## Setting up MCPToolset step by step

Install the integration with `pip install mcp-haystack` and export `DIZO_API_KEY`. While developing, use a `dz_test_` key: it returns synthetic data and never spends credits, so you can test pipeline wiring without a balance.

Create the server info: `StreamableHttpServerInfo(url="https://mcp.dizo.ai/mcp", token=Secret.from_env_var("DIZO_API_KEY"))`. Haystack's reference says `token` generates an `Authorization: Bearer` header, which is exactly what Dizo expects, and `Secret.from_env_var` means the key is resolved at runtime rather than stored in your pipeline definition. There is also a `headers` parameter for custom headers; if you set both, `headers` takes precedence. A `timeout` parameter sets the connection timeout in seconds.

Wrap it in `MCPToolset(server_info=..., tool_names=[...])` and pass the toolset to `Agent(chat_generator=OpenAIChatGenerator(), tools=dizo, exit_conditions=["text"])`. Run the agent with `agent.run(messages=[ChatMessage.from_user(...)])` and read the last message. The Agent warms up the toolset automatically. If you use the toolset directly with a chat generator instead, call `warm_up_tools(toolset)` first.

## Choosing tool_names and connection timing

Haystack's docs warn that loading every tool from a server can overwhelm the model, and Dizo exposes more than twenty tools. Set `tool_names` to the handful a given agent needs. A meeting-prep agent might need only `dizo_enrich_company`, `dizo_org_chart`, `dizo_quote` and `dizo_whoami`. A lead-routing agent might need only `dizo_email_to_profile`. Smaller tool lists make tool choice more reliable and make the agent's behaviour easier to review.

`MCPToolset` also takes `eager_connect`, which defaults to `False`. With the default, the toolset connects during warm-up rather than at construction, which keeps pipeline definitions cheap to build and serialize. Set it to `True` if you want a missing key or a network problem to fail immediately when the pipeline is created. There are also `connection_timeout` and `invocation_timeout` settings for tuning slow calls.

## Combining Dizo lookups with your own retrieval

The strongest Haystack use of Dizo is not replacing your documents but complementing them. A typical pattern is a pipeline where a retriever pulls internal context, such as past call notes or open support tickets for an account, and the Agent decides whether it also needs outside facts. If the notes already name the champion and their email, the agent has no reason to spend credits. If the notes are thin or old, it calls `dizo_enrich_company` or `dizo_org_chart` to fill the gaps.

Make that decision explicit in the prompt. Tell the agent to check retrieved context first and to call Dizo only for fields that are missing or that the notes flag as outdated. This keeps cost tied to genuine gaps rather than to every question asked. It also makes answers easier to trust, because the agent can say which facts came from your records and which came from a fresh lookup.

When Dizo returns something that turns out to be wrong, such as an email that bounces, report it with `dizo_report_bad_data`. Confirmed reports are credited back automatically, and the correction improves what your pipeline gets next time. Field definitions for every record type are in the [data fields reference](/data/fields).

## Controlling spend

Tell the agent its rules in the system or user message: call `dizo_whoami` once at the start, call `dizo_quote` before any job likely to exceed about 100 credits, and stop on a 402. Those instructions guide the model; the enforceable limits live on the key and the account.

Create a dedicated key with `data:read` scope, `max_credits_per_request`, daily and monthly caps and an endpoint allow-list that mirrors your `tool_names`. MCP connections default to `data:read` and a 500-credit per-call limit unless changed in the console. The account's monthly spend cap in USD stops all calls with `402 monthly_cap_reached`, and alerts at 50%, 80% and 100% of any cap go to email and webhook. The [keys reference](/docs/keys) lists every field.

## Worked examples with costs

Nightly account enrichment. A pipeline runs over 1,000 new account domains a month and calls `dizo_enrich_company` for each, at 1 credit if matched. Assume 900 are matched; the 100 unmatched cost nothing. The month is 900 credits: $22.50 at the $0.025 pay-as-you-go rate, or $18.90 at $0.021 if credits come from a $500 to $1,999 purchase. For a job this regular, `dizo_batch` can run the lookups as one asynchronous job at the same per-item price.

Meeting prep on demand. A rep asks the agent to brief them on one account before a call. It enriches the company for 1 credit, pulls finance and RevOps from the org chart, assume 40 people at 1 credit per 25 for 1.6 credits, and finds emails for three of them, assume all found, for 3 credits. That is 5.6 credits, about $0.14 at $0.025. Twenty briefs a month is 112 credits, about $2.80. The [meeting prep use case](/use-cases/meeting-prep) shows the play in more detail.

## Troubleshooting

Things that commonly go wrong and how to read them:

- Auth errors: `DIZO_API_KEY` is not set where the pipeline runs, so `Secret.from_env_var` resolves to nothing.
- An `Authorization` header you set in `headers` is overriding `token`: remove one of them.
- OAuth errors: `oauth_config` cannot be combined with `token` or an `Authorization` header; for server pipelines, use a key.
- The model ignores or confuses tools: shorten `tool_names`.
- Tool calls rejected: the key's endpoint allow-list does not include that tool's endpoint.
- 402 `monthly_cap_reached` or rate limits: stop on the 402; for rate limits, retry only when `error.retryable` is true, after `error.retry_after` seconds.

## Security practices

Use `Secret.from_env_var` rather than a literal token so the key never appears in a serialized pipeline YAML or in logs. Give each deployed pipeline its own key so `dizo_balance` shows its usage separately and you can revoke it in isolation. Keep `billing:write` off pipeline keys; only that scope can top up or change refills, and the account owner can lock billing entirely.

Run development and CI with `dz_test_` keys, and use live keys only in production. You get a live key when you [sign up](/signup), plus 250 free credits on a work email, with no card required.

## FAQ

### Which package connects Haystack to Dizo?
`mcp-haystack`, installed with `pip install mcp-haystack`. It provides `MCPToolset` and `StreamableHttpServerInfo` under `haystack_integrations.tools.mcp`.

### How do I pass the Dizo key?
Set `token=Secret.from_env_var("DIZO_API_KEY")` on `StreamableHttpServerInfo`. It generates the `Authorization: Bearer` header Dizo expects, and the key is read from the environment at runtime.

### Do I need to call warm_up myself?
Not when the toolset is passed to a Haystack `Agent`, which warms it up automatically. If you use the toolset directly with a chat generator, call `warm_up_tools(toolset)` first.

### Can I use Dizo in a pipeline without an Agent?
Yes. Any Haystack component that can call the REST API at `https://api.dizo.ai/v1` works, for example a custom component that posts to `/v1/companies/enrich`. MCP through an Agent is simpler when the model should decide which tool to call.

### Does a pipeline pay for unmatched records?
No. Enrichment and lookups are charged only when something is matched or found, and searches charge only for results returned. An email finder miss is a free `404 not_found`.

### Is there a native Dizo component for Haystack?
No. There is no Dizo-specific Haystack package or listing. You connect through the standard `mcp-haystack` integration to the hosted Dizo MCP server.
