Skip to content

Conversation

@deloreyj
Copy link
Collaborator

@deloreyj deloreyj commented Apr 24, 2025

This PR fixes an issue where we were having to set the active account id twice when the MCP Server. The reason the bug was happening is as follows

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](http://connection.id/))) {
        this.#sendMessageToConnection(connection, msg);
      }
    }
  }
The `[connection.id](http://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.

The PR also adds a launch.json with a config to attach a debugger to assist in future MCP Server debugging.

@Maximo-Guk Maximo-Guk self-requested a review April 24, 2025 19:53
@deloreyj deloreyj merged commit e25967e into main Apr 24, 2025
6 checks passed
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.

2 participants