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
| Method | Behavior |
|---|---|
initialize | Returns protocol version 2024-11-05, capabilities.tools.listChanged: false, server agentshield-gateway 0.1.0 |
tools/list | One descriptor per configured name, requiring a resource string |
ping | Empty result |
tools/call | Forwards to client.call_tool |
| anything else | JSON-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| Variable | Required | Meaning |
|---|---|---|
AGENTSHIELD_GATEWAY | yes | Gateway origin |
AGENTSHIELD_AGENT_ID | yes | Registered agent id |
AGENTSHIELD_ORGANIZATION_ID | yes | The agent's organization |
AGENTSHIELD_SEED_FILE | yes | Path to the 32-byte seed. Read once at startup |
AGENTSHIELD_TOOLS | no | Comma-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" }
}
}
}resourceis required and removed from the arguments.operationis optional, defaults to the tool name, and is removed from the arguments.- Everything else is sent as
arguments.
Results
| Outcome | MCP result |
|---|---|
allow and executed | content: [{type: "text", text: <execute result JSON>}], isError: false |
deny, require_approval | isError: true, text {"outcome", "decision_id", "reason"} |
| Gateway error | isError: true, text {"error", "message"} |
Unknown tool name, missing resource, bad params | JSON-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.
Implementation references
Was this page helpful?
CrewAI
GatewayCrewTool, a CrewAI BaseTool with no local function. Give crews gateway-enforced tools with typed arguments and optional approval waiting.
Custom Tool Integration
Put your own HTTP API behind AgentShield with the http.request adapter. Configure hosts and credentials, write policy, and call it from an agent.