Skip to content

LangChain

langchain-protogrid connects LangChain 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 your agent. MIT licensed, Python 3.11 or later. For LangChain.js, see @protogrid/langchain.

Terminal window
pip install langchain-protogrid

It builds on the Python SDK and on langchain[mcp], LangChain’s MCP support (langchain.mcp, marked beta upstream).

Load the tools of servers that pass your rules

Section titled “Load the tools of servers that pass your rules”
import os
from langchain.agents import create_agent
from langchain_protogrid import Rules, load_tools
tools = await load_tools(
"send an email",
rules=Rules(min_quality=70, owner_verified=True),
secrets={"api_key": os.environ["MAIL_API_KEY"]},
)
agent = create_agent(model="anthropic:claude-sonnet-5", tools=tools)

For a query, load_tools tries the best search results in order (candidates, 10 by default) until max_servers (1 by default) have loaded; servers=["io.github.owner/server"] names them instead. For each server:

  1. The gate checks it against your rules. A server that fails is passed over.
  2. The server’s connection comes from the registry with ${NAME} placeholders, which secrets fills in your process. Secrets are never sent to protogrid, and a server needing one you did not give is passed over.
  3. Your process connects to the server’s own endpoint, with no proxy in between, and lists its tools.
  4. The tools come back named <server key>_<tool>, with protogrid_server and protogrid_tools_hash in their metadata.

When no server loads, load_tools raises NoServerLoaded with the reason for each server passed over. Pass a 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.

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; None accepts them. The default from 0.1.2.
classes R0, R1 Connection classes accepted. Add R2 to allow OAuth servers, which open a sign-in page the first time. 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.

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 strict_tools=True, load_tools 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.

from langchain_protogrid import ProtogridGate, ProtogridSearch, Rules
agent = create_agent(model=model, tools=[ProtogridSearch(), ProtogridGate(rules=Rules(min_quality=70))])
  • protogrid_search finds 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_gate tells 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.