Skip to content

Allow refreshing props for existing Durable Objects via serveSSE POST endpoint #323

Open
@sgomez

Description

@sgomez

When using a MCPAgent locally, the POST /message handler fetches the Durable Object using idFromName("sse:${sessionId}") but does not re-initialize or update the props context via _init() or similar.

// Get the Durable Object
const id = namespace.idFromName(`sse:${sessionId}`);
const doStub = namespace.get(id);

// Forward the request to the Durable Object
const error = await doStub.onSSEMcpMessage(sessionId, request);

In practical terms, this leads to stale or missing values inside this.props. For instance, in the Auth0 integration example, this.props.tokenSet.accessToken from tokenExchangeCallback never updates after the first token exchange. Even though the refresh token flow is correctly triggered, the updated access token never reaches the Durable Object instance, breaking authenticated API requests.

I guess a solution can be:

// Get the Durable Object
const id = namespace.idFromName(`sse:${sessionId}`);
const doStub = namespace.get(id);
await doStub._init(ctx.props) // refresh props

// Forward the request to the Durable Object
const error = await doStub.onSSEMcpMessage(sessionId, request);

If you agree with the fix, I’d be happy to open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions