Skip to content

McpAgent throws error #214

Closed
Closed

Description

@threepointone

(via @deloreyj)

Hey Sunil, I've been debugging an issue we're having with the McpAgent where you have to set the active account ID twice for it to take effect. It looks like the issue ends up in the internals of PartyServer, so I wanted to get your take.

Here's the flow:

  1. Define an McpAgent with an initialState property like so
  2. Call the setActiveAccountId tool
  3. Spread this.state into the setState call
  4. this.state calls the getter which passes through to this.#agent.state getter
  5. Since we overrode the state, the getter drops through to this.setState in the Agent class
  6. Then we end up in this.broadcast
  7. Now we're in PartyServer at this method
/** Send a message to all connected clients, except connection ids listed in `without` */
  broadcast(
    msg: string | ArrayBuffer | ArrayBufferView,
    without?: string[] | undefined
  ): void {
    for (const connection of this.#connectionManager.getConnections()) {
      if (!without || !without.includes(connection.id)) {
        this.#sendMessageToConnection(connection, msg);
      }
    }
  }

The connection.id getter fails with this error

Uncaught TypeError TypeError: Cannot read properties of null (reading '__pk')
    at get (/Users/delorey/code/mcp-server-cloudflare/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/partyserver/src/connection.ts:100:34)
    at eval (repl:1:12)

Removing the initialState property from the McpAgent solves the problem because we return before the this.setState here.

We're unblocked on the MCP Servers, but seems like an issue worth looking into at some point?

Activity

  1. changed the title [-]McpAgent accountid throws error[/-] [+]McpAgent throws error[/+] on Apr 25, 2025
  2. added
    mcp
    on Apr 25, 2025
  3. whoiskatrin commented on Sep 11, 2025

    @whoiskatrin
    Contributor

    shouldn't be the case anymore, merged updated McpAgent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    mcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions