Skip to content

Running tools from your code ​

Your backend can run a project's tools directly, with no model in the loop: the same operation, the same customer credential and the same write policy as the project's MCP server. Use a project API key.

List the tools ​

bash
curl "https://api.frege.io/v1/projects/$PROJECT/operations?page_size=100" \
  -H "Authorization: Bearer $KEY"

Each entry has tool_name, method, path, summary, description, tags and the JSON Schema input_schema of its arguments. GET /v1/projects/{id}/tools/search?q=refund searches names, summaries, descriptions, paths and tags.

Run one ​

bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/tools/createOrder/invoke" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"arguments": {"sku": "TEA-01", "quantity": 2}, "client_id": 42}'
FieldWhat it is
argumentsThe tool's arguments, by its input_schema. Send {} for a tool that takes none.
client_idThe customer whose sign-in the call uses: a customer of this environment who has signed in. Required, since every credential belongs to a customer.
asynctrue runs the call in the background; see below.

The answer is your API's own response, as it came:

json
{"data": {"tool_name": "createOrder", "method": "POST", "url": "https://shop.example.com/orders",
  "status_code": 201, "body": "{\"id\": \"A-1001\"}"}}

body is the response text; parse it yourself. An answer your API gave comes back this way whatever its status, with that status in status_code.

The call is in the audit log with both parties: who asked (the key), and whose account it reached (on_behalf_of).

When Frege refuses ​

StatusCodeWhy
403forbiddenThe caller may not run tools.
403call_deniedThe environment refused this call: its write policy or a guardrail. Nothing was sent.
409upstream_misconfiguredThe environment's sign-in setup cannot make this call: a secret bound to no host, or a missing injected value.
422validation_failedThe arguments or client_id are wrong; error.fields says which.
502bad_gatewayThe call failed before an answer came back; error.message says why.

With the write policy ask, writes from a key are refused: nobody is there to approve them.

In the background ​

With "async": true the call answers 202 at once with a task, and runs on its own:

bash
curl "https://api.frege.io/v1/projects/$PROJECT/tasks/$TASK" -H "Authorization: Bearer $KEY"

Poll every poll_interval_ms until terminal is true. Then status is completed (read result, shaped as the answer above), failed (read error) or cancelled. POST /v1/projects/{id}/tasks/{taskID}/cancel asks a task to stop; GET /v1/projects/{id}/tasks lists the recent ones. An intent tool cannot run in the background yet.