What Pydantic AI is and how it uses MCP
Pydantic AI is a Python agent framework from the team behind Pydantic. An agent is created with a model and, optionally, tools and toolsets; you run it with a prompt and get typed, validated output. Its design leans on Python type hints, so tool arguments and results are checked instead of trusted.
The framework's documentation has a client page for Model Context Protocol servers. The current class is MCPToolset, imported from pydantic_ai.mcp, and the install command shown is pip install "pydantic-ai-slim[mcp]". You construct it with a server URL and pass it to the agent as Agent(model, toolsets=[toolset]). The docs state that a URL ending in /sse uses SSE and any other URL uses Streamable HTTP.
SimilarIQ has no Pydantic AI plugin or listing. It hosts an MCP server at https://similariq.ai/mcp over streamable HTTP. The URL does not end in /sse, so MCPToolset selects the right transport without further configuration.
Why connect a typed agent to look-alike search
Pydantic AI users care about structure. They define an output model and expect the agent to fill it with values that came from somewhere real. Competitor and look-alike questions are a poor fit for a model working alone: it can produce a well-formed list of company names with nothing behind the ordering.
SimilarIQ supplies the values. One call with a domain returns up to 100 companies, each with rank, company, domain, matchScore from 0 to 100, a relationship type of Direct, Indirect, Adjacent or Emerging, confidence from 0 to 100 and a boolean likelyCompetitor. Those fields map cleanly onto a Pydantic model with an integer score, a literal type and a boolean.
That pairing lets you write agents whose output you can test. If the output model requires a match score for every company, the agent has to obtain it from the tool. The structured output glossary entry explains why that constraint improves reliability.
Setup walkthrough: MCPToolset with an API key
Install the MCP extra, then create a SimilarIQ API key in the app. The key starts with sk-live-, is shown once, and should be read from an environment variable.
Create the toolset as toolset = MCPToolset('https://similariq.ai/mcp', headers={'X-API-Key': KEY}). The docs describe headers as the place for static headers such as API keys. Then build the agent with Agent(model, toolsets=[toolset]), using whichever model identifier you already use, and run it with await agent.run('Find look-alikes for stripe.com').
The docs describe the connection lifecycle. Wrap runs in async with agent: to open the connection once and close it afterward. If you skip that, the toolset opens and closes automatically as needed, which is fine for a single run and slower for many. The docs also note that the server must already be running, since Pydantic AI does not start remote servers; SimilarIQ's is hosted, so there is nothing for you to run.
Other ways to authenticate and configure
MCPToolset also takes an auth argument. The docs say it accepts a bearer token string, an auth object for the underlying HTTP client, the string 'oauth', or a function that returns credentials per run. SimilarIQ's server supports OAuth 2.1 with a sign-in and consent screen, so 'oauth' suits a tool run by a person at a keyboard. For unattended jobs, the API key header is the simpler choice. The per-run function is useful when each of your users has their own key.
If you run several MCP servers, the docs show .prefixed('name') on a toolset to add a prefix to its tool names. MCPToolset('https://similariq.ai/mcp', ...).prefixed('similariq') would expose the search tool as similariq_find_similar_companies.
Configuration can also live in a file. load_mcp_toolsets('mcp_config.json') reads a JSON file with an mcpServers object; an entry with a url and optional headers is treated as HTTP, and the docs say environment variables are expanded with the ${VAR} syntax. That matches the generic client config SimilarIQ publishes, with "headers":{"X-API-Key":"${SIMILARIQ_API_KEY}"} keeping the key out of the file.
Timeouts, and a note on older tutorials
Pydantic AI's timeouts page lists two defaults for MCPToolset. init_timeout is 5 seconds and covers connecting and the initialize handshake. read_timeout is 300 seconds and bounds a single MCP request. A SimilarIQ search takes roughly 30 to 60 seconds, well inside 300, so you do not need to change anything for a search to complete. If a request does fail, the page says the model sees a retryable tool error under the default error behaviour.
The same page makes a point worth remembering: the agent's own tool timeout settings are enforced for function tools only and are not read by tools from an MCP server. If you set an agent-level tool timeout expecting it to cap a SimilarIQ call, it will not. Bound MCP calls on the toolset.
Pydantic AI publishes a migration map between major versions, and its notes say the current toolset's defaults differ from those of the earlier classes. Older tutorials use different class names for MCP servers. If an example you find does not import MCPToolset, check it against the current client page before copying it.
Example prompts
With the toolset attached, the agent can handle requests like these. Tool names are the ones the SimilarIQ MCP server exposes.
- Tell me how many credits are left.
get_search_balance, free. - Find look-alikes for datadoghq.com and return the Direct ones as a typed list.
find_similar_companies, one credit. - Before searching, see whether this domain is in recent searches.
list_recent_searches. - Re-open search SEARCH_ID and count results by relationship type.
get_search_results, free. - Start a bulk search for these 30 domains and poll until done.
start_bulk_search, thenget_bulk_job. - Save every result above a match score of 85.
save_company, free per call. - Return a share link for this search.
create_share_link. - List companies that have appeared in more than one of my searches.
list_my_companies.
Controlling spend
Two tools cost credits: find_similar_companies at one credit, and start_bulk_search at one credit per domain. One credit is $0.25 for up to 100 look-alikes. The remaining eight tools are free, including the balance check and every read of a past result. Twenty searches cost $5.00; a thousand cost $250.
The retry behaviour described above deserves attention for a paid tool. A search that fails on SimilarIQ's side returns an error and the credit is refunded automatically, so those retries are free. A retry after a client-side timeout is different, which is one more reason to leave read_timeout generous. Instruct the agent to check list_recent_searches before repeating a search.
For agents that should never spend, restrict the toolset to the free tools using the filtering mechanism in your Pydantic AI version; this page did not verify its name. And set account limits in SimilarIQ: the balance is the stop when auto-refill is off, and the monthly cap is a hard ceiling when it is on. See spend controls.
Two agents worth building
Typed competitor report. Define an output model with a list of companies, each holding a name, domain, score, type and confidence, plus a short summary field. Give the agent the toolset and one instruction: search the domain if it is not in history, then fill the model using only tool results. The caller receives a validated object it can store or render. One new company costs $0.25. SimilarIQ provides no revenue, headcount or contact fields, so leave those out of the model or fill them from another tool.
ICP validation run. Feed the agent 15 of your best customers' domains. It starts one bulk job, waits, then reads each result and tallies which look-alike companies recur across customers. Recurring companies describe your market more reliably than any single list. Fifteen domains cost $3.75. The ICP validation use case explains how to interpret overlap, and results stay in history for free re-analysis.
Troubleshooting and security
A failure within five seconds of start-up is the init_timeout; check the URL is exactly https://similariq.ai/mcp and that your network allows outbound HTTPS. A 401 means the key is missing or revoked; confirm the header name is X-API-Key. A 402 means the balance is empty. A 429 means the rate limiter is smoothing a burst, so slow down. A 502 means the search failed and the credit was refunded.
Keep the key in an environment variable or a secrets manager, and use the ${VAR} form if you load servers from a JSON file so the file can be committed safely. Issue one key per agent or environment and revoke it from the SimilarIQ app when no longer needed. Company names in results come from the open web. Validate them as strings in your output model and never let tool output act as instructions. More background is in the guide to adding an MCP server.
Frequently asked questions
Is there an official SimilarIQ integration for Pydantic AI?
No. SimilarIQ publishes no Pydantic AI package. You connect through Pydantic AI's own MCPToolset pointed at the hosted SimilarIQ MCP server, or by writing a function tool that calls the REST API or the Python SDK.
How do I connect Pydantic AI to a remote MCP server?
Install the mcp extra, create MCPToolset with the server URL, and pass it in the agent's toolsets list. The docs say a URL ending in /sse uses SSE and any other URL uses Streamable HTTP.
Where does the SimilarIQ API key go?
In the headers argument of MCPToolset, as X-API-Key with your sk-live- key. The docs also describe an auth argument that accepts a bearer token, 'oauth', or a per-run function.
Do I need to raise a timeout for a 30 to 60 second search?
No. Pydantic AI's timeouts page gives the default read_timeout for a single MCP request as 300 seconds. The 5-second init_timeout applies only to connecting.
Does the agent's tool timeout apply to SimilarIQ tools?
No. Pydantic AI's docs say agent-level tool timeouts are enforced for function tools only, and tools from an MCP server do not read them. Set limits on the toolset instead.
Can I use SimilarIQ from Pydantic AI without MCP?
Yes. Install the Python SDK with pip install similariq, which uses only the standard library, and wrap its search method in a function tool. This suits agents that need search and nothing else.