-
Notifications
You must be signed in to change notification settings - Fork 381
Fix streamable hibernation issues #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1ded712
08041e0
3e62e44
9c6fb27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "agents": patch | ||
| --- | ||
|
|
||
| Jmorrell/fix streamable hibernation issue |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,7 +259,7 @@ export abstract class McpAgent< | |
| this.#transportType = (await this.ctx.storage.get( | ||
| "transportType" | ||
| )) as TransportType; | ||
| this.init?.(); | ||
| await this._init(this.props); | ||
|
|
||
| // Connect to the MCP server | ||
| if (this.#transportType === "sse") { | ||
|
|
@@ -285,16 +285,22 @@ export abstract class McpAgent< | |
|
|
||
| async _init(props: Props) { | ||
| await this.ctx.storage.put("props", props ?? {}); | ||
| await this.ctx.storage.put("transportType", "unset"); | ||
| 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(); | ||
| } | ||
| } | ||
|
|
||
| isInitialized() { | ||
| return this.initRun; | ||
| async setInitialized() { | ||
| await this.ctx.storage.put("initialized", true); | ||
| } | ||
|
|
||
| async isInitialized() { | ||
| return (await this.ctx.storage.get("initialized")) === true; | ||
|
Comment on lines
+298
to
+303
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little odd because this is only used by the streamable transport, and not the SSE transport. |
||
| } | ||
|
|
||
| async #initialize(): Promise<void> { | ||
|
|
@@ -898,7 +904,7 @@ export abstract class McpAgent< | |
| const isInitialized = await doStub.isInitialized(); | ||
|
|
||
| if (isInitializationRequest) { | ||
| await doStub._init(ctx.props); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a question about this change. Also, wasn't the OAuth flow relying on that? https://github.com/cloudflare/workers-oauth-provider/blob/main/src/oauth-provider.ts#L1857 See my comment here for additional details: #194 (comment)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! You're absolutely right. Let me add that back in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this is only an issue if you need to access the results of auth in your MCP tools. I think the auth flow itself will still work.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| await doStub.setInitialized(); | ||
| } else if (!isInitialized) { | ||
| // if we have gotten here, then a session id that was never initialized | ||
| // was provided | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,7 +269,6 @@ describe("McpAgent Streamable HTTP Transport", () => { | |
|
|
||
| it("should reject invalid session ID", async () => { | ||
| const ctx = createExecutionContext(); | ||
| const sessionId = await initializeServer(ctx); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unused in the rest of the test and can be safely removed without affecting the test logic |
||
|
|
||
| // Now try with invalid session ID | ||
| const response = await sendPostRequest( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this guard this would be overwritten when the DO wakes up. The complexity of our "boot" logic is higher than I would like.