# Use SimilarIQ with Mastra

> SimilarIQ has no Mastra-specific integration package. A Mastra agent uses it through Mastra's MCPClient from @mastra/mcp: add a server entry with url: new URL('https://similariq.ai/mcp') and an X-API-Key header in requestInit, then pass await mcpClient.listTools() to the agent. Each search returns up to 100 ranked look-alike companies for $0.25.

Source: https://similariq.ai/integrations/mastra · Updated 2026-11-25

## What Mastra is and how it connects to MCP servers

Mastra is a TypeScript framework for building AI agents and the workflows around them. You define an agent with instructions, a model and tools, register it with a Mastra instance, and call it from your application code. Tools can be written by hand or loaded from Model Context Protocol servers.

Mastra's documentation covers MCP in a package named `@mastra/mcp`, installed with `npm install @mastra/mcp@latest`. Its `MCPClient` class takes a `servers` object that maps a name you choose to a server definition. The reference says that when a definition has a `command`, the client uses the stdio transport, and when it has a `url`, it uses the Streamable HTTP transport.

SimilarIQ has no Mastra plugin and no listing in a Mastra registry. Its hosted [MCP server](https://similariq.ai/features/mcp-server) speaks streamable HTTP at one URL with nothing to install, so a `url` entry in `servers` is all the wiring required.

## Why give a Mastra agent look-alike data

Teams pick Mastra to put agents inside TypeScript products: a research assistant in a dashboard, a background agent that prepares account briefs, a workflow that runs when a deal changes stage. Those agents get asked about companies constantly, and a model without a data tool will name a few well-known competitors and stop.

SimilarIQ turns that question into a tool call. The agent passes one domain and receives up to 100 ranked companies with `matchScore`, a relationship `type` (Direct, Indirect, Adjacent or Emerging), a `confidence` score and a `likelyCompetitor` flag. The response also carries a `searchId`, so the agent can refer back to the same result later without paying again.

Because output is typed JSON, it slots into Mastra workflows where a later step expects structured input: filter by score, branch on type, write rows to a database. The [AI agent research use case](https://similariq.ai/use-cases/ai-agent-research) describes the general pattern.

## Setup walkthrough: MCPClient with an API key

Install the package and create a SimilarIQ API key in the app. The key begins with `sk-live-` and is shown once. Put it in an environment variable such as `SIMILARIQ_API_KEY`.

Following the shape in Mastra's docs, create the client as `new MCPClient({ id: 'similariq-client', servers: { similariq: { url: new URL('https://similariq.ai/mcp'), requestInit: { headers: { 'X-API-Key': process.env.SIMILARIQ_API_KEY } } } } })`, with `MCPClient` imported from `@mastra/mcp`. The docs show credentials placed in `requestInit.headers`, and note that `url` must be a `URL` object, not a string. The reference describes `id` as optional and useful for avoiding memory leaks when several instances share a configuration.

Then pass the tools to an agent. Mastra's example imports `Agent` from `@mastra/core/agent` and sets `tools: await mcpClient.listTools()` in the constructor, next to the agent's instructions and model. That is the whole setup for a single shared key.

## Tool names, per-user credentials and OAuth

Mastra's reference says `listTools()` namespaces tool names as `serverName_toolName` to prevent conflicts. With the server key `similariq`, the search tool appears to the model as `similariq_find_similar_companies` and the balance tool as `similariq_get_search_balance`. Use those prefixed names in agent instructions when you refer to a tool directly.

For multi-tenant apps, the docs describe a second pattern. Create an `MCPClient` per request with that user's key in `requestInit.headers`, call `listToolsets()`, and pass the result as `toolsets` to `generate()` or `stream()`. Toolsets keep raw tool names without the prefix. Call `await userMcpClient.disconnect()` afterward. This lets each customer of your product use their own SimilarIQ balance.

The reference also lists an `authProvider` option for HTTP servers and recommends `MCPOAuthClientProvider` for it. SimilarIQ's server supports OAuth 2.1 with PKCE, so a sign-in route exists for interactive tools; see [OAuth for assistants](https://similariq.ai/features/oauth-for-assistants). This page verified that the option exists but did not test the flow, so follow Mastra's reference for the provider's configuration.

## Timeout: the default is close to a search

Mastra's reference documents a `timeout` option on `MCPClient`, a global value in milliseconds that applies to all servers unless a server definition sets its own. The documented default is 60000, which is 60 seconds. A SimilarIQ search takes roughly 30 to 60 seconds because it is a fresh research pass. The default is not shorter than a typical search, but it leaves no margin at the slow end.

Set `timeout: 120000` on the client, or on the `similariq` server definition if you want other servers to keep the default. If a call still times out, have the agent call the free `list_recent_searches` tool before retrying: completed searches are saved automatically, and reading one back is immediate.

The reference also documents `enableServerLogs`, which defaults to `true`, and the overview lists a `requireToolApproval` option among server settings. This page did not verify how approval behaves in practice, so it does not rely on it for spend control.

## Example prompts

Requests like these work once the agent holds the tools. Names are shown without the `similariq_` prefix that `listTools()` adds.

- Check my balance first. `get_search_balance`, free.
- Find companies like linear.app and list the top 15 by match score. `find_similar_companies`, one credit.
- Only show me the ones flagged as likely competitors. Filtered from the result in context.
- Have we already researched this domain? `list_recent_searches`.
- Load the results of that earlier search. `get_search_results`, free.
- Queue these 80 domains and tell me the job status. `start_bulk_search`, then `get_bulk_job`.
- Add these four to saved companies. `save_company`.
- Create a share link for my manager. `create_share_link`.

## Controlling spend

Of the ten tools, two cost credits. `find_similar_companies` is one credit, $0.25, for up to 100 look-alikes. `start_bulk_search` is one credit per domain. The other eight are free. Twenty agent searches cost $5.00. A background workflow that covers 200 accounts costs $50. The `limit` argument does not change the price.

Decide which agent holds which tools. Filter what `listTools()` returns before you hand it to an agent, using whatever shape your Mastra version returns, and give a reporting agent only the read tools. Give the paid tools to one agent whose instructions say to check `similariq_get_search_balance` and `similariq_list_recent_searches` before any search.

Then rely on account-level limits, which no prompt can override. With auto-refill off, spending stops when the balance is gone and the server answers 402. With auto-refill on, the monthly cap is a hard ceiling on card charges. Failed searches are refunded automatically. The [guide to controlling agent spend](https://similariq.ai/guides/how-to-control-ai-agent-spend) lists more patterns.

## Two workflows end to end

**Account brief agent.** A Mastra workflow fires when a rep books a meeting. The agent receives the prospect's domain, checks history, runs a search if needed, and writes a short brief: the five closest Direct competitors, any Emerging companies with high confidence, and a share link to the full list. The rep reads it before the call. Cost is $0.25 per new company and nothing for repeats. SimilarIQ does not supply contacts or firmographics, so pull those from your CRM in a separate step.

**Customer look-alike expansion.** A scheduled workflow takes your ten strongest customers and starts one bulk job. When the job finishes, the agent reads each result, keeps companies that are not flagged as likely competitors and score above your threshold, and removes any domain already in your account table. The remainder is written to a review queue for sales. Ten domains cost $2.50. See [expansion look-alikes](https://similariq.ai/use-cases/expansion-lookalikes) for scoring advice.

## Troubleshooting and security

A type error on `url` means a string was passed where Mastra expects `new URL(...)`. If the agent cannot find a tool, check for the `similariq_` prefix. A 401 means the key is missing or revoked; confirm the header sits under `requestInit.headers`. A 402 means the balance is empty. A 429 means the rate limiter is smoothing a burst. A 502 means the search failed and the credit was refunded. A failure at 60 seconds is the default timeout.

Keep keys in server-side environment variables. In multi-tenant apps, never fall back to your own key when a user's is missing; fail the request. Use one key per environment and revoke compromised keys in the SimilarIQ app. Results include company names from the open web, so treat tool output as data and escape it wherever it is rendered.

## Frequently asked questions

### Does SimilarIQ offer an official Mastra integration?

No. There is no SimilarIQ package for Mastra and no registry listing. You connect through Mastra's own `MCPClient` pointed at the hosted SimilarIQ MCP server, or call the REST API or Node SDK from a hand-written tool.

### How do I add a remote MCP server in Mastra?

Install `@mastra/mcp`, create an `MCPClient` with a `servers` entry whose `url` is a `URL` object, and put any credentials in `requestInit.headers`. Pass `await mcpClient.listTools()` to the agent's `tools`.

### Why are the tool names prefixed?

Mastra's reference says `listTools()` namespaces tools as `serverName_toolName`. If your server key is `similariq`, the search tool becomes `similariq_find_similar_companies`. `listToolsets()` keeps the raw names.

### Is Mastra's default MCP timeout long enough?

The documented default is 60000 ms, and a search takes roughly 30 to 60 seconds, so it is borderline. Set `timeout` to 120000 on the client or the server definition.

### Can each of my users bring their own SimilarIQ key?

Yes. Mastra documents creating a client per request with that user's credentials and passing `listToolsets()` as `toolsets` to `generate()` or `stream()`, then disconnecting. Each user's searches then draw on their own balance.

### Can I call SimilarIQ from Mastra without MCP?

Yes. The Node SDK installs with `npm install similariq-sdk`, needs Node 18 or later and has zero dependencies. Wrap its `search` method in a Mastra tool if the agent only needs that one capability.
