Skip to Content
ZeroLeaksDocs
Shield SDK

scanTools()

Checks tool definitions, including MCP server tool lists, for tool poisoning before the model sees them.

Checks tool definitions for tool poisoning: instructions hidden in a tool's description or in its parameter schema. The model reads that text on every request, and the user usually never sees it, so a malicious or compromised MCP server can use it to steer the agent.

Run scanTools() on each MCP server's tool list before passing the tools to a model, and again whenever the server reports a change.

API

function scanTools(tools: ToolDefinition[], options?: ScanToolsOptions): ScanToolsResult
function scanToolsAsync(tools: ToolDefinition[], options?: ScanToolsOptions): Promise<ScanToolsResult>

tools can mix these shapes:

ShapeWhere the schema is read from
MCP (tools/list result)inputSchema
OpenAI Chat Completions { type: "function", function: { ... } }function.parameters
OpenAI Responses API function toolparameters
Anthropicinput_schema
AI SDKparameters or inputSchema

From each tool, the description and the free text in its schema (descriptions, titles, examples, defaults, enum and const values, and parameter names split into words, at any depth) are joined and passed to detect().

ScanToolsResult

FieldTypeDescription
flaggedbooleanTrue when any tool was detected or has an issue
toolsArray<{ name, result, issues }>Per tool: the detect() result and a list of issues

Issues:

IssueMeaning
duplicate_nameTwo tools share a name, so one can shadow the other
hidden_characters_in_nameThe name contains invisible or non-ASCII characters, often used to impersonate another tool
oversized_descriptionThe description is longer than maxDescriptionLength (4,000 characters by default), a common way to bury instructions
changed_since_pinnedThe definition differs from the one pinned in pins (see Pinning)

options takes every detect() option plus maxDescriptionLength and pins.

On 7,312 unique benign tool definitions from the Hermes function-calling dataset (NousResearch, Apache-2.0), scanTools() flagged 20 (0.27%), all by the classifier and all with very short descriptions, such as "Create a new user" or "Send an email". Raise classifier.threshold if short descriptions in your tool lists get flagged, or use onFlaggedTools: "warn" in the MCP client while you review them.

Hosted detection

scanTools performs synchronous local checks. For hosted or asynchronous detector options, use scanToolsAsync:

import { createHostedDetector, scanToolsAsync } from "@zeroleaks/shield";

const shield = createHostedDetector({
  apiKey: process.env.ZEROLEAKS_API_KEY,
  model: "shield",
});
const scan = await scanToolsAsync(tools, shield.options());

The synchronous function rejects asynchronous detector options. The MCP wrapper awaits checks when configured with a hosted detector.

Pinning

A server can change a tool after it was reviewed, keeping the name and changing what the model reads (a "rug pull"). pinTools(tools, pins?) returns pins for the tools, and scanTools(tools, { pins }) reports every tool whose definition no longer matches its pin as changed_since_pinned:

import { pinTools, scanTools } from "@zeroleaks/shield";

let pins = pinTools(approvedTools); // plain data: save it with JSON.stringify
// later
const scan = scanTools(currentTools, { pins });
pins = pinTools(currentTools, pins); // pins new tools; changed ones keep their old pin

A pin is the canonical JSON of the tool's description, title, input and output schemas, and annotations. Keys are sorted, so reordering a schema doesn't count as a change. pinTools() never overwrites an existing pin: a changed tool remains flagged until you remove its entry. The MCP client wrapper does this for you.

Example

import { scanTools } from "@zeroleaks/shield";

const { tools } = await mcpClient.listTools();
const scan = scanTools(tools);

if (scan.flagged) {
  for (const tool of scan.tools) {
    if (tool.result.detected || tool.issues.length > 0) {
      console.warn(`Refusing tool ${tool.name}:`, tool.result.matches, tool.issues);
    }
  }
}

const safeTools = tools.filter(
  (_, i) => !(scan.tools[i].result.detected || scan.tools[i].issues.length > 0)
);

scanTools() only reads the definitions. Tool results are scanned by the provider wrappers (scanToolResults, on by default) or by calling detect() on them.

On this page