Skip to content

App.registerTool rejects valid tool names inherited from Object.prototype #861

Open

Description

@lj1166

Bug

App.registerTool() rejects tool names inherited from Object.prototype as already registered, even on a newly created App. For example, constructor, toString and __proto__ are all valid MCP tool names but cannot be registered.

The App registry is initialized with {} and the duplicate check reads this._registeredTools[name], so an inherited property is mistaken for a registered tool. The same registry is also used by the WebMCP bridge for name shadowing.

Reproduction

On current main ea3e9d0e624a20bc1c51310292f09d9b8ed17161 (SDK 2.1.0), using Bun 1.3.10 on Windows:

import { App } from './src/app.ts';

for (const name of ['constructor', 'toString', '__proto__']) {
  const app = new App({ name: 'repro', version: '1.0.0' }, {}, { autoResize: false });
  try {
    app.registerTool(name, { description: 'Returns its name' }, async () => ({
      content: [{ type: 'text', text: name }],
    }));
    console.log(name, 'registered');
  } catch (error) {
    console.log(String(error));
  }
}

Actual:

Error: Tool constructor is already registered
Error: Tool toString is already registered
Error: Tool __proto__ is already registered

Expected: each fresh App accepts the name, lists it and serves its callback; registering the same tool twice still fails.

Three new cases in the existing App integration tests fail at registration on unchanged source, with all 14 existing cases passing. The regression then exercises tools/list, tools/call, duplicate registration and removal over linked real SDK InMemoryTransports once registration succeeds. No browser, model, provider or external server is involved.

Proposed fix

Use a prototype-free record for _registeredTools, retaining the existing lookup/iteration behavior. I intend to submit the focused fix with these regressions.

Duplicate searches for prototype tool names and registerTool/constructor found no corresponding issue/PR. #420 contains an incidental browser stack/prototype dump and concerns Windows quickstart commands, not this registration behavior.

AI assistance: Codex found this during a contribution-oriented source review, ran the reproduction/tests and drafted the report under the account holder's instruction. Independent human reproduction is not claimed.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions