Skip to content

Support function calling in the local API through MCP - #13

Merged
redacid merged 1 commit into
mainfrom
feat/api-function-calling
Dec 3, 2026
Merged

redacid merged 1 commit into
mainfrom
feat/api-function-calling

Conversation

@redacid

@redacid redacid commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Agents that send tools (SolidCraft, for one) got HTTP 400 tools (function calling) are not supported. This adds native function calling for claude/… and codex/… models.

How

  • A request with tools starts the CLI with one MCP server, client, served by the API itself at /mcp/<random token> and offering exactly the caller's functions. The CLI's own tools stay off.
  • When the model calls a function, the HTTP request is answered with tool_calls (finish_reason: "tool_calls") while the CLI waits on its MCP call.
  • The caller's next request with role: "tool" results (matching tool_call_id) answers those calls; the same process continues.
  • A request whose results match no live session starts a new one from the written-out conversation.
  • Sessions idle for 10 minutes are stopped; at most 8 wait at once; one process runs at most 2 hours.

Per tool

  • Claude Code: --mcp-config + --strict-mcp-config + --allowedTools mcp__client, built-in tools still --tools "".
  • Codex: -c mcp_servers={client={url=…,tool_timeout_sec=3600,default_tools_approval_mode="approve"}} (without approve mode codex exec refuses MCP calls).
  • Gemini CLI: not yet; requests with tools get 400.

Tested

  • make check: 192 tests (new bridge.test.ts: full loop through ApiServer, streaming, restart from transcript, idle stop).
  • Live, real CLIs through ApiServer: Codex called the function and answered with its result (6.3 s, then 2 s); Claude Code (haiku, streaming) the same (3.4 s, then 1.4 s); no sessions left afterwards.
  • Not tested with SolidCraft itself.

Docs: docs/api.md (Function calling), docs-dev/architecture.md, OpenAPI description, README status.

Agents such as SolidCraft send `tools` and got a 400, because the
subscription CLIs answer with text only. The CLIs do support MCP, so a
request with tools now starts the CLI with one MCP server, served by
the API at /mcp/<token>, that offers exactly the caller's functions.
A model's call is returned as OpenAI `tool_calls` while the CLI waits
on its MCP call; the caller's next request with `role: "tool"` results
answers it and the same process carries on. The model uses its native
tool calling, and later steps take a second or two instead of a new
process with the whole conversation.

Claude Code gets --mcp-config with --allowedTools mcp__client (its own
tools stay off); Codex gets the server as its only MCP server with
default_tools_approval_mode="approve", since codex exec never asks.
Idle sessions stop after 10 minutes, at most 8 wait at once, and a
request whose results match no session starts over from the written-out
conversation. Gemini CLI is not wired up yet and answers tools with 400.
@redacid
redacid merged commit 59d605c into main Dec 3, 2026
8 checks passed
redacid pushed a commit that referenced this pull request Dec 3, 2026
Version bump and changelog for function calling in the local API (#13).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant