---
title: "Create or update the server-owned access policy of a backend function (functions/<name>.js)"
method: POST
path: "/api/mcp/tools/set_function_policy"
tags: ["tools"]
---

# Create or update the server-owned access policy of a backend function (functions/<name>.js)

`POST /api/mcp/tools/set_function_policy`

## Request

- Base URL: `https://finestructure.ai`
- URL: `https://finestructure.ai/api/mcp/tools/set_function_policy`
- Auth: HTTP bearer

Create or update the server-owned access policy of a backend function (functions/<name>.js). Without a policy a function answers only to the app owner's Studio token (401 for app visitors and webhooks). Recipes: anonymous checkout step or inbound webhook/IPN -> require_auth=false; signed-in members -> require_auth=true + allowed_roles (e.g. ['authenticated'] or ['admin','staff']); webhook with a shared secret -> require_secret=true + secret_name (an app secret) that the caller sends in secret_header. allowed_hosts fences the function's outbound network to those hosts plus the platform backend; omit it for open egress.

## Request body

- object
  - `app_id` string, required: The app ID
  - `function` string, required: Function name, e.g. takbull_create (file functions/takbull_create.js)
  - `require_auth` boolean, required: false = anonymous visitors and external callers may invoke
  - `allowed_roles` string[]: App roles allowed when require_auth is true; 'authenticated' = any signed-in app member
  - `require_secret` boolean: Caller must send a shared secret header (webhooks)
  - `secret_name` string: Name of the app secret holding the shared value (set_secret)
  - `secret_header` string: Header the caller sends the shared secret in
  - `allowed_hosts` string[]: Outbound egress allow-list of host[:port] entries, e.g. ['api.takbull.co.il']. Omit to keep the stored list; pass [] to open egress again
  - `sdk_identity` 'caller' | 'app': Whose identity the SDK inside the function uses. 'caller' (default): the function reads data as whoever called it, so an anonymous call sees only what anonymous may read. 'app': the SDK acts as the app owner on THIS app's entities (a checkout or payment IPN that must load/update orders whose read policy is owner/admin/staff); the caller still counts as anonymous for rate limits, audit and X-FSe2-Caller-Type. Owner-only. Omit to keep the stored value

## Response `200`

Tool executed successfully

- ToolResult
  - `ok` boolean, required
  - `tool` string, required
  - `result` object, required

## Other responses

- `400`: Invalid arguments for this tool
- `401`: Missing or invalid bearer token
- `402`: Not enough credits on the account
- `403`: Token scope does not permit this tool
- `404`: Unknown tool name
- `429`: Rate limit exceeded, retry after the indicated delay
- `500`: Internal error while executing the tool

---

[API](https://skmtc.dev/finestructure/apis/fine-structure-api.md) · [All operations](https://skmtc.dev/finestructure/apis/fine-structure-api/llms.txt) · [OpenAPI document](https://skmtc.dev/finestructure/apis/fine-structure-api/revisions/02c50ed5fd70?raw)
