Skip to content

Conversation

@threepointone
Copy link
Contributor

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Dec 22, 2025

🦋 Changeset detected

Latest commit: 07f58ff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@claude
Copy link

claude bot commented Dec 22, 2025

Claude Code Review

Issues Found:

  1. Return value handling bug in onStart wrapper (ai-chat-agent.ts:248-263)

    The wrapped onStart doesn't properly return the result from _onStart(props):

    this.onStart = async (props?: Props) => {
      return agentContext.run(..., async () => {
        await this._tryCatchChat(async () => {
          await this.mcp.ensureJsonSchema();
          return _onStart(props);  // ← Return inside _tryCatchChat, not agentContext.run
        });
      });
    };

    The return _onStart(props) is inside _tryCatchChat but that result is not returned from the agentContext.run callback. Compare with the base Agent class implementation (index.ts:621-637) which correctly returns:

    await this._tryCatch(async () => {
      await this.mcp.restoreConnectionsFromStorage(this.name);
      this.broadcastMcpServers();
      return _onStart(props);
    });

    Fix: Add explicit return:

    async () => {
      return await this._tryCatchChat(async () => {
        await this.mcp.ensureJsonSchema();
        return _onStart(props);
      });
    }
  2. Missing test coverage

    No tests verify that ensureJsonSchema is called on AIChatAgent startup. Consider adding a test in the mcp directory or a new ai-chat-agent test file.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@746

commit: 07f58ff

@threepointone threepointone changed the title Ensure this.mcp.jsonSchema is initialized on ai chat agent start WIP: Ensure this.mcp.jsonSchema is initialized on ai chat agent start Dec 22, 2025
@threepointone threepointone marked this pull request as draft December 22, 2025 01:24
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.

"jsonSchema not initialized" intermittent error when calling agent.mcp.getAITools()

1 participant