Skip to Content
AgentShield
Integrations

Model Context Protocol (MCP)

Expose gateway-enforced tools to any MCP host over stdio with GatewayMCPServer. Tools are names; every tools/call goes through AgentShield.

GatewayMCPServer is a minimal MCP server whose tools/call handler only forwards to the AgentShield gateway. Tools are names, not functions. A name that was not listed is a protocol error and nothing runs locally.

Supported protocol surface

MethodBehavior
initializeReturns protocol version 2024-11-05, capabilities.tools.listChanged: false, server agentshield-gateway 0.1.0
tools/listOne descriptor per configured name, requiring a resource string
pingEmpty result
tools/callForwards to client.call_tool
anything elseJSON-RPC -32601 method not found

Notifications (messages without an id) receive no response. Messages use Content-Length framing on stdin and stdout, at most 1 MiB each.

Run the server

python -m pip install ./sdk/python ./integrations/mcp
export AGENTSHIELD_GATEWAY="http://127.0.0.1:8081"
export AGENTSHIELD_AGENT_ID="<agent-uuid>"
export AGENTSHIELD_ORGANIZATION_ID="<organization-uuid>"
export AGENTSHIELD_SEED_FILE="$HOME/.agentshield/agent.seed"
export AGENTSHIELD_TOOLS="sample.echo,http.request"
agentshield-mcp        # or: python -m agentshield_mcp
VariableRequiredMeaning
AGENTSHIELD_GATEWAYyesGateway origin
AGENTSHIELD_AGENT_IDyesRegistered agent id
AGENTSHIELD_ORGANIZATION_IDyesThe agent's organization
AGENTSHIELD_SEED_FILEyesPath to the 32-byte seed. Read once at startup
AGENTSHIELD_TOOLSnoComma-separated tool names. Defaults to sample.echo

The process exits with a message naming any missing required variable.

Configure an MCP host

Point your host at the agentshield-mcp command (installed with the package) as a stdio server. Use the command's full path if the host does not inherit your environment's PATH. The exact configuration format depends on the host; the command and environment are:

{
  "command": "agentshield-mcp",
  "env": {
    "AGENTSHIELD_GATEWAY": "http://127.0.0.1:8081",
    "AGENTSHIELD_AGENT_ID": "<agent-uuid>",
    "AGENTSHIELD_ORGANIZATION_ID": "<organization-uuid>",
    "AGENTSHIELD_SEED_FILE": "/path/to/agent.seed",
    "AGENTSHIELD_TOOLS": "http.request"
  }
}

Calling a tool

tools/call arguments map to the gateway like the LangGraph node:

{
  "jsonrpc": "2.0", "id": 7, "method": "tools/call",
  "params": {
    "name": "http.request",
    "arguments": {
      "operation": "http.get",
      "resource": "https://api.github.com/repos/octo/hello",
      "headers": { "Accept": "application/json" }
    }
  }
}
  • resource is required and removed from the arguments.
  • operation is optional, defaults to the tool name, and is removed from the arguments.
  • Everything else is sent as arguments.

Results

OutcomeMCP result
allow and executedcontent: [{type: "text", text: <execute result JSON>}], isError: false
deny, require_approvalisError: true, text {"outcome", "decision_id", "reason"}
Gateway errorisError: true, text {"error", "message"}
Unknown tool name, missing resource, bad paramsJSON-RPC error -32602

The server does not wait for approval. A held call is reported immediately.

Security notes

  • Tool descriptors say "Authorized only through the AgentShield gateway." Hosts cannot attach a handler, and the server rejects any tool definition that is not a plain string name.
  • The seed file is read once and kept in the client. Restrict its permissions.
  • An MCP host that also connects to other, unprotected servers can still reach tools through them. Route sensitive capabilities only through AgentShield.

Was this page helpful?

On this page