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.
Most agent tools are HTTP APIs. The http.request adapter lets you place any HTTPS API behind AgentShield without writing gateway code: the gateway holds the credential, enforces policy per operation and URL, and records every call.
This guide puts a fictional internal ticketing API at tickets.internal-example.com behind the gateway. Substitute your own host.
Write a tools file
{
"http": {
"timeout": "5s",
"max_response_bytes": 262144,
"hosts": [
{
"host": "tickets.internal-example.com",
"headers": {
"Authorization": { "env": "TICKETS_API_AUTHORIZATION" }
}
}
]
}
}The file names environment variables, never secret values, so it can be committed. Hosts are lowercase hostnames with an optional port; IP addresses are refused.
Give the gateway the credential
export GATEWAY_TOOLS_CONFIG=/etc/agentshield/gateway-tools.json
export TICKETS_API_AUTHORIZATION="Bearer <service token>"The gateway refuses to start if a referenced variable is empty. The agent never sees this value: the adapter injects it, and agents cannot set Authorization, cookies, or Host.
With Docker Compose, mount the file into the gateway container and set GATEWAY_TOOLS_CONFIG to its path inside the container. On Kubernetes, use a ConfigMap for the file and a Secret for the variable.
Check the logs
On startup the gateway logs the registered adapters:
{"level":"INFO","msg":"tools","adapters":["http.request","sample.echo"]}Write policy for operations and URLs
Operations map to HTTP methods: http.get, http.head, http.post, http.put, http.patch, http.delete. Allow reads, hold writes for a person, and deny deletes:
{
"permissions": {
"allowed": ["http.get"],
"denied": ["http.delete"],
"approval_required": ["http.post", "http.patch"]
},
"resource_rules": [
{ "effect": "allow", "action": "http.get", "resource": "https://tickets.internal-example.com/v2/tickets" },
{ "effect": "allow", "action": "http.get", "resource": "https://tickets.internal-example.com/v2/queues" }
]
}Because http.get has allow resource rules, only those two exact URLs can be read. Remove the resource rules to allow reads anywhere on the listed host.
Call it
executed = client.call_tool(
tool_name="http.request",
operation="http.get",
resource="https://tickets.internal-example.com/v2/tickets",
arguments={"query": {"status": "open", "assignee": ["me", "team"]}},
)
print(executed.result["status"], executed.result.get("json"))Query parameters go in arguments.query, never in the resource. The resource must be the canonical URL: lowercase host, no query, fragment, userinfo, or dot segments. A non-canonical spelling is rejected with a message showing the canonical form.
Argument reference
| Argument | Type | Notes |
|---|---|---|
query | object of string or string[] | Encoded into the URL query |
headers | object | Only Accept, Accept-Language, If-Match, If-None-Match |
body | JSON value | Only for post, put, and patch. At most 256 KiB |
Any other key is rejected with 400 validation_failed before anything is dispatched.
Exposing the API to a framework
Give the model narrow, well-described tools rather than a generic HTTP tool:
from agentshield_langchain import ToolSpec, gateway_tools
tools = gateway_tools(client, [
ToolSpec(
name="list_open_tickets",
description="List open support tickets.",
tool_name="http.request",
operation="http.get",
resource="https://tickets.internal-example.com/v2/tickets",
parameters={"type": "object", "properties": {"query": {"type": "object"}}},
),
ToolSpec(
name="comment_on_ticket",
description="Add a comment to a ticket. A person approves every comment.",
tool_name="http.request",
operation="http.post",
resource="https://tickets.internal-example.com/v2/comments",
parameters={
"type": "object",
"properties": {"body": {"type": "object"}},
"required": ["body"],
},
approval_timeout=600,
),
])Fixing resource per tool means a prompt-injected model cannot point the tool at another URL.
Development options
For local testing against a plain-HTTP service on your machine, the tools file accepts allow_insecure_http: true and allow_private_networks: true. Both are refused when AGENTSHIELD_ENV=production, and the gateway will not start with them.
Beyond HTTP
Tools that are not HTTP APIs need a dedicated adapter in the gateway, designed for the scope it is limited to. See Tool execution architecture. A tool name with no adapter always returns 501; AgentShield never fakes a successful execution.
Implementation references
Was this page helpful?
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.
API Reference
The AgentShield HTTP APIs. Two services, two authentication schemes, one error envelope. Rendered from the OpenAPI contracts in the repository.