Skip to content
askdareDocumentation

    ADR-0038: More tools: remote MCP, httpTool, web search, and approving a call

    • Status: Accepted on 2026-11-30 by the maintainer, with every recommendation of the first draft (see "Settled with the maintainer"). Built by one task per part (decision 6); where building differs, "As built in 0.8-t1", "0.8-t2", "0.8-t3", "0.8-t4" and "0.8-z1" say so.
    • Date: 2026-11-29
    • Related: ADR-0004 (the client never chooses tools), ADR-0015 and ADR-0030 (a button the server acts on), ADR-0017 (tool cards), ADR-0022 (toolResults), ADR-0025 (retrieval as a tool), ADR-0026 (provider path), ADR-0028 (the React budget). Decided in task 0.8-x5; approving a call is built after 0.8-b1.

    Context

    A bot today reaches the outside world only through defineTool: a server-side function with a strict Zod schema, a timeout (default 10 s, at most 120 s), a 16,000-character output cap, arguments re-validated before execute runs, and results that never reach the browser except through replies and ui. THREAT_MODEL.md (T6, T11) still says: don't give an anonymous bot tools with side effects, "not supported yet".

    Sites ask for four things that build on it:

    1. Tools from a remote MCP server they already run or buy (a CRM, a booking system, a docs server), without wrapping each tool by hand.
    2. Calling their own HTTP API in a few lines ("order status", "opening hours of a branch"), without writing fetch, timeouts and size checks each time.
    3. The web as a fallback when the bot's documents have nothing, for questions like "is the A4 closed today".
    4. A visitor approving a call before it runs ("Book a demo for Tuesday 10:00?" with Approve and Decline), which is what makes tools with side effects acceptable at all.

    Each one moves data across a new boundary: to a third-party server, to the app's API, to a web search, or into a button the server acts on. The rules that bound the design:

    • ADR-0004: the client never chooses the model, instructions, tools or identifiers; every endpoint has limits and budgets; no content or PII in logs.
    • ADR-0022 and ADR-0025, decision 6: what a tool returns is third-party data; retrieved text is always wrapped as untrusted.
    • ADR-0015 and ADR-0030: a click is a visitor message, with one exception (the handoff button). A button the server acts on needs its own ADR. This is that ADR, for a second action.
    • CLAUDE.md: only src/openai/ imports openai; raw OpenAI stream events never reach clients; the library hardcodes no model IDs and reads no files at runtime.
    • ADR-0028: a feature that grows the React entry makes room first. After 0.7 the entry has 501 B left of 34 KB and the headless case 86 B of 12 KB (measured on main at 9cd7dfa with a local zlib; CI's zlib reads 538 and 86).

    What the OpenAI API offers (checked 2026-11-29)

    From the openaiDeveloperDocs MCP server and the types of openai 7.62.0, the version the package depends on:

    • Remote MCP (MCP servers guide): a hosted tool { type: 'mcp', server_label, server_url | tunnel_id, allowed_tools, require_approval, authorization, headers, server_description, defer_loading }. OpenAI's servers call the MCP server (Streamable HTTP or HTTP/SSE), list its tools into an mcp_list_tools item and record each call, arguments and output, as an mcp_call item. allowed_tools takes names or a filter (tool_names, read_only from the server's readOnlyHint). require_approval is always (the default), never or a filter; an approval arrives as an mcp_approval_request item and is answered with an mcp_approval_response in the next request. authorization is not stored by OpenAI and must be sent with every request. No fee per call beyond tokens. The guide's own warnings: a malicious server can exfiltrate anything in the model's context, servers may change their tools without notice, and data sent to an MCP server follows that server's retention and residency, not OpenAI's. connector_id is deprecated for models released after 2026-09-01.
    • Web search (web search guide): { type: 'web_search', filters: { allowed_domains | blocked_domains } (up to 100), search_context_size, user_location, external_web_access }. The answer cites with url_citation annotations (URL, title, position), and the guide requires an interface that shows web results to show the citations as "prominent, clickable links". include: ['web_search_call.action.sources'] lists every URL consulted. With tool_choice: 'auto' the model may skip the search. max_tool_calls on responses.create caps built-in tool calls per response, across file_search and web_search together.
    • Cost (pricing, Tools table): web search is $10 per 1,000 calls plus the search content tokens at the model's input rate (a fixed 8,000-token block per call for gpt-4o-mini and gpt-4.1-mini). file_search is $2.50 per 1,000 calls.
    • Residency (data residency): both "Responses Web Search" and "Remote MCP server tool" are eligible for regional storage in every listed region and regional processing only in the United States and Europe; hosted tools aren't available for regional processing in Australia, India and Japan.

    Decision

    1. Remote MCP: askdare is the MCP client, in an add-on

    askdare calls the MCP server itself and turns each allowed tool into an ordinary askdare tool. It doesn't use OpenAI's hosted mcp tool (settled question 1). The hosted tool would save the client code, but the call would happen between OpenAI and the MCP server, out of askdare's reach: it couldn't apply the timeout, the output cap, the untrusted wrapper (ADR-0025, decision 6), the per-day limits or the visitor's approval of decision 4, and the server's output would go straight into the model's context. It would also tie MCP to the OpenAI path (ADR-0026) and require the server to be reachable from OpenAI's network.

    • Where: a new add-on, @boldare/askdare-mcp, so core gains no dependency. It depends on the official @modelcontextprotocol/sdk client (pinned and reviewed like every dependency) and speaks Streamable HTTP only. The older HTTP+SSE transport is deprecated in the MCP specification and isn't supported.

    • The API: a factory that returns tools for defineBot({ tools }):

      import { mcpTools } from '@boldare/askdare-mcp';
      
      const crm = mcpTools({
        server: 'crm',                               // a label for logs and doctor, [a-z0-9_-]
        url: 'https://mcp.example.com/mcp',          // https only (http://localhost outside production)
        headers: (context) => ({ authorization: `Bearer ${process.env.CRM_MCP_TOKEN}` }),
        allow: ['find_contact', { name: 'create_ticket', approval: true }],
        timeoutMs: 10_000,
      });
      
      defineBot({ tools: [...crm, findSlots] });

      The tool names the model sees are <server>__<tool>, so two servers can't collide with each other or with the bot's own tools; defineBot refuses duplicates as it does today.

    • Which servers: only those in the server's code, with a fixed URL. Neither the visitor nor the model can name a server, a URL or a tool outside allow.

    • Credentials stay on the server. headers is a function of the tool context (bot, locale, the verified identity of ADR-0009), so a signed-in visitor's call can carry a token the app mints for that user; it is never filled from the model's arguments or the request. Headers are never logged, never reach the client and never go to OpenAI. OAuth flows of the MCP authorization specification are out of scope: the app passes a token it already has.

    • The allowlist is required. allow names each tool; a tool the server lists but allow doesn't name doesn't exist for the bot. The tools' descriptions and input schemas come from the server's tools/list, cached per instance for 10 minutes; a listing that fails leaves that server's tools out of the turn and is reported once to onError. Because a server can change a tool's description or schema at any time, askdare doctor prints a fingerprint of each allowed tool's definition and warns when it differs from the one the app pinned in allow ({ name, fingerprint }, optional; settled question 3).

    • Arguments: an MCP schema is often not valid for OpenAI's strict mode, so these tools are sent with strict: false when the schema isn't strict-compatible, and the add-on validates the arguments against the listed inputSchema before the call. A tool whose schema it can't check is refused at listing time, with a doctor warning.

    • The client declares no capabilities. No sampling, no roots, no elicitation: a server can't ask the model to write, read the app's files or prompt the visitor. Resource links and images in a result are dropped, never fetched.

    • Timeouts and size: each call has timeoutMs (default 10 s, at most 30 s, below the turn's deadline), listing has 5 s. The result's text content (and structuredContent, as JSON) goes through the same 16,000-character cap as every tool; over it, the call fails with askdare's own text. An isError result is a failed call, and the model sees askdare's fixed failure text, not the server's.

    • Results are always untrusted: wrapped as {"untrusted_tool_result": …} whatever the bot's toolResults says, as search_knowledge results are, and the matching rule joins the instructions.

    • Approval by default for tools that may write: a tool needs the visitor's approval (decision 4) unless the server annotates it readOnlyHint: true or allow says approval: false. An annotation is the server's word, so the docs say to check it (settled question 4).

    • doctor gains mcp.reachable (initialize and list within 5 s), mcp.allowed (every name in allow exists) and mcp.changed (a pinned fingerprint differs).

    2. httpTool: one endpoint of the app, as a preset over defineTool

    httpTool builds a normal Tool (so replies, ui, timeoutMs and decision 4's approval work as they do), with the request built from validated arguments only. It lives in core (no dependency, fetch only) and is exported from @boldare/askdare next to defineTool.

    const orderStatus = httpTool({
      name: 'order_status',
      description: 'Looks up the status of one of the signed-in customer’s orders.',
      input: z.object({ orderId: z.string().regex(/^[A-Z0-9]{8}$/) }),
      url: 'https://shop.example.com/api/orders/{orderId}',
      headers: (context) => ({
        authorization: `Bearer ${process.env.SHOP_API_TOKEN}`,
        'x-customer': context.identity?.id ?? '',
      }),
      response: (body: { status: string; eta: string | null }) => ({ status: body.status, eta: body.eta }),
    });
    • Method: GET by default; POST, PUT, PATCH and DELETE take a body: (input, context) => JSON. Any method other than GET needs the visitor's approval unless the tool says approval: false (settled question 5).
    • The URL template can't move the request elsewhere (no SSRF):
      • the template is an absolute https: URL (http://localhost outside production), parsed once at definition; scheme, host, port and the path before the first placeholder are fixed, and placeholders aren't allowed in them;
      • a placeholder {name} names a top-level field of input with a string, number or boolean schema, checked at definition, so a typo fails at startup;
      • each value is filled with encodeURIComponent, and an empty value, . or .. fails the call, so a value can't add a path segment or climb out of the prefix;
      • after filling, the server checks that the URL's origin is the template's and its path starts with the fixed prefix, and refuses the call otherwise;
      • query parameters come from an optional query: (input, context) => Record<string, string>, set through URLSearchParams;
      • redirects are not followed (redirect: 'manual'); a 3xx is a failed call.
    • Headers come from the server: headers(context) as for MCP. Nothing from the visitor's request (cookies, Authorization, X-Forwarded-For) is forwarded.
    • The response: only a 2xx with a JSON content type counts; anything else is a failed call, and the model sees { "error": "http_error", "status": 404 } (the status only, never the body). The body is read up to maxResponseBytes (default 64 KB, at most 1 MB) and the read is cut there. response(body, { status }) shapes it into what the model sees; without it, the whole body goes on. The shaped result then takes the usual 16,000-character cap and toolResults wrapping (it is the app's own API, so toolResults decides, unlike MCP).
    • Timeout: timeoutMs, default 10 s as for every tool, passed to fetch as an AbortSignal together with the turn's.

    3. web_search: off by default, a fallback after the documents

    • A bot turns it on in defineBot:

      defineBot({
        knowledge: { index },                          // or { vectorStoreId }
        webSearch: {
          when: 'fallback',                            // 'fallback' (default) | 'always'
          allowedDomains: ['gov.pl', 'example.com'],   // optional, up to 100
          contextSize: 'low',                          // optional: 'low' | 'medium' | 'high'
          liveAccess: true,                            // optional: external_web_access
          country: 'PL',                               // optional: user_location, never from the visitor
          limits: { perBotPerDay: 200, perVisitorPerDay: 10, perTurn: 2 },
        },
      });

      Without webSearch there is no web search, which is how a bot with regulated content keeps it off. web_search becomes a reserved tool name. The web search tool is OpenAI's hosted one (web_search, never web_search_preview), so webSearch is refused at startup on a provider that has none (ADR-0026), and doctor reports a regional endpoint where hosted tools aren't available (Australia, India and Japan today).

    • when: 'fallback' offers the search only after the documents found nothing:

      • with the bot's own index (search_knowledge, ADR-0025) this is enforced: web_search joins allowed_tools only on the steps after a search_knowledge call in this turn returned no passages. The tool list stays the same on every step, so the prompt cache holds;
      • with an OpenAI vector store (file_search), both searches run inside one response and askdare can't see the first one's results before the model may call the second. There, fallback offers web_search on every step with a rule in the instructions ("search the documents first; search the web only when they have nothing, and say the answer comes from the web"). It is a request to the model, not a guarantee, and the docs say so (settled question 6);
      • without a knowledge base, fallback is refused at startup; the bot says when: 'always'.
    • Citations: the answer's url_citation annotations already become citation { index, title, url } events in openai/citations.ts, through the same http(s) check, so web sources show in the answer's source list as links, and the protocol doesn't change. web_search_call items become tool.status events named web_search; the queries never reach the client. The source list counts as OpenAI's "prominent, clickable" citations, and the [n] markers stay text (settled question 8).

    • Cost: a search costs a call fee and tokens. The token part is reserved like any turn: while a turn may still search, its reservation adds 8,000 input tokens per remaining allowed search, OpenAI's block for the small models and a fair estimate for the rest, and real usage replaces it at the end. The call fee isn't tokens, so it is bounded by count: max_tool_calls is set to perTurn plus one for file_search when the bot has it, and the daily counters are checked before web_search is offered; an exhausted counter takes it out of allowed_tools until the next day. onUsage gets webSearchCalls, so the app can price the fee, and docs/costs.md gets the arithmetic.

    • Privacy: the visitor's question, rewritten by the model, leaves for a web search. docs/privacy.md says so; onInput redaction (ADR-0022) runs before the model reads the message, so it covers the queries too.

    4. Approving a call in the chat

    • Which calls: a tool says so in its definition. approval in defineTool (and so in httpTool and mcpTools) takes a function that writes, from the validated arguments, the one sentence the visitor approves:

      defineTool({
        name: 'book_demo',
        input: z.object({ day: z.string(), time: z.string(), email: z.string() }),
        approval: { summary: (input) => `Book a demo on ${input.day} at ${input.time} for ${input.email}` },
        execute: bookDemo,
      });

      The summary is plain text, at most 200 characters, never Markdown, and shows only what the developer picked. It shows values the model chose, which is the point: the visitor checks them. A summary is required rather than a generic "Allow book_demo?", which tells a visitor nothing (settled question 13).

    • What happens in the turn:

      1. The model calls an approval tool. The server validates the arguments as for any call, does not run the tool, and leaves the call without output. Other calls of the same step run as usual.
      2. It sends tool.approval { messageId, callId, name, summary, handle } and ends the turn. The answer shows the model's text, if it wrote any, and the card.
      3. handle is encrypted with CHAT_SECRET like a form handle (ADR-0031), bound to the bot, the visitor or signed-in user, the conversation, the call ID and a SHA-256 of the arguments as stored, and expires after 10 minutes (settled question 12).
      4. The visitor answers. Approving or declining posts to the turn endpoint, POST /messages, with approval: { handle, approve } in place of message (settled question 9). It is a turn like any other: the same limits, budgets, conversation lock and stream.
      5. The server checks the handle and reads the call's arguments from the stored conversation, never from the request, and checks their hash. Approved: the tool runs with them and its output answers the call. Declined: the call is answered with askdare's fixed {"status":"declined"}. Then the model continues and writes a new answer, so a decline gets a reply too (settled question 10).
    • Only one approval per turn. A second approval call in the same step, or a later step, is answered with {"status":"one_at_a_time"} and doesn't show a card (settled question 11).

    • What the model sees while it waits: nothing; it isn't running. The approval tool's description, sent to the model, ends with a fixed sentence: the visitor approves the call in the chat before it runs, and the output says whether they did.

    • A turn that ends unapproved: if the visitor writes a message instead, or the handle expires, the next turn answers the open call with {"status":"not_approved"} before the visitor's message. Today's repair of a call left without output (ADR-0015, danglingCallId) is the path; for approval tools it writes this output instead of the generic one. A handle used twice, or after its call has an output, answers 409, like a form sent twice.

    • History: a message gets an optional approval: { callId, name, summary, state } rebuilt from the stored call: pending (no output, with a fresh handle while the 10 minutes last), approved (any output but askdare's fixed ones), declined or expired (not_approved). The summary is derived again from the stored arguments with the tool's current approval.summary, as ui payloads are.

    • The default UI: a primitive ToolApproval (part tool-approval, with buttons in parts approve and decline, data-state), shown under the answer's text in the default skin, with the summary as the group's label. Its texts are approval.approve, approval.decline, approval.approved, approval.declined and approval.expired, in the bot's dictionary per language. The buttons are disabled while a turn runs and once answered. The iframe renders the same primitive, so approval works in the script-tag widget too, unlike tool cards.

    • The client: ChatMessage.approval, set by the reducer, and actions.approve(handle, approve), which runs the store's existing send path with a different body. The parts that read the stream don't change.

    Size. Measured on main by removing the closest feature, the handoff's client side (its event, reducer case, action and two primitives): it costs 141 B in the headless case and 272 B in the React entry (gzipped, the same script). Approval has the same pieces, with a larger event (four fields), a history field and a card with two buttons and four states, and its action reuses the send path. The estimate:

    • headless case: about +200 B (+150 to +250);
    • React entry: about +500 B in all (+350 to +650), the headless part included;
    • texts come with the bot's public configuration, so they cost the bundles nothing.

    That doesn't fit the 86 B and 501 B left. 0.8-b1 must free at least 300 B in the headless case and 900 B in the React entry first, which keeps about 100 B and 400 B of headroom for marked patches (ADR-0028). b1's targets, 600 B and 1,536 B, cover it. If b1 falls short, the approval task stops and a budget ADR decides; it doesn't raise a budget on its own. The implementing task measures again and writes the real numbers into this ADR.

    5. Limits and logs for every remote call

    • Per turn: limits.remoteCallsPerTurn (default 5) counts httpTool and MCP calls in one turn; past it, a call fails with askdare's text, as the step limit does. Web search has its own perTurn.
    • Per day: limits.remoteCalls: { perBotPerDay: 1_000, perVisitorPerDay: 100 } in the existing rate-limit store (memory or Upstash), keyed as handoff limits are (ADR-0030, decision 7), and web search's own counters (decision 3). A call is counted when it starts, and a failed call stays counted. When a bot's daily count runs out, onError gets one report a day, without IPs.
    • Logs and hooks: askdare logs no arguments, results, filled URLs (a path can hold an email), headers, MCP output or search queries. The tool calls in onUsage (ChatToolCallReport) keep name, durationMs and outcome and gain kind (function, http, mcp, web_search) and, for HTTP, the status code. Errors are reported by class name and status code only, never the remote server's text.

    6. Order of building, one task each

    httpTool ──┐                          (core, no protocol change)
    web_search ┴─→ approval (after b1) ─→ remote MCP add-on
    
    1. httpTool with the limits and logs of decision 5: server-only, no protocol change. Until approval lands, a non-GET httpTool needs approval: false written out.
    2. web_search, beside it: bot/define-bot.ts and openai/ only.
    3. Approving a call, after 0.8-b1: defineTool, the protocol, chat/* and the React primitives (the 0.8 hot files).
    4. Remote MCP last: a new add-on that uses the limits and, for tools that write, the approval.

    bot/define-bot.ts takes model settings (ADR-0036), prompt versions (ADR-0039) and then webSearch, in that order, as ROADMAP.md plans.

    As built in 0.8-t1

    Amended on 2026-11-30 (task t1, httpTool and the remote call limits), where the code differs from or adds to decisions 2 and 5:

    • How a tool says it is remote: a public kind on defineTool and Tool, 'function' | 'http' | 'mcp' (ToolKind, default function). httpTool sets http; the MCP add-on (0.8-t4) sets mcp through defineTool({ kind: 'mcp' }), so it needs nothing internal. http and mcp calls count against the remote call limits, and their failures are logged by error class only. Any defineTool that calls a server itself may say kind: 'http'. For z1: ToolKind and Tool.kind are new public API next to httpTool's types (HttpToolDefinition, HttpToolMethod, HttpToolQueryValue) and RemoteCallLimits.
    • The HTTP status reaches the usage report through an internal symbol on the tool httpTool builds, not through execute. Called directly, an httpTool's execute returns the shaped body or throws an error that names the outcome and status only.
    • Decision 2, the template: besides the rules above, the template may have no credentials, query, fragment, backslash or whitespace, and its path must be written as a URL keeps it (no empty, . or .. segments, nothing that needs encoding), so the filled URL is compared with what the URL parser makes of it. http: works for localhost, 127.0.0.1 and [::1], outside production. A placeholder may also name an enum or literal field; not a nullable one. A value with /, \ or % fails the call as . and .. do (the security review's hardening): encoded, it would stay in its segment for askdare, but a server or proxy that decodes the path before routing it would read more segments, or .., into it.
    • Decision 2, the response: a 204 No Content or 205 Reset Content counts, with null as the body, since a DELETE often answers with one. query, headers, body and response may be async; a response that throws fails the call, and the report keeps the status. A 2xx JSON body that doesn't parse fails as http_error with its status; a body over maxResponseBytes fails with the tool's "too much data" text. The request is sent with cache: 'no-store', so a framework's fetch cache never answers one visitor with another's result.
    • Decision 2, approval: approval on httpTool takes only false until 0.8-t3 adds the approval of decision 4.
    • Decision 5, the counts: limits.remoteCalls.perTurn is counted in the turn; the daily counters per visitor or user, per IP (both perVisitorPerDay) and per bot are taken when the call starts, after its arguments were validated, and refunded together when one refuses it, as handoff's are. A call refused by the turn's limit takes nothing from the day. The console's playground counts like a visitor; askdare eval counts against the bot's daily count only (ADR-0035, decision 4). A rate-limit store that fails refuses the call. The kill switch refuses every remote call.
    • Decision 5, the report: ChatToolCallReport.kind is required (every report since 0.8 has it) and status is set for http calls whose server answered, failed ones included.

    As built in 0.8-t2

    Written at the release (task y1, 2026-12-01) from t2's hand-over, where web search as built differs from or adds to decision 3:

    • Where it lives: webSearch in defineBot with its own limits (perTurn, perVisitorPerDay, perBotPerDay), not in BotLimits; the types are WebSearchConfig and WebSearchLimits. fallback on a bot without knowledge is a setup error, and web_search is refused as a tool name.
    • The report: web searches aren't function calls, but they join onUsage's tools with kind: 'web_search' (name, duration and outcome, never the query), and ChatUsageReport.webSearchCalls counts the searches OpenAI billed. The admin records don't carry the count, so the dashboard's costs leave the search fees out.
    • doctor's regional check names four endpoints without hosted web search on 2026-11-30: Australia, India, Japan and, new since this ADR was written, the United Arab Emirates.
    • The widget shows a search as any tool's status (status.tool, "Using web_search…"); a text of its own, such as "Searching the web…", needs the chat's texts and is left for later.
    • Not verified live (the smoke project had no credit): { type: 'web_search' } inside allowed_tools on the fallback's later steps, max_tool_calls bounding the searches, and the stream's shape. Unit tests use streams built from the web search guide; src/openai/web-search.smoke.ts records the real fixture (testing/fixtures/web-search.sse) with SMOKE_RECORD=1.
    • Checked live at the release (y1, 2026-12-01, gpt-6-luna): web-search.smoke.ts passed: the first step offered only search_knowledge, which found nothing; the second offered web_search with max_tool_calls: 1, which OpenAI accepted and kept to (one search with two queries, billed once), and the answer cited the pages as url_citations. The step's stream is recorded in testing/fixtures/web-search.sse (queries kept, safety identifier redacted) and replayed by recorded.test.ts in both conversation modes.

    As built in 0.8-t3

    Amended on 2026-11-30 (task t3, approving a call), where the code differs from or adds to decisions 2 and 4:

    • The API: approval in defineTool is { summary }, false or absent (ToolApproval, and Tool.approval). httpTool takes the same; a method other than GET needs one of the two, { summary } or false, and is refused at startup with neither. This replaces t1's interim "approval: false required"; a GET may ask for approval too. The MCP add-on (0.8-t4) passes approval through defineTool.
    • The summary is written from the validated arguments, then whitespace runs (line breaks included) become one space and control and format characters (bidi overrides, zero-width marks) go; what is left must be 1 to 200 characters (code points). A summary that throws or breaks that fails the call with askdare's "The tool failed.", logged by the tool's name only, never with the summary or the arguments. The browser checks the rule again (isApprovalSummary, shared with the server's schemas).
    • Which call becomes the card: of a step's calls of approval tools, the first whose arguments fit and whose summary can be written. Earlier ones that fail are answered with their error; every later one, in the same step, gets one_at_a_time. When its handle can't be issued, the card's call gets askdare's {"status":"approval_unavailable"} and still counts as the turn's card, so later calls get one_at_a_time too. The history picks the card the same way, from the stored calls, and shows none for approval_unavailable, so a reload shows what the turn showed. One card per turn means one per answer: the turn that answers a card may show a new one.
    • Ending the turn: the step's other calls run, the forms of the step go out, and the step is stored before the card is sent: an item store records it with the other calls' outputs, an OpenAI conversation gets those outputs appended (as an answered suggest_replies is). The waiting call shows no tool.status; tool.approval is the answer's last event before message.end. The asking answer offers no reply options and gets no rating handle (it is a question), and the history doesn't rate it either.
    • The handle is its own token type (askdare-approval+jwt), bound to the bot, the visitor (its subject) or signed-in user (identityKey), the conversation, the call, the tool's name and the SHA-256 of the stored arguments. The 10 minutes start when the card is issued: the limits store keeps a 10-minute window per call (ask:ao:<pseudonym>), and a reload's handle lives only for what is left of it. Without the window (an in-memory store on another instance, a store that failed), the history shows the card as expired.
    • The answer is POST /messages with approval and an empty text, without attachments, and with the conversation's resume token. Before the stream starts, the server verifies the handle (404 for a forged, expired or foreign one, or one of another conversation), applies the history's rate limit (the answers it refuses never reach the turn's limits, and each reads the store), reads the conversation's latest 100 items for the call (404 when it isn't there, its name differs or its arguments' hash doesn't match; 409 with the key error.approvalAnswered when it has an output), then takes a one-time claim in the limits store (ask:ac:<pseudonym>, 11 minutes; 409 when taken), then the turn's usual limits. A turn that ends before it answered the call (a lock, a failure, a visitor who left) gives the claim back, so the card can be answered again.
    • One turn at a time: a bot with an approval tool takes the conversation lock that output checks use (ADR-0022) for every turn, so a message can't close a call while an answer to it runs, and two answers can't interleave.
    • In the turn, the answer stores no visitor message. An item store opens the turn by appending the call's output, at the version it read; an OpenAI conversation gets it as the request's input. Approved, the tool runs through the same path as any call (timeout, remote call limits, untrusted wrapping, tool.status, its ui and replies under the new answer); declined, the output is {"status":"declined"}. A visitor message instead: an item store appends {"status":"not_approved"} for each approval call still waiting in its window before the message; an OpenAI conversation answers it in the repair path of a call left without output, which reads the conversation's latest 50 items to tell an approval call from an interrupted one.
    • The history splits a turn at the card's output: the card stays on the answer that asked (or on an answer with empty text and the call's item ID, when the model wrote nothing before the call), and the answer after the visitor's answer is a message of its own, with the approved call's cards and options. approved is any output but askdare's declined and not_approved, the tool's failures included.
    • With output checks, tool.approval is held with the answer and dropped when the answer is replaced or withheld, so a card only shows under an answer the checks passed as it was; the history agrees.
    • The client: actions.approve(handle, approve) runs the store's send path with the answer instead of a message, and shows the card's answer at once. A 404 before the next answer starts marks the card expired; a 409 (error.approvalAnswered) keeps what the visitor chose; another failure puts it back to pending. A card still waiting when the next answer starts is marked expired, as the server answers it; a message the server refuses leaves it waiting. No message.sent event fires for an answer to a card; message.received does for the bot's next answer.
    • Elsewhere: in the console's playground the turn ends at the card with a placeholder handle, and the card shows read-only, like a form there. askdare eval does the same and counts the requested call in tools (ADR-0035, "As built in 0.8-t3").
    • Size, measured with scripts/react-size.mjs and CI's zlib (Node 24): the headless case went from 11,675 to 11,996 bytes gzipped (+321 B; 292 of 12,288 left), the React entry from 33,221 to 33,747 (+526 B; 1,069 of 34,816 left) and the embed case from 12,438 to 12,759 (+321 B). The React entry landed on the estimate; the headless case went past it (+200, at most +250 estimated), because the browser checks the summary's rule and the history's card like the event's, and the next answer marks a waiting card expired. It fits within the room 0.8-b1 made, with about 290 B left for the headless case, so no budget changes.
    • Not checked live (the smoke project had no credit): that OpenAI accepts a developer note (output checks) between a call and its output in a conversation, and the order of items when the answer is sent. If the model call after an approved tool fails before OpenAI stored its input, the tool ran but its output isn't in the conversation; the next message then tells the model it wasn't approved. An item store doesn't have this gap: it stores the output before the model call, under the conversation lock. Transcripts and admin records show an answer to a card as a turn with an empty input; marking them is a follow-up.
    • Checked live at the release (y1, 2026-12-01, gpt-6-luna, the site run locally with openaiConversations()): book_call's card answered with Approve (the tool ran, the next answer confirmed it), Decline (the model answered that it didn't book), and a typed message instead (the card turned expired, the message got its answer); a reload showed the same three states from history. With a temporary onOutput that held an answer ending at a card, the answer and its card were withheld, and the next message got a normal answer: OpenAI accepted the developer note between the open call and its not_approved output, with no 400.

    As built in 0.8-t4

    Amended on 2026-11-30 (task t4, the MCP add-on), where the code differs from or adds to decisions 1 and 5:

    • The API: mcpTools({ server, url, headers, allow, timeoutMs }) returns one Tool per allow entry. An entry is a name or { name, fingerprint?, approval? }, and approval is { summary: (input) => string } or false, as settled with the maintainer on 2026-11-30: the decision's approval: true had no place for the summary decision 4 requires. A tool that needs approval (the server doesn't say readOnlyHint: true) and has neither is left out of every turn, reported to onError and warned about by doctor. A summary in allow means approval for every call, even of a tool the server calls read-only. server is at most 32 characters; tool names with characters other than [A-Za-z0-9_-] can't be allowed, since the model's tool names can't hold them.
    • The SDK is @modelcontextprotocol/client 2.4.0, pinned: the client package of the SDK's version 2, which splits client and server. @modelcontextprotocol/sdk 1.x would have pulled in Express, Hono and the server's other dependencies. The client brings @modelcontextprotocol/core, zod, jose (already in core's tree), and cross-spawn, eventsource, eventsource-parser and pkce-challenge for stdio, the old SSE transport and OAuth, which askdare doesn't use. Its two JSON Schema validators, Ajv and @cfworker/json-schema, are bundled in its build; askdare uses @cfworker/json-schema, which interprets a schema instead of compiling it to code and fetches no remote $ref. The tests run the SDK's server package (@modelcontextprotocol/server, a dev dependency) on a loopback port.
    • Core's hooks (minor changeset): defineTool takes load(context), run before each turn by streamTurn (at most 6 s, a little more than the listing's 5 s), whose LoadedTool (description, JSON Schema, strict, and the Zod schema that checks the arguments) replaces the tool's description and input for that turn, the compaction after it included; a tool that loads none sits the turn out, but still counts for the rule on wrapped results and for closing a call that waited for approval (the code review's fix), since its earlier calls are in the conversation. defineTool also takes diagnose(signal), whose ToolChecks doctor shows once per function for a bot, failures first when the report's 20 checks per bot would be exceeded. A tool of kind: 'mcp' always has its results wrapped, and the matching rule joins the instructions. LoadedTool, ToolLoadContext and ToolCheck are new public types (for z1). The only change to a hot file is one hunk in server/handler.ts's doctor report, in its own commit.
    • Connections: each listing and each call opens a connection and closes it after, so an MCP session is never shared and one visitor's headers never carry another's call. A listing is shared by every visitor, so headers gets { operation: 'list' } without a visitor; a call gets { operation: 'call', tool, botId, visitorId, locale, identity, source }. Headers the transport sets (content-type, accept, host, mcp-session-id, mcp-protocol-version and the like) are refused. Redirects fail the request (redirect: 'error'), requests skip any fetch cache, and each response is read up to 1 MB. The client declares no capabilities and turns off the SDK's automatic answers to input requests.
    • Listing: cached per mcpTools call, bounded at 5 s as a whole (headers included), and at most 32 pages; after a failure the server's tools sit out turns for 30 seconds before the next try, so turns don't wait on a server that is down. onError hears about a failure once until a listing succeeds, and about allowed tools that are missing or left out once per listing. A description over 4,000 characters, or a schema over 16,000 characters of JSON, leaves the tool out, since both sit in every turn's prompt.
    • Strict mode: a schema goes to the model with strict: true only when every object is closed with all its properties required and it uses only type, properties, required, additionalProperties, items, enum, description, anyOf, $defs and local $refs (the guide's supported subset; title and const aren't in it), at most 5 levels deep; anything else goes with strict: false. The $schema keyword is dropped from the copy the model gets.
    • Results: the model gets { text, structuredContent, omittedContent }: the text blocks joined, the structured content as the server sent it, and how many other blocks were dropped.
    • Fingerprints are sha256: and 32 hex digits (128 bits) of the SHA-256 of the canonical JSON of the tool's name, description, input schema and readOnlyHint, what the model sees and what decides approval. Beyond decision 1's doctor warning, a tool whose pinned fingerprint no longer matches sits out every turn until it is pinned again, as a pin is meant to stop a changed definition from reaching the model.
    • doctor: per server, mcp.reachable (connect, initialize and list within 5 s, failing otherwise), mcp.allowed (a warning naming the missing tools), mcp.changed (a warning naming the changed ones), one warning for tools left out with why, and the fingerprints, four per line.
    • Not checked live: against a third-party MCP server, and OpenAI's acceptance of the schemas real servers list with strict: false; a schema the API refuses would fail the bot's turns until the tool is taken out of allow.
    • Checked at the release (y1, 2026-12-01): src/mcp.smoke.ts listed DeepWiki's public server (https://mcp.deepwiki.com/mcp, Streamable HTTP, three tools), passed doctor's checks, printed the fingerprints and loaded read_wiki_structure and read_wiki_contents as a turn does. The turn on a real model, and with it OpenAI accepting the listed schemas, waits for the funded run in tasks/0.8-y1-release.md.
    • And with a real model (y1, 2026-12-01, gpt-6-luna): a turn asked about a repository's DeepWiki page, the model called smoke__read_wiki_structure, the call succeeded and the turn completed, so OpenAI accepted the server's listed schema.

    As built in 0.8-z1 (the API review)

    Amended on 2026-11-30 (task z1), as the maintainer settled before 0.8.0 shipped:

    • Decision 5, the names: the per-turn limit is limits.remoteCalls.perTurn, beside perBotPerDay and perVisitorPerDay in RemoteCallLimits, so the remote call limits are named as webSearch.limits are. t1 built it as limits.remoteCallsPerTurn, which never shipped, so there is no alias. Default and range are unchanged (5, 0 to 50).
    • Decision 4, the MCP add-on's approval: McpAllowedTool.approval is core's ToolApproval (with the arguments as Readonly<Record<string, unknown>>), exported from @boldare/askdare; the add-on's own McpApproval is gone.
    • Decision 1, fingerprints: their format (sha256: and 32 hex digits, over the name, description, input schema and readOnlyHint) is public API (ADR-0006), since apps pin them in allow: changing it is a breaking change.

    As built in 0.8.x: the last step says why

    Amended on 2026-12-04, after the daily live smoke failed from 2026-12-01 with no change to askdare's code (model behaviour drift at OpenAI, gpt-6.1-terra):

    • The loop: a bot with handoff, a model form and a vector store, on its last step, sends allowed_tools with only file_search. Asked for a person or an offer, the model searched the documents about 14 times in one response, spent its max_output_tokens on reasoning and ended without text. allowed_tools restricts the calls without telling the model why.
    • Decision 3, max_tool_calls, doesn't bound it: the reference says calls past the maximum are "ignored", not refused. Sending max_tool_calls: 2 shrank the input but the model kept trying (about 8 searches still visible) and the turn still ended at max_output_tokens. maxToolCalls stays as it was: it bounds the web search fee, which is what it is for.
    • The fix: a last step that takes away functions the model could call before ends the instructions with one more rule (lastStepRule in openai/tools.ts): no function can be called now, write the answer, say that a handover or a form can't happen in this answer and that the visitor can ask again, and, while a hosted search is left, search only for facts. Measured: 3.4k input tokens instead of about 22k, about 160 output tokens, 10 s instead of 45–50 s, with the price from the documents and the sentence about the person and the form.
    • The prompt cache: every other step keeps its instructions as they were, and the rule goes last, after everything the steps share. On models before GPT-6.2 the instructions start the prefix, so a last step that follows earlier steps misses the cache from there on, once per turn that reaches it; a bot with maxSteps: 1 sends the rule on every turn, so its prefix stays stable. From GPT-6.2 the API puts top-level instructions after the input (keep the prefix unchanged), so nothing changes in the prefix at all. A developer message appended to input would keep the prefix on every model, but with a conversation store at OpenAI it would be stored in the conversation and read back on later turns, where the functions are available again.

    Consequences

    • New public API (ADR-0006, when each part ships):
      • httpTool and its option types;
      • webSearch in defineBot, the reserved tool name web_search, webSearchCalls in the usage report;
      • approval in defineTool; the tool.approval event, the approval field of POST /messages and of the history response (additive in protocol version 1); ChatMessage.approval and actions.approve; the ToolApproval primitive, its parts and the approval.* texts;
      • limits.remoteCalls (perTurn, perBotPerDay, perVisitorPerDay), and kind and status in ChatToolCallReport;
      • @boldare/askdare-mcp with mcpTools, and three doctor checks.
    • Tools with side effects become possible for an anonymous bot, with the visitor's approval. Approval is consent, not authentication: the tool still decides whose account it acts on from the verified identity, never from the arguments, and the docs say so. THREAT_MODEL.md T6 and T11 change their "not supported yet" when approval ships.
    • A turn can end in the middle of a step for the first time, with a call left open until the visitor answers. The repair path for open calls becomes part of normal operation, not only of aborted turns.
    • Approving or declining costs a model call. It counts against the visitor's message limits like a typed message.
    • MCP costs an add-on and a dependency, and the app's server makes the calls, so the MCP server must be reachable from it (not from OpenAI). It works on every provider path.
    • A web search costs about 1 cent plus up to 8,000 input tokens. With the defaults, at most 200 searches a day per bot, about $2 in fees plus tokens.
    • Web search sends the visitor's question, rewritten, to a search provider. It is off by default; turning it on is the bot owner's decision, for the privacy notice.
    • The fallback of web search is only a request to the model on vector-store bots; it is enforced only with the bot's own index.
    • The React entry and the headless case grow by about 500 B and 200 B, after b1 has made room.

    Settled with the maintainer (2026-11-30)

    The first draft left these questions open, each with a recommendation. The maintainer accepted all fifteen as recommended ("Yes, accept all"), and the decisions above are written that way.

    1. MCP through OpenAI's hosted tool, or askdare as the client? Settled: askdare as the client (decision 1). The hosted tool is less code, but takes the timeout, output cap, untrusted wrapper, limits and approval out of askdare's hands and works only at OpenAI.
    2. MCP in an add-on with the official SDK, or a small client in core? Settled: the add-on @boldare/askdare-mcp with @modelcontextprotocol/sdk. Core stays without a dependency, and the protocol's session and transport details aren't ours to maintain.
    3. MCP tool definitions from the server at runtime, or pinned in the app's code? Settled: from the server with a required allowlist, a 10-minute cache and an optional fingerprint per tool that doctor compares. Pinning whole definitions in code duplicates the server and goes stale silently in the other direction.
    4. Which MCP tools need approval by default? Settled: all but those the server marks readOnlyHint: true, overridable per tool in allow.
    5. Does a non-GET httpTool need approval by default? Settled: yes, unless the tool writes approval: false.
    6. when: 'fallback' on a vector-store bot: a rule in the instructions only, or not offered? Settled: the rule, documented as a request to the model. Enforcing it would take a second response after an answer was already streamed.
    7. Web search off by default? Settled: yes, a bot turns it on, and when defaults to fallback.
    8. Is the source list enough for OpenAI's "prominent, clickable" citations? Settled: yes for now, since every web source shows as a link right under the answer; the [n] markers stay text. Linking the markers costs React bytes; we do it if OpenAI's terms say the list isn't enough.
    9. Answer an approval through POST /messages, or a new endpoint? Settled: POST /messages with an approval field. It reuses the stream, the limits, the lock and the client's send path, which is why the approval fits in about 200 headless bytes. A separate endpoint would duplicate all four.
    10. Does a decline run a model call? Settled: yes, so the bot replies ("All right, I didn't book it") and the transcript reads naturally. Ending without a model call is cheaper but leaves a call output without an answer and needs a second response shape.
    11. One approval per turn, or several cards? Settled: one. Several cards in one answer make the visitor approve things they didn't read, and the state and UI stay simple.
    12. How long is an approval handle valid? Settled: 10 minutes. An action approved much later may no longer be what the visitor wants (a slot taken, a price changed); the model can ask again.
    13. A required approval.summary, or a generic card? Settled: required. A visitor can only consent to what the card says.
    14. The default limits: 5 remote calls per turn, 1,000 per bot and 100 per visitor a day; web search 2 per turn, 200 per bot and 10 per visitor a day. Settled as written; a bot sets its own.
    15. The order: httpTool and web search side by side, then approval after b1, then MCP. Settled as in decision 6.

    Alternatives considered

    • OpenAI's hosted MCP tool, with its require_approval mapped onto the visitor's card. Less code and no dependency, but see settled question 1. The approval would also arrive as an mcp_approval_request inside a response, a second approval mechanism beside decision 4's.
    • An MCP proxy or gateway in front of every server, run by the app. That is the app's choice, and mcpTools works with one; askdare shouldn't require it.
    • httpTool with a free URL argument and a host allowlist. The model would build URLs, and every encoding trick (.., %2F, @, IPv6 literals, redirects) would need its own rule. A fixed template with filled values removes the class.
    • Web search always on, with a rule in the instructions. Cheaper to build, but every question could cost a search fee and send the question to the web, including on bots with regulated content.
    • Searching the web before the turn, when the index finds nothing. It would search with the visitor's raw words, without the model's reading of the question, and pay a search on every miss, including small talk.
    • Approval without a model call: the server runs the tool and shows the result as a card. The model would never see the result and couldn't answer about it.
    • A generic "confirm" reply option (ADR-0015) where the visitor types "yes". The model would have to decide whether "yes" approves the call, and a prompt injection could too; a sealed handle bound to the call and its arguments leaves no doubt.
    • Approval handled by the app's execute (for example, a confirmation email). Still possible and sometimes better for high-value actions; decision 4 covers the common case in the chat.