Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-hoops-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agents": patch
---

fix: Ensure McpAgent props stay current
13 changes: 11 additions & 2 deletions packages/agents/src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,10 @@ export abstract class McpAgent<
abstract init(): Promise<void>;

async _init(props: Props) {
await this.ctx.storage.put("props", props ?? {});
await this.updateProps(props);
if (!this.ctx.storage.get("transportType")) {
await this.ctx.storage.put("transportType", "unset");
}
this.props = props;
if (!this.initRun) {
this.initRun = true;
await this.init();
Expand All @@ -377,6 +376,11 @@ export abstract class McpAgent<
return (await this.ctx.storage.get("initialized")) === true;
}

async updateProps(props: Props) {
await this.ctx.storage.put("props", props ?? {});
this.props = props;
}

private async _initialize(): Promise<void> {
await this.ctx.blockConcurrencyWhile(async () => {
this._status = "starting";
Expand Down Expand Up @@ -890,6 +894,8 @@ export abstract class McpAgent<
const doStub = namespace.get(id);

const messageBody = await request.json();
// Update props with fresh values before processing message
await doStub.updateProps(ctx.props);
const error = await doStub.onSSEMcpMessage(sessionId, messageBody);

if (error) {
Expand Down Expand Up @@ -1133,6 +1139,9 @@ export abstract class McpAgent<
jsonrpc: "2.0"
});
return new Response(body, { status: 404 });
} else {
// Update props for existing sessions
await doStub.updateProps(ctx.props);
}

// We've evaluated all the error conditions! Now it's time to establish
Expand Down