Skip to content

fix(devframe): return complete connection metadata from dev server handles - #484

Open
SaKaNa-Y wants to merge 13 commits into
devframes:mainfrom
SaKaNa-Y:fix/dev-server-sse-handle
Open

SaKaNa-Y wants to merge 13 commits into
devframes:mainfrom
SaKaNa-Y:fix/dev-server-sse-handle

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

With WebSocket disabled, createDevServer() opens an HTTP listener and then throws before returning the handle needed to close it. With WebSocket and SSE enabled, the handle advertises only WebSocket. HTTP discovery also omits the names of strict JSON methods, so an RPC client can send a Map to a handler that expects JSON.

Return a closable handle for each transport configuration. Both discovery paths read the strict JSON method names from the current RPC registry, including methods registered after startup. Each call to handle.connectionMeta() returns a fresh JSON snapshot, so static configuration values such as URL have the same representation as in HTTP discovery.

For a devframe mounted at /nested/tool/, callers can reach the same MCP route from either descriptor. Same-origin WebSocket and SSE paths follow the same rule. For an endpoint at the mount root, HTTP discovery and the public MCP helper return ./. The handle returns /nested/tool/. When WebSocket uses a dedicated port, resolve its path from the root of that port’s origin.

Source Advertised MCP path Resolve against
handle.connectionMeta() /nested/tool/tools/mcp handle.origin
__connection.json tools/mcp Discovery document URL

Evidence

  • Real WebSocket and SSE calls use both discovery paths. In Chrome, a strict JSON method previously rejected a plain object created in a same-origin iframe. It now accepts the object over either transport and still rejects Map and Date before the handler runs. An unflagged method round-trips the same Map.
  • Before the snapshot fix, initializing MCP through the nested handle returned 404, and reading a handle with a URL in its static configuration threw DataCloneError. The regression tests now initialize MCP through both descriptors and read the same URL string from both. Mutating a handle snapshot leaves subsequent snapshots and HTTP discovery intact.
  • With MCP at the mount root, the public helper previously sent clients to / and initialization returned 404. On this revision, the helper, HTTP discovery and the handle all led to /nested/tool/ and initialization returned 200. For a WebSocket on a dedicated port, following the revised guide connected at /__ws.
  • The lifecycle tests close the SSE-only and HTTP-only handles and verify port reuse. The SSE-only test also verifies registry cleanup.

On 4c4081af, all 105 tests in the six changed test files passed. Documentation lint and ESLint on the edited files passed. With WebSocket disabled, the onReady callback fetched discovery successfully in both SSE-only and HTTP-only configurations. Both descriptors also connected a client from a nested mount to a dedicated WebSocket port at /__ws.

Merge Danger

Door: Two-way. The patch can be reverted without a data migration.

Blast Radius: Live connection discovery and strict JSON serialization. RPC clients using a strict JSON method now reject unsupported values before dispatch. An incorrect path or method list can prevent a connection or select the wrong encoding.

Keep the shared HTTP handle and RPC group when WebSocket is disabled. Return instance connection metadata while retaining transport JSON encoding hints.

Cover SSE-only startup and disposal, returned-descriptor RPC over both transports, nested and renamed routes, and transport-disabled controls.
@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

@SaKaNa-Y is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/devframes/devframe/484?from=github-actions[bot]

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-11-22 07:53 UTC
🔗 head 4c4081a
🤖 automated by pulls.review

{
  "headSha": "4c4081af4808c92cbcf261e05c5eba072b6e2f93",
  "result": {
    "overallSummary": "Fixes `createDevServer()` so it always returns a closable handle with accurate, HTTP-discovery-consistent connection metadata (including strict JSON method names read live from the RPC registry and correct mount-root/sub-path resolution for WebSocket, SSE and MCP), and relaxes strict JSON serialization to accept plain objects from other realms while still rejecting unsupported types like `Map`/`Date`.",
    "groups": [
      {
        "key": "handle-connection-meta",
        "label": "Dev server handle metadata",
        "summary": "Makes `createDevServer()` always return a closable handle (even with WebSocket disabled), aligns `handle.connectionMeta()` snapshots with HTTP discovery (same mount-root `./` resolution, same JSON form for static config), and publishes strict JSON method names from the live RPC registry in both discovery paths.",
        "category": "api",
        "filePaths": [
          "packages/devframe/src/adapters/_shared.ts",
          "packages/devframe/src/adapters/dev.ts",
          "packages/devframe/src/adapters/initiate.ts",
          "packages/devframe/src/node/instance-shell.ts",
          "packages/devframe/src/node/utils.ts"
        ],
        "critical": true,
        "fileNotes": [
          {
            "path": "packages/devframe/src/node/instance-shell.ts",
            "text": "Shared-server tier now also binds when WS is disabled (`wsDisabled || ...`) so a handle/RPC group is returned, and `jsonSerializableMethods` is exposed via a getter that reads the registry lazily on each access.",
            "critical": true
          },
          {
            "path": "packages/devframe/src/adapters/dev.ts",
            "text": "`connectionMeta()` now round-trips through `JSON.parse(JSON.stringify(...))` to match HTTP discovery's representation, and rewrites same-origin websocket/sse/mcp paths relative to `basePath`.",
            "critical": true
          }
        ]
      },
      {
        "key": "strict-json-realms",
        "label": "Strict JSON cross-realm fix",
        "summary": "Fixes `strictJsonStringify` to accept plain objects created in another realm (e.g. a same-origin iframe) by comparing the object's constructor source instead of identity with the local `Object.prototype`, while still rejecting class instances like `Map`/`Date`.",
        "category": "core",
        "filePaths": [
          "packages/devframe/src/rpc/serialization.ts"
        ],
        "critical": true
      },
      {
        "key": "docs",
        "label": "Dev server docs",
        "summary": "Documents the full `StartedServer` shape, the snapshot semantics of `connectionMeta()`, and how to resolve same-origin and dedicated-port WebSocket paths.",
        "category": "docs",
        "filePaths": [
          "docs/content/2.adapters/3.dev.md"
        ]
      },
      {
        "key": "tests",
        "label": "Regression tests",
        "summary": "Adds and updates tests covering the new handle metadata, nested/mount-root MCP initialization through both descriptors, SSE/HTTP-only handle lifecycle and port reuse, late-registered strict JSON methods, and cross-realm JSON validation.",
        "category": "tests",
        "filePaths": [
          "examples/custom-hub-next/tests/next-devframe-hub.test.ts",
          "packages/devframe/src/adapters/__tests__/dev-transports.test.ts",
          "packages/devframe/src/adapters/__tests__/dev.test.ts",
          "packages/devframe/src/adapters/__tests__/initiate.test.ts",
          "packages/devframe/src/rpc/serialization.test.ts",
          "packages/hub/src/node/__tests__/initiate.test.ts"
        ],
        "fileNotes": [
          {
            "path": "packages/devframe/src/adapters/__tests__/dev-transports.test.ts",
            "text": "New end-to-end test file exercising real WebSocket/SSE/HTTP round-trips for the fixed handle behavior: SSE-only lifecycle, mount-root resolution, nested MCP via both descriptors, and static config snapshot equality."
          }
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-22T07:53:24.673Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

Read method flags from the current RPC registry when a client requests the instance descriptor. This gives SSE-only handles and HTTP discovery the same encoding hints as WebSocket handles, including methods registered after startup.
@SaKaNa-Y
SaKaNa-Y force-pushed the fix/dev-server-sse-handle branch from 85e31b1 to 70282fa Compare November 7, 2026 07:53
Return a fresh connection descriptor for each handle call so a viewer can edit its copy without changing HTTP discovery. Resolve local RPC paths from the mount so viewers can connect from the server origin.
Serialize connection metadata using the discovery JSON format so static configuration can supply values with toJSON methods. Resolve same-origin MCP paths against the mount base for callers that receive the handle.

Exercise both discovery paths with a real MCP initialize request and compare the published representation of a URL in static configuration.
@SaKaNa-Y SaKaNa-Y changed the title fix(devframe): return complete dev server handles for SSE fix(devframe): return complete connection metadata from dev server handles Nov 8, 2026
SaKaNa-Y and others added 9 commits November 14, 2026 16:36
Advertise the mount root as ./ so a discovery document under a nested path resolves WebSocket, SSE and MCP to the bound endpoint. Cover both discovery paths with real connections.
HTTP discovery can select strict JSON for a method called with an object from a same-origin iframe. Each window owns a different Object.prototype, so comparing the prototype by identity rejected ordinary JSON before dispatch.

Recognize the native Object constructor for the prototype from another realm. Keep rejecting class and Map instances.
Use the same relative path for hand-written and built-in discovery at a nested mount. A descriptor with its own port still uses the root of the sidecar origin.
@SaKaNa-Y
SaKaNa-Y marked this pull request as ready for review November 22, 2026 07:56

This branch has not been deployed

No deployments
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