Skip to navigation

Tools and MCP servers

Give an agent webhook tools and tools discovered on an MCP server.

Tools belong to an agent’s draft. Every tool write takes the draft ETag in If-Match and a new Idempotency-Key, like any other draft edit (Build and publish an agent). A tool takes effect for calls once the agent is published.

export RASEN_API_BASE="https://api.rasen.ai/v1"
export RASEN_API_KEY="<your key>"
AUTH=(-H "Authorization: Bearer $RASEN_API_KEY")

Add a webhook tool

ETAG=$(curl -sS -D - -o /dev/null "$RASEN_API_BASE/agents/$AGENT_ID/draft" "${AUTH[@]}" \
| awk -F': ' 'tolower($1)=="etag"{print $2}' | tr -d '\r')
curl -sS -X POST "$RASEN_API_BASE/agents/$AGENT_ID/tools" "${AUTH[@]}" \
-H "If-Match: $ETAG" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
-d '{
"name": "lookup_order", "description": "Look up an order by its ID.", "kind": "webhook",
"side_effect": "none", "retry_posture": "none",
"definition": {
"url": "https://api.example.com/orders/{order_id}", "method": "GET",
"parameters": [{"name": "order_id", "location": "path", "source": "model", "required": true,
"schema": {"type": "string", "description": "The order ID."}}],
"headers": [{"name": "X-Api-Key", "value_type": "secret",
"credential": {"secret_id": "sec_…", "version": 1}}]
}}'
  • A secret header pins one exact {secret_id, version}. Rotation never moves a pin: to adopt a new version, replace the tool with the new reference and publish. See Secrets and rotation.

  • For one-off setup you may send write-only material instead of a reference: "credential": {"value": "…", "material_kind": "api_key"}. It is sealed at once as version 1 of a new secret and reads back only as its reference. Inline material needs the secrets.manage capability; a reference needs secrets.read.

  • end_call, transfer and transfer_to_number are reserved names, and so is the prefix _detached_: every write and validation refuses them with invalid_request (details.field = "name"). Configure the built-in tools through the draft’s default_tools (the default-tool policy).

  • A pinned version must be releasable when you bind it: a revoked or destroyed version, a secret of another workspace, or a secret of the other purpose answers credential_unavailable.

  • A tool’s name is its key in the draft: a second tool with the same name answers 409 tool_name_conflict.

  • A destination that names a private address (127.0.0.1, localhost, *.internal) answers 422 outbound_destination_refused.

Validate, replace and remove

# Check a definition without saving anything; no webhook is called and no Idempotency-Key is needed.
# It checks the tool as a new tool of the draft: a name the draft already has reports tool_name_conflict.
# To check a replacement, send the PUT; it validates before it saves.
curl -sS -X POST "$RASEN_API_BASE/agents/$AGENT_ID/tools/validate" "${AUTH[@]}" \
-H "Content-Type: application/json" -d @tool.json
# Replace it fully (the kind cannot change).
curl -sS -X PUT "$RASEN_API_BASE/agents/$AGENT_ID/tools/$TOOL_ID" "${AUTH[@]}" \
-H "If-Match: $ETAG" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" -d @tool.json
# Take it out of the draft.
curl -sS -X DELETE "$RASEN_API_BASE/agents/$AGENT_ID/tools/$TOOL_ID" "${AUTH[@]}" \
-H "If-Match: $ETAG" -H "Idempotency-Key: $(uuidgen)"

DELETE detaches the tool from the draft and answers the draft. A version that already froze the tool keeps running it until another version is activated. Disabling a live tool immediately is done in the app; to stop its credential at once, revoke the secret version (POST /secrets/{secret_id}/versions/{version}/revoke).

Register an MCP server and discover its tools

An MCP server is a workspace-level tool source that several agents can use.

curl -sS -X POST "$RASEN_API_BASE/mcp-servers" "${AUTH[@]}" \
-H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
-d '{"name": "Order system", "url": "https://mcp.example.com/mcp", "transport": "streamable_http",
"auth": "bearer", "credential": {"secret_id": "sec_…", "version": 1}, "resource_key": "orders-mcp"}'
# The server is recorded, not contacted: "discovery_state": "not_discovered".
curl -sS -X POST "$RASEN_API_BASE/mcp-servers/$SERVER_ID/discover" "${AUTH[@]}" -H "Idempotency-Key: $(uuidgen)"
curl -sS "$RASEN_API_BASE/mcp-servers/$SERVER_ID/tools" "${AUTH[@]}"
  • url is an absolute HTTPS URL with no credentials, query or fragment; anything else answers 400 invalid_request with details.field = "url".

  • auth: none carries no credential and no header name; bearer needs a credential; secret_header needs a credential and header_name.

  • The credential is a secret whose purpose is mcp_server, or inline material, which is sealed as one. A webhook_tool secret is refused with credential_unavailable: store the MCP token as its own secret even when it has the same value as a webhook secret.

  • A disabled server answers 404 not_found on reads and updates.

  • Discovery contacts the server under the platform’s egress policy and saves the bounded tool list. A server that does not answer gives "state": "failed" with a registered failure reason (never the remote text), and the last good discovery stays. Discovering the same tool set again changes no ETag. A host name that cannot be resolved is refused with outbound_destination_refused rather than recorded as a failed discovery.

  • The same discovery request with the same Idempotency-Key, sent while a discovery still runs, answers 409 idempotency_in_progress with Retry-After and does not contact the server; after Retry-After it replays the result. A refused discovery (outbound_destination_refused, credential_unavailable) keeps nothing, so the identical request can be sent again at once.

  • A running discovery holds its Idempotency-Key for up to two minutes, so Retry-After on a duplicate can be as long as 120 seconds.

  • Before a discovery saves its result, it is admitted again. If the key was revoked or the workspace suspended while it ran, it answers 401 unauthenticated or 409 workspace_unavailable and saves nothing. A discovery whose claim a retry took over also saves nothing: it answers 409 idempotency_in_progress while the new attempt runs, or replays that attempt’s answer once it has settled.

Attach a discovered tool

Attach a discovered tool to a draft with "kind": "mcp" and "definition": {"server_id", "remote_tool_name", "schema_digest"}, taken from the discovered list. The tool’s name must equal the remote name. The tool copies the server’s pinned credential version, so a server whose pinned version is revoked cannot have tools attached (credential_unavailable).

Change an MCP server

  • PUT /mcp-servers/{server_id} needs the server’s own ETag in If-Match.
  • An omitted credential keeps its binding only when auth and header_name are unchanged.
  • Discovery resets only when the URL, transport, auth mode or header name changes, so adopting a rotated credential keeps it.
  • Changing a server changes it in every draft that attached tools of it: those tools take its new URL, authentication and credential version at once, so the draft ETag of each of those agents changes. Each agent adopts the change when you publish it.
  • A different resource_key answers 409 conflict with details.reason = "resource_key_immutable"; omitting it keeps the stored key.

Disable an MCP server

DELETE /mcp-servers/{server_id} takes the server’s current ETag and an idempotency key. It soft-disables the source and removes it from ordinary discovery and authoring reads. The source keeps its resource_key; creating another with that key still conflicts. See the API Reference for disable eligibility and response details.

Credentials during calls

A webhook tool or MCP server sends the exact secret version it pins, and the platform checks that version every time it releases it.

  • Webhook tools. Each call to the tool releases the pinned version. A revoked or destroyed version is refused at once, also in live agents and running calls: the tool call shows as a refused tool outcome with credential_unavailable, and the call continues.
  • MCP servers. Before every tool call on an MCP server, the platform asks for the pinned version again. If the version is revoked, or the platform cannot confirm it in time (for example during a platform outage), the connection stops using the credential for the rest of the call: that tool call and every later one to the same server in the call end with credential_unavailable. The check fails closed. It shares the tool call’s deadline; with no time left, nothing is sent and the tool call fails with its deadline reason. The connection itself closes when the call ends.
  • An action that was already sent is not undone.

See Secrets and rotation for revoking a version.