Skip to content

feat(sdk): wire MCP servers into the in-process runtime; share gateway-auth builder#25

Merged
stxkxs merged 1 commit into
mainfrom
feat/sdk-mcp-wiring
Jun 4, 2026
Merged

feat(sdk): wire MCP servers into the in-process runtime; share gateway-auth builder#25
stxkxs merged 1 commit into
mainfrom
feat/sdk-mcp-wiring

Conversation

@stxkxs

@stxkxs stxkxs commented Jun 4, 2026

Copy link
Copy Markdown
Member

The "more flexible" follow-up from the native-vs-hand-rolled audit. See the commit message for full detail.

Why

The sdk / sdk-k8s runtime wired no MCP servers at all — only claude-cli did. So sdk-mode roles silently lost github/linear/etc. and couldn't run the github-MCP commit flow, making sdk a degraded transport. This makes it first-class.

What

  • src/mcp.ts buildHttpMcpServers — single source for the {type:'http',url,headers} MCP map that both Claude Code's --mcp-config and the Agent SDK's mcpServers option accept; owns the gateway-bearer injection + FAB_MCP_STRICT policy + the GATEWAY_HOSTED set (previously duplicated in claude-cli).
  • sdk runtime passes the role's servers to query() as mcpServers + strictMcpConfig: true (fab's servers only).
  • claude-cli de-duplicated to a thin wrapper over the shared builder (identical output).

Verification

npm run lint / build / format:check clean · npm test 300/300 (+4 buildHttpMcpServers tests).

…teway-auth builder

The flexibility follow-up from the native-vs-hand-rolled audit. The sdk (and
sdk-k8s) runtime ran with NO MCP servers — only claude-cli wired them — so
sdk-mode roles silently lost github/linear/etc. and couldn't run the github-MCP
commit flow, making the sdk transport a degraded, second-class option. This
closes the gap and removes a duplicated gateway-auth code path.

─── Shared HTTP MCP builder (src/mcp.ts) ───

buildHttpMcpServers(serverNames, env) resolves a role's MCP servers into the
{type:'http', url, headers} map that BOTH Claude Code's --mcp-config JSON and
the Agent SDK's `mcpServers` query option accept. It owns the gateway-bearer
injection (MCP_GATEWAY_TOKEN) plus the FAB_MCP_STRICT throw / skip-with-warning
policy, and the GATEWAY_HOSTED set — previously duplicated in claude-cli.

─── sdk runtime now wires MCP (src/runtimes/sdk.ts) ───

runRoleSession builds the role's MCP map and passes it to query() as
`mcpServers` with `strictMcpConfig: true` (fab's servers only, not the user's
ambient ~/.claude config), mirroring claude-cli's --strict-mcp-config. sdk and
sdk-k8s roles now get their declared MCP tools.

─── claude-cli de-duplicated (src/runtimes/claude-cli.ts) ───

buildMcpConfigJson is now a thin wrapper over buildHttpMcpServers: identical
output, one source of gateway-auth truth. Removed its private GATEWAY_HOSTED set
and McpHttpEntry / McpConfigShape interfaces.

─── Tests ───

mcp.test.ts covers buildHttpMcpServers: direct servers (no bearer), gateway
bearer injection, non-strict skip on a missing token, and the FAB_MCP_STRICT
throw. Existing claude-cli tests are unchanged (behavior preserved).

Verified: npm run lint / build / format:check clean; npm test 300/300.

Co-authored-by: stxkxsbot <275011021+stxkxsbot@users.noreply.github.com>
@stxkxs stxkxs marked this pull request as ready for review June 4, 2026 04:22
@stxkxs stxkxs merged commit ebdbbe2 into main Jun 4, 2026
2 checks passed
@stxkxs stxkxs deleted the feat/sdk-mcp-wiring branch June 4, 2026 04:23
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