Skip to content

Extension Library: URL MCP servers with stateful sessions and OAuth on remote runtimes, verified live #3824

Done

Description

@integry

Goal

URL (kind: "https") MCP servers from the Extension Library work for agents on every runtime (Docker, Sprites, Fly Machines) with stateless and stateful servers, and with no auth, Bearer and OAuth. The Fly smoke workflow proves each combination live.

Current state (epic 3758-epic-runtime-abstraction-sc0, after #3818)

  • The URL-server gateway (packages/core/src/extensions/mcpGateway.ts) forwards each JSON-RPC call independently. It says "Stateful upstream MCP is intentionally unsupported": no upstream Mcp-Session-Id, cookies or server-to-client requests.
  • So stateful (2025-era) servers fail. https://mcptest.io/fixtures/echo/mcp answers tools/call with HTTP 400, "Mcp-Session-Id header is required; send initialize first, or server/discover for the stateless revision".
  • Stateless servers already answer tools/list without a session: https://mcp.deepwiki.com/mcp and https://learn.microsoft.com/api/mcp.
  • OAuth (authentication: "oauth", scopes, clientId, token refresh through Core) is implemented, but it has never been tested live, and never from a Sprite or a Fly Machine.
  • The smoke workflow skips URL servers: urlServers=0, and the step summary says "URL MCP server: skipped".

Required

1. Stateful upstream sessions in the gateway

  • The gateway owns the upstream session. It forwards initialize (and notifications/initialized), keeps the returned Mcp-Session-Id on the gateway side, keyed by (run grant, server), and sends it on later calls. It never returns it to the agent. The agent-facing side stays as it is today, so nothing upstream can widen a run's grant.
  • Pin the connection per upstream session (keep-alive agent pinned to the already-vetted address). The mcptest echo fixture loses the session when a request arrives on a new connection ("Session not found"), and other servers with sticky sessions behave the same way.
  • Handle upstream 404 "Session not found" by re-initializing once, then replaying the call (idempotent read tools only; for write-capability servers, fail the call instead).
  • Supporting both protocol eras: on the 2025 revision, sessions as above. On the stateless 2026-07-28 revision, server/discover with no session. Pick per server from the upstream's answer, not from configuration.
  • End of run (grant revoked or expired): DELETE each upstream session, best effort, and drop it from memory. Sessions never outlive the grant. Cap sessions per grant and in total, with idle expiry.
  • Server-to-client requests (sampling, elicitation, roots) stay unsupported: answer them with a JSON-RPC error and don't relay them to the agent. Upstream notifications on the call's own SSE stream are fine to drop. Keep the existing per-tool allowlist, capability (read/write) checks, egress policy, byte accounting and OAuth token redaction unchanged.
  • Response formats: both application/json and text/event-stream, with the existing size limits.

2. OAuth, verified end to end

3. Live coverage in .github/workflows/fly-e2e.yml (extensions mode)

The agent's output file gets one line per server, each with a run-unique token where the server can echo one:

  • Stateful, no auth: https://mcptest.io/fixtures/echo/mcp, tool echo with argument message (not text). Expected line: the exact echoed URL-STATEFUL-OK-<run>.
  • Stateless, no auth: one stateless public server, either DeepWiki or Microsoft Learn (tools/list without a session works for both). The check is that the tool call succeeds (e.g. a non-empty result), since the content isn't deterministic. Alternatively, mcptest echo on its stateless 2026 revision, if the gateway negotiates it.
  • Bearer: https://mcptest.io/fixtures/auth-bearer/mcp, with the fixture's published token stored as the server's Bearer secret. Also check that a wrong token gives a clean tool error, not a hang.
  • OAuth: mcptest.io has no OAuth fixture, so the smoke run brings its own. A minimal OAuth 2.1 authorization server plus MCP endpoint (PKCE, protected resource metadata, auto-approving consent, a deterministic echo, an access-token lifetime of about 60 s to force a refresh mid-run).
    • Host it on something public over HTTPS that the run creates and tears down. Stay within the Fly Free Plan: 3 Machines per org, stopped ones included (the smoke run already uses the ProPR Machine and the agent Machines). A Sprite with its public URL, or the ProPR app's own Machine count, are the options to weigh. Delete it in the teardown step even on failure.
    • The workflow drives the sign-in through the same API that Settings → Extensions uses, with no browser.
  • Run the extensions mode on both agent_runtime=sprites and agent_runtime=fly-machines. The step summary lists urlServers=4 and each server's session mode (stateful/stateless), auth mode, and number of token refreshes.

4. Settings and docs

  • Settings → Extensions shows, after "Check", whether a URL server is stateful or stateless, and which auth it uses. The "intentionally unsupported" note in the docs is replaced with the new behaviour and its limits (no sampling or elicitation).

Acceptance

  • Unit tests:
    • a gateway session is created, reused, re-initialized after a 404, and deleted at grant end;
    • nothing upstream can reach the agent (no session id, no server-to-client requests);
    • write servers are never replayed;
    • both eras;
    • OAuth refresh and retry on 401.
  • The smoke extensions mode passes on Sprites and on Fly Machines with all four URL servers. The agent's file has the stateful echo token and the OAuth echo token. Teardown is clean: no leftover apps, Sprites or fixture branches.
  • Evidence (run links, each server's session and auth mode, refresh count) goes in the PR description.

Activity

  1. propr-dev commented on Nov 26, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3824/claude-opus-5-5-extension-library-url-mcp-20261126-2350-bz1
    • Base Branch: 3758-epic-runtime-abstraction-sc0
    • Worktree: issue-3824-20261126-2350-claude-opus-5-5-bz1

    🔍 Track Task Execution

  2. integry commented on Dec 1, 2026

    @integry
    OwnerAuthor

    Done in #3826, which merged into the runtime epic; the epic merged into main with #3774 and ships in 0.9.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions