TypeScript SDK
The @agentshield/sdk client for Node.js. Set it up, call tools, handle decisions, execute approvals, and read content analysis.
The TypeScript SDK mirrors the Python client. It signs the raw body with the same signing input, executes only after allow, and has no local tool runner. It uses only node:crypto and the global fetch.
Set up
Build a package tarball from the repository and install it into your project:
# in the AgentShield repository
npm ci
npm pack --workspace @agentshield/sdk # builds dist/ and writes agentshield-sdk-0.1.0.tgz
# in your project
npm install /path/to/agentshield-sdk-0.1.0.tgzimport { Client } from "@agentshield/sdk";The package is ESM with type declarations, uses only node:crypto and the global fetch, and has no runtime dependencies. It works with plain node and any TypeScript setup using "moduleResolution": "NodeNext" or "Bundler". Inside the repository, workspaces can depend on it directly after npm run build --workspace @agentshield/sdk.
Node.js 22 or newer is required.
Create a client
import { readFileSync } from "node:fs";
import { Client } from "@agentshield/sdk";
const client = new Client({
gateway: "http://127.0.0.1:8081",
agentId: process.env.AGENTSHIELD_AGENT_ID!,
organizationId: process.env.AGENTSHIELD_ORGANIZATION_ID!,
seed: readFileSync(process.env.AGENTSHIELD_SEED_FILE!), // 32 bytes
});Prop
Type
Call a tool
import { ApprovalRequired, Denied, GatewayError } from "@agentshield/sdk";
try {
const executed = await client.callTool({
toolName: "http.request",
operation: "http.get",
resource: "https://api.github.com/repos/octo/hello",
arguments: { headers: { Accept: "application/json" } },
});
console.log(executed.adapter, executed.result);
if (executed.warning) {
// Pass this to the model with the content.
console.warn(executed.warning);
}
} catch (error) {
if (error instanceof Denied) {
console.log("denied:", error.decision.explanation.reason);
} else if (error instanceof ApprovalRequired) {
console.log("held:", error.decision.approvalId, error.decision.approvalExpiresAt);
} else if (error instanceof GatewayError) {
console.log(error.status, error.code, error.message);
} else {
throw error;
}
}Authorize and execute separately
const args = { body: { title: "Export is broken" } };
const decision = await client.authorize({
toolName: "http.request",
operation: "http.post",
resource: "https://api.github.com/repos/octo/hello/issues",
arguments: args,
});
if (decision.outcome === "require_approval") {
// after a person approves in the console
const executed = await client.execute(decision.decisionId, decision.idempotencyKey, decision.approvalId, args);
}execute(decisionId, idempotencyKey, approvalId?, args?) must receive the same arguments that were authorized for adapters that use them.
Types
interface Decision {
decisionId: string;
outcome: string; // "allow" | "deny" | "require_approval"
explanation: Record<string, unknown>;
idempotencyKey: string;
approvalId?: string;
approvalExpiresAt?: string;
}
interface ExecuteResult {
decisionId: string;
outcome: "allow";
adapter: string;
result: Record<string, unknown>;
analysis?: Analysis; // { status: "clean" | "flagged" | "unavailable", ruleset?, verdict?, findings? }
warning?: string; // set when analysis flagged the content
}analysisWarning(analysis) builds the same warning sentence for any Analysis value.
Low-level exports
| Export | Purpose |
|---|---|
publicKey(seed) | 43-character base64url public key for registration |
signingInput(timestamp, nonce, body) | The v1 signing string |
sign(seed, timestamp, nonce, body) | Unpadded base64url signature |
encodeJson(value) | Deterministic JSON bytes with sorted keys, identical to the Python encoder. Non-integer numbers throw |
Argument values may be objects, arrays, strings, integers, booleans, and null. Send decimals as strings or as integers in minor units.
Errors
Denied and ApprovalRequired carry .decision. GatewayError carries status, code, and message, and covers error envelopes, non-JSON responses, and decisions returned with an unexpected HTTP status. A network failure surfaces as the underlying fetch error.
Framework wrappers
The TypeScript SDK is the integration point for Node.js agent frameworks. Wrap callTool in your framework's tool interface without adding a local fallback; see Writing integrations for the rules every wrapper follows.
Implementation references
Was this page helpful?
Python SDK
The agentshield_sdk client. Install it, sign requests, call tools, handle decisions and errors, execute approvals, and use the framework-neutral tools layer.
LangGraph
Route every tool call in a LangGraph graph through AgentShield with GatewayToolNode, or give LangGraph agents typed gateway tools.