Skip to main content

Server tools

Server tools are tools the gateway runs itself. A caller puts {"type": "spanway:web_fetch"} or {"type": "spanway:datetime"} in tools on /chat/completions, the gateway gives the routed model an ordinary function tool in its place, runs the tool when the model calls it, feeds the result back and returns the final answer. Any model that supports function calling can use them.

Every server tool is off by default. A tool runs only when the proxy admin enabled it and both the caller's key and, for a team key, the key's team were granted it.

Server tools on chat completions are free and need no license. Only using them inside custom agents needs the enterprise agent_server_tools feature.

ToolWhat it does
spanway:datetimeReturns the current date and time, optionally in an IANA timezone such as Europe/Berlin.
spanway:web_fetchFetches a public http or https page and returns its text, title and final URL. HTML is reduced to text without scripts or styles. Plain text, Markdown, CSV, JSON and XML are returned as text.

A real-world scenario​

A research team wants a model to read a public web page and summarise it, without building their own fetch tool or giving the model a path into the company network. The admin enables web_fetch for public domains only and grants it to the team. A developer then adds one tool entry to their chat request and gets the summary back.

Steps​

  1. Enable the tools in general_settings.server_tools, as in Enable server tools, and reload the config.

  2. Grant web_fetch to the team. In the Admin UI open Teams, open the team, click Edit and tick web_fetch under Server Tools. With the API, use the /team/update call in Grant server tools to keys and teams.

  3. Check what a team key may use.

    curl http://localhost:4000/v1/server_tools -H "Authorization: Bearer $TEAM_KEY"
  4. Send the chat completion from Use a server tool with the team key.

  5. Open Logs in the Admin UI to see the request, its fetch and the cost.

Expected result​

The answer is the model's summary, and choices[0].message.provider_specific_fields.server_tool_calls lists the fetch with status completed.

Enable server tools​

An admin enables tools under general_settings in config.yaml. The proxy refuses to start when the block is invalid.

general_settings:
server_tools:
enabled_tools: ["datetime", "web_fetch"]
limits:
max_tool_calls: 10 # server tool calls per request, at most 30
max_wall_seconds: 600 # deadline for the server tool loop of one request, at most 900
max_cost_usd: null # optional cap on server tool spend per request
web_fetch:
allowed_domains: [] # when set, only these domains and their subdomains can be fetched
blocked_domains: []
allowed_ports: [80, 443]
max_uses: 10 # fetches per request, at most 50
max_content_chars: 100000
max_body_bytes: 5242880
timeout_seconds: 15 # at most 30
max_redirects: 5
price_per_fetch: 0.0 # charged to the caller's spend for each fetch

Removing a tool from enabled_tools, or removing the block, turns the tool off on the next reload.

Grant server tools to keys and teams​

Grants live in object_permission.server_tools on keys and teams. An empty list grants nothing.

curl -X POST http://localhost:4000/team/update \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"team_id": "team-research", "object_permission": {"server_tools": ["web_fetch", "datetime"]}}'

curl -X POST http://localhost:4000/key/generate \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"team_id": "team-research", "object_permission": {"server_tools": ["web_fetch"]}}'

Only a proxy admin can change the server tools of a team, and only a proxy admin can grant server tools to a key that is not in a team. A key can only be granted tools its team was granted. Grant changes are recorded in the key and team audit log like any other permission change. The master key and a proxy admin's UI session can use every enabled tool. A virtual key follows its key and team grants even when a proxy admin owns it.

In the Admin UI, tick the tools under Server Tool Settings when you create a key or a team, or under Server Tools when you edit one. The list shows the enabled tools that your own session may use, which for a proxy admin outside a team is every tool enabled in general_settings.server_tools. A team admin or other user sees only the tools granted to them, so an empty list with the note "No server tools are available to you" means either that none are enabled or that none were granted to you. On a team the boxes are locked for everyone but a proxy admin, and the form says so. A tool that is still granted but no longer enabled stays in the list, marked as having no effect, so you can remove it. The key and team views show the granted tools under Object Permissions.

A key can list the tools it may use, with the function schema the model sees and its limits.

MethodPathSummary
GET/v1/server_toolsList the server tools your key may use
curl http://localhost:4000/v1/server_tools -H "Authorization: Bearer sk-my-key"

Use a server tool​

curl http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer sk-my-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Summarize https://example.com in one sentence"}],
"tools": [{"type": "spanway:web_fetch", "allowed_domains": ["example.com"], "max_uses": 3}],
"max_tool_calls": 5
}'

A request that asks for a server tool the gateway has not enabled, or that the key or team was not granted, fails with 403 before any model is called, and the error names the tool. This also holds when no server tool is enabled at all, so a spanway: tool entry is never sent on to a provider. Server tools work on /chat/completions today. Asking for one on another endpoint returns 400.

The tool entry for spanway:web_fetch can narrow the admin settings with allowed_domains, blocked_domains, max_uses and max_content_chars. A request can never widen them. max_tool_calls at the top level of the body lowers the per-request limit.

The response is the model's final answer. choices[0].message.provider_specific_fields.server_tool_calls lists each server tool call with the fields id, name (the tool), status and detail (the reason when it did not complete). The status is completed, failed, refused, skipped or error. error appears as a single entry with an empty id when the server tool loop itself failed. The gateway then removes the server tool calls from the answer, returns the model's last answer as it stood, and puts the error type in detail. Streaming requests are answered as a stream once the tools have finished.

When the model calls a server tool and one of your own function tools in the same turn, the gateway returns your function call only and does not run the server tool in that turn, so you never receive a call you cannot answer. The server tool call is listed in server_tool_calls with status skipped.

Limits​

Each call is checked against the request's limits before it runs. A call over a limit is not run, the model gets a failed tool result that says which limit was reached, and the tool is no longer offered for the rest of the request. If the model still calls a tool that was withdrawn, that call is refused the same way and the model gets one more turn to answer. When it calls a refused tool again in that turn, the gateway stops and returns the answer as it stands, with every call it did not run listed as refused. The same call repeated across many steps keeps working until a limit is reached.

LimitDefaultMaximum
Server tool calls per request1030
Fetches per request1050
Deadline for the server tool loop of a request600 seconds900 seconds
Time per fetch, redirects included15 seconds30 seconds
Bytes read per fetch5 MB5 MB
Text returned per fetch100,000 characters400,000 characters

The deadline starts when the first model answer asks for a server tool and covers the tool calls and the model turns in between. No call starts after it, and a fetch that starts close to it only gets the time that is left. The cost cap is checked before each call, so the call that crosses it still finishes and the next one is refused.

How web fetch stays off your network​

Web fetch never reaches private, loopback, link-local, carrier-grade NAT, multicast or cloud metadata addresses, and this does not depend on any other URL setting of the gateway. IPv6 addresses that carry an IPv4 address, such as NAT64 (64:ff9b::/96), 6to4 and IPv4-mapped forms, are checked by the IPv4 address inside them, so a NAT64 gateway cannot be used to reach an internal IPv4 host. Before each request, including each redirect, the gateway checks the scheme, the port, the domain lists and every address the host name resolves to. It then connects to the one address it checked and sends the original host name in the Host header and for TLS, with certificate checks on. Nothing resolves the name a second time, so a DNS server that answers with a public address first and a private one later cannot redirect the fetch. Redirects are followed one at a time, at most max_redirects times, and every hop goes through the same checks.

URLs with credentials in them are refused. The gateway sends no caller headers, cookies or credentials, only a fixed SpanwayFetch user agent. It asks for an uncompressed body, and when a server compresses anyway the byte limit applies to both the compressed and the decompressed size, so a small compressed body cannot expand past it in memory. Failures, such as a refused address, an HTTP error, a timeout or an unsupported content type, come back to the model as a failed tool result and never fail the request.

Fetched content is untrusted​

A fetched page is text written by whoever runs that site, and the model reads it as a tool result. A page can carry instructions meant for the model, and a model that follows them can call web fetch again with a URL that carries parts of the conversation in its query string. Before a result goes back to the model, the gateway runs the guardrails configured for the post_mcp_call event on it, the same ones that check MCP tool results, so a prompt injection or data loss guardrail set up for MCP also covers fetched pages. A guardrail can mask parts of the result, and a result it blocks reaches the model only as a failed tool result naming the guardrail.

For anything beyond trusted sources, set allowed_domains in the admin settings or in the tool entry so the model can only fetch the domains you expect, and keep max_uses low.

Tools the gateway does not run​

There are no shell, patch, code execution or subagent server tools, because running code or editing files on the gateway host would turn every granted key into remote code execution. Model-written code can still run, but never on the gateway host: code interpreter interception runs it in an external sandbox, such as E2B or OpenSandbox, that the gateway creates and deletes. Search, tool discovery and other remote tools work through the MCP gateway instead, where each server is granted per key and team and guardrails can check every call's arguments and results.

Spend, logs and traces​

Every server tool call is logged as its own call with call_type aserver_tool and model spanway:<tool>, billed to the caller's key, team and user like the model calls around it, and tagged with the parent request's session and trace ids. Spend logs, budgets, the run ledger and Lens show the tool calls next to the model calls of the same request. The log keeps the tool, call id, status, error and cost, and never the fetched page, whatever the request's logging settings are.

Server tools in custom agents​

Custom agents can use server tools through builtin_tools with server_web_fetch and server_datetime. This needs a license that includes the agent_server_tools feature and the tool enabled in general_settings.server_tools. A run also needs the person who starts it to be granted the tool on their key and team. Otherwise the run is refused with 403 before it starts. Each call is billed and logged like any other server tool call, under the run's session. A run gets its own set of the limits above, counted across all of its steps, and its fetched pages go through the same guardrails. Those include the guardrails on the caller's key, team and project and the ones the policy engine attaches to that key, team or the agent's model.

Errors​

StatusMessageMeaning and fix
403Server tools not enabled on this gateway: [...]The request asks for a tool that is not in general_settings.server_tools.enabled_tools. Enable it.
403Server tools not enabled for this key or team: [...]The tool is enabled, but the key or its team has no grant. Grant it.
403Key requests server tools not granted to team '<team id>': [...]. Team grants: [...].A key create or update asks for tools its team was not granted. Grant them to the team first, or remove them from the key.
400Unknown server tools [...]. Known server tools: [...]A grant names a tool that does not exist. Use a name from the list.
400Invalid or unsupported server tool ...A spanway: tool entry has an unknown type or a field with a wrong value. Check the entry against the examples above.
400max_tool_calls must be an integermax_tool_calls is not a whole number. Send a number.
400max_tool_calls must be between 1 and 30max_tool_calls is outside the allowed range. Send a value from 1 to 30.
400spanway: server tools are only available on /chat/completionsA spanway: tool was sent to another endpoint. Use chat completions.
403Only a proxy admin can change the server tools granted to a team.Ask a proxy admin.
403Only a proxy admin can grant server tools to a key that is not in a team.Put the key in a team, or ask a proxy admin.
A call listed as refusedA limit such as max_uses or the deadline was reached.Raise the limit in the admin settings, or ask the model for fewer fetches.
The gateway refuses to startThe server_tools block is invalid.Fix the value the startup error names.
A single server_tool_calls entry with status errorThe server tool loop failed, for example a follow-up model call failed.Check the gateway log line server tool loop failed and the follow-up call in Logs.

Logs​

LevelLineWhat it meansAction
WARNINGserver tool <name> failed: <error type>One tool call raised an error, and the model got a failed tool result.Normal now and then, for example a page that times out. Investigate when it repeats.
WARNINGserver tool loop failed: <error type>The whole loop failed, and the answer carries a server_tool_calls entry with status error.Check the follow-up model call of that request in Logs.
INFOguardrail withheld a <name> result: <error type>A post_mcp_call guardrail blocked a tool result, so the model only saw a failed result naming the guardrail.Expected when the guardrail is doing its job.