Mastra
@protogrid/mastra connects Mastra agents to the MCP servers in the protogrid registry.
It finds servers by what they do, checks each against rules you set, connects directly to the ones that pass and hands their tools to an Agent.
MIT licensed, Mastra 1.83 or later and Node.js 20 or later.
npm install @protogrid/mastra @mastra/coreIt builds on the TypeScript SDK and the official MCP client, @modelcontextprotocol/client 2.x, which it installs.
Load the tools of servers that pass your rules
Section titled “Load the tools of servers that pass your rules”import { Agent } from "@mastra/core/agent";import { loadTools } from "@protogrid/mastra";
await using mail = await loadTools({ query: "send an email", rules: { min_quality: 70, owner_verified: true }, secrets: { MAIL_API_KEY: process.env.MAIL_API_KEY },});const agent = new Agent({ id: "mailer", name: "Mailer", instructions: "You send mail for the team.", model: "anthropic/claude-sonnet-5", tools: mail.tools,});await agent.generate("Mail the weekly report to ops");For a query, loadTools tries the best search results in order (candidates, 10 by default) until maxServers (1 by default) have loaded; servers: ["io.github.owner/server"] names them instead.
For each server:
- The gate checks it against your rules. A server that fails is passed over.
- The server’s connection comes from the registry with
${NAME}placeholders, whichsecretsfills in your process. Secrets are never sent to protogrid, and a server needing one you did not give is passed over. - Your process connects to the server’s own endpoint, with no proxy in between, and lists its tools.
- The tools come back in
toolsas Mastra tools, named<server key>_<tool>, with the server’s own input schema.originsmaps each name to its server, its name there and the tool-set hash protogrid checked.
A tool that answers with text returns that text, any other answer returns the MCP result as it came, and a result the server marks as an error makes the tool call fail.
The connections stay open until you call close(), which await using does for you.
When no server loads, loadTools throws NoServerLoaded with the reason for each server passed over.
Pass a new LoadReport() as report to read the servers loaded and passed over in every case.
Rules are set by whoever runs the agent; the model cannot change them. A rule you leave out keeps its default, and an empty list switches a default off.
rules |
Default | Meaning |
|---|---|---|
min_quality |
none | Lowest quality score accepted. |
min_trust |
none | Lowest trust score accepted. |
no_fail |
tools.hidden_text, tools.poisoning |
Quality checks that must not fail. |
exclude_quality_flags |
known-vulns |
Quality flags that refuse a server. |
exclude_flags |
none | Trust flags that refuse a server. |
owner_verified |
none | true accepts only servers whose owner proved control. |
paid |
false |
false refuses servers that charge per call, which an agent without an x402 wallet cannot use; null accepts them. The default from 0.1.1. |
class |
R0, R1 |
Connection classes accepted. Add R2, with the oauth option of the TypeScript SDK, to allow OAuth servers. Local packages (L0) are never loaded. |
The defaults refuse tools that hide text from people, tools holding instructions aimed at the model, servers depending on a package with a known vulnerability, and servers that charge per call.
Pin what you reviewed
Section titled “Pin what you reviewed”The gate returns the hash of the tool set protogrid checked.
pins: { "io.github.owner/server": "<tools_hash>" } passes over that server once its checked tools differ from the ones you reviewed, so a changed tool never reaches your agent unnoticed.
With strictTools: true, loadTools also hashes the tools the server lists at connection time and passes over the server unless they are the ones protogrid checked.
This catches a change made after protogrid’s last probe, at the cost of refusing a server that changed for a good reason until protogrid probes it again.
Let the agent search and check
Section titled “Let the agent search and check”import { gateTool, searchTool } from "@protogrid/mastra";
const tools = { protogrid_search: searchTool(), protogrid_gate: gateTool({ rules: { min_quality: 70 } }),};protogrid_searchfinds servers by what they do and returns, for each, its name, connection class, quality score and flags, whether its owner is verified, and the tools that matched.protogrid_gatetells whether a server passes the rules given when the tool was built, with every broken rule.
Both read PROTOGRID_API_KEY for higher limits; no key is needed.