Skip to content

feat: serve over streamable HTTP with per-request credentials - #38

Open
zvikagart wants to merge 3 commits into
mainfrom
shared-http-server
Open

feat: serve over streamable HTTP with per-request credentials#38
zvikagart wants to merge 3 commits into
mainfrom
shared-http-server

Conversation

@zvikagart

Copy link
Copy Markdown
Contributor

Lets a single server process serve many users, so callers (notably the Code Ocean agent) can run one shared server instead of spawning one subprocess per invocation.

Changes

  • New --transport streamable-http mode (with --host/--port), served with stateless_http=True. stdio remains the default; running the server with only CODEOCEAN_TOKEN and CODEOCEAN_DOMAIN exported from Claude Desktop or Cursor is unchanged.
  • The CodeOcean client is now resolved per request in HTTP mode, from the request's Authorization: Bearer header, via a request-scoped proxy. Tools keep closing over a single client object, so all 26 tool definitions, their names, input schemas and descriptions are untouched.
  • Tool descriptions are read at registration time, before any request exists; the proxy falls back to a placeholder client built from the environment for those reads, which makes no network call.
  • HTTP requests without a usable credential are refused rather than falling back to a server-wide token.
  • Per-token clients are cached so connection pools are reused instead of growing with invocation count.

Add a --transport streamable-http mode that serves many users from one
process, resolving the Code Ocean client from each request's
'Authorization: Bearer <token>' header via a request-scoped client proxy,
so the tool definitions stay untouched. Requests without a token are
refused rather than served with the environment's token. The stdio
transport with CODEOCEAN_TOKEN remains the default and is unchanged.
CopilotAI lite review requested due to automatic review settings August 20, 2026 16:27

CopilotAI 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.

Pull request overview

Adds a new streamable-HTTP transport option so a single codeocean-mcp-server process can serve multiple callers, resolving Code Ocean credentials per request from the HTTP Authorization header while keeping the existing stdio behavior unchanged.

Changes:

  • Introduces --transport streamable-http (plus --host / --port) and runs FastMCP in stateless HTTP mode.
  • Adds a request-scoped CodeOcean client proxy with an LRU cache to reuse connection pools per token.
  • Adds end-to-end tests for per-request credential isolation and updates README usage docs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

FileDescription
tests/test_http_transport.pyAdds E2E coverage for streamable-HTTP, per-request tokens, and tool parity with stdio.
src/codeocean_mcp_server/server.pyAdds CLI parsing and wires streamable-HTTP transport + request-scoped client behavior.
src/codeocean_mcp_server/client.pyImplements per-request token extraction and cached client creation.
README.mdDocuments how to run and call the server over streamable HTTP.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment threadsrc/codeocean_mcp_server/server.py Outdated
Comment threadsrc/codeocean_mcp_server/client.py
Rewrite the Authorization header parse as an explicit scheme guard - the
conditional expression it replaces read as if the scheme check could be
skipped, and a test now covers a token offered under a non-Bearer scheme.
Report only the variables actually required for the chosen transport, so
streamable-HTTP no longer claims CODEOCEAN_TOKEN must be set.
Comment threadsrc/codeocean_mcp_server/server.py Outdated
Comment threadsrc/codeocean_mcp_server/client.py
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@zvikagart
zvikagart requested a review from doronslAugust 21, 2026 09:44
Sign up for freeto 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.

2 participants

@zvikagart