Skip to content

Share one server between agents over HTTP, with a control lease - #16

Merged
Tom-R-Main merged 1 commit into
mainfrom
improve/http-lease
Sep 24, 2026
Merged

Tom-R-Main merged 1 commit into
mainfrom
improve/http-lease

Conversation

@Tom-R-Main

Copy link
Copy Markdown
Owner

Stacked on #15.

Why: Claude and Codex each ran their own stdio server with their own OBS connection, so I had to stay off OBS by hand while Codex recorded. Now both can connect to one server, and whoever is recording holds control.

What

  • OBS_MCP_HTTP_PORT serves Streamable HTTP at http://127.0.0.1:<port>/mcp (0 picks a free port), using the SDK's createMcpHandler and a small node:http adapter (no new dependency).
    • Listens on 127.0.0.1 only.
    • Rejects Host or Origin headers that aren't localhost (the SDK's DNS-rebinding helpers).
    • OBS_MCP_HTTP_TOKEN requires a bearer token, compared in constant time.
    • Other paths get 404.
  • Resource notifications over HTTP go through the handler's event bus once (forwardResourceEvents). The stateless per-request servers don't attach OBS listeners, which would leak.
  • OBS_MCP_DYNAMIC_TOOLSETS is ignored over HTTP, with a log line: stateless requests can't keep per-session groups.
  • Control lease:
    • obs-claim-control (minutes, reason) gives the calling client control. Tools that change OBS then refuse other clients' calls.
    • Read-only tools and stopping (obs-stop-record/-stream/-output/…, obs-take-stop) always work.
    • obs-release-control and obs-control-status manage it. It expires on its own.
    • obs-take-start claims control for the length of the take; obs-take-stop releases it.
    • Clients are told apart by the name in the request envelope (2026) or from initialize (2025). Two sessions of the same client share control.
  • Tool counts: 171 total; core 93; core read-only 42.

Tests

  • npm run check passes: 186 unit, 14 e2e.
  • The lease runs through an in-process HTTP handler with two named clients:
    • only the holder may change OBS; reads, status, and refused claim/release for others
    • stopping is never blocked
    • expiry
    • automatic claim for a take
  • New http.e2e.test.ts against the compiled server:
    • two agents share one OBS connection, with the lease enforced
    • a foreign Host header gets 403; a missing or wrong token gets 401; another path gets 404; the right token works

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vjn8uBEa4mJshaQU3pFuqX

OBS_MCP_HTTP_PORT serves Streamable HTTP on 127.0.0.1 through the SDK's
createMcpHandler and a small node:http adapter. Host and Origin must be
localhost (DNS rebinding protection), and OBS_MCP_HTTP_TOKEN requires a
bearer token. Resource notifications go through the handler's event bus
once, instead of per-request listeners that would leak.

obs-claim-control gives one client control of OBS for a set time: tools
that change OBS refuse other clients' calls, while reading and stopping
outputs always work. obs-release-control and obs-control-status manage it,
and obs-take-start claims control for the length of the take. Clients are
told apart by the name they report.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vjn8uBEa4mJshaQU3pFuqX
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T02:42:49.125201Z 18bcc20 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18bcc206d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools/takes.ts
const { take } = started;
// Other clients sharing this server cannot change OBS until the take stops.
const holder = callerName(server, ctx);
if (claim(client, holder, 240, `recording take ${take.id}`).ok) take.leaseHolder = holder;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Claim control before starting the take

When client A starts a take with no active lease, startTake awaits the preflight, OBS startup, and monitor startup before this claim runs. Client B can claim control during that interval; A will still start recording, this claim then silently returns ok: false, and no leaseHolder is stored, allowing B to modify OBS while the take records and potentially blocking A's subsequent take operations. Reserve control before the asynchronous startup and release it if startup fails.

Useful? React with 👍 / 👎.

Comment thread src/tools/takes.ts
const { take } = started;
// Other clients sharing this server cannot change OBS until the take stops.
const holder = callerName(server, ctx);
if (claim(client, holder, 240, `recording take ${take.id}`).ok) take.leaseHolder = holder;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep automatic control for the full take

For any take lasting longer than four hours, this hard-coded 240-minute lease expires even though the recording and take monitor continue indefinitely. The next lease check removes it, after which another agent can change OBS during the active take, contradicting the tool's promise to hold control until obs-take-stop; the automatic lease should instead remain tied to the take lifecycle or be renewed while the take is active.

Useful? React with 👍 / 👎.

Comment thread src/tools/lease.ts
Comment on lines +93 to +95
return (name: string, config: { annotations?: ToolAnnotations }, callback: (...args: unknown[]) => unknown) => {
if (config.annotations?.readOnlyHint === true || ALWAYS_ALLOWED.has(name)) {
return Reflect.apply(registerTool, target, [name, config, callback]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exempt stop requests sent through generic tools

When a non-holder uses obs-call-request or obs-batch to send StopRecord, StopStream, StopOutput, or another stop request, the wrapper treats the generic tool as an ordinary mutator and rejects it without inspecting its arguments. This breaks the stated guarantee that stopping outputs is always allowed, particularly when tool filtering exposes the protocol escape hatch but not the explicit stop tool; recognize stop-only generic calls while continuing to reject batches containing other mutations.

Useful? React with 👍 / 👎.

@Tom-R-Main
Tom-R-Main changed the base branch from improve/dynamic-toolsets to main September 24, 2026 05:12
@Tom-R-Main
Tom-R-Main merged commit 1bfbe94 into main Sep 24, 2026
4 checks passed
@Tom-R-Main
Tom-R-Main deleted the improve/http-lease branch September 24, 2026 05: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