Skip to content

feat(mcp): add allowedTools filtering support to OneMcpServer#10811

Merged
chkuang-g merged 1 commit into
mainfrom
chkuang/onemcp-tool-filter
Jul 17, 2026
Merged

feat(mcp): add allowedTools filtering support to OneMcpServer#10811
chkuang-g merged 1 commit into
mainfrom
chkuang/onemcp-tool-filter

Conversation

@chkuang-g

Copy link
Copy Markdown
Contributor

Description

Adds support for tool filtering in OneMcpServer via an optional allowedTools?: string[] parameter in OneMcpServerOptions (addressing b/535744232).

  • listTools() filters remote tool list responses against allowedTools.
  • callTool() guards against invoking tools not present in allowedTools.

Scenarios Tested

  • Unit tests in src/mcp/onemcp/onemcp_server.spec.ts verifying listTools filters tools when allowedTools is configured.
  • Unit tests in src/mcp/onemcp/onemcp_server.spec.ts verifying callTool throws a FirebaseError for unallowed tools.
  • Unit tests verifying backward compatibility when allowedTools is omitted or empty.

Sample Commands

npx mocha --require ts-node/register src/mcp/onemcp/onemcp_server.spec.ts

@chkuang-g
chkuang-g force-pushed the chkuang/onemcp-tool-filter branch from 2935ad3 to a4d74e7 Compare July 17, 2026 19:28
@chkuang-g
chkuang-g requested a review from joehan July 17, 2026 19:28

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces tool filtering support to OneMcpServer via a new allowedTools configuration option, filtering the tools returned by listTools() and checking permissions in callTool(). The review feedback points out that callTool() currently only logs a warning when a disallowed tool is invoked instead of blocking execution. To properly guard the execution and adhere to the repository style guide, the reviewer recommends throwing a FirebaseError when a disallowed tool is called, and updating the corresponding unit tests to assert this error behavior.

I am having trouble creating individual review comments. Click here to see my feedback.

src/mcp/onemcp/onemcp_server.ts (120-128)

high

The implementation currently only logs a warning when a disallowed tool is called, and then proceeds to execute the tool anyway. According to the PR description, callTool() is supposed to guard against invoking tools not present in allowedTools. To properly guard and prevent execution, we should throw a FirebaseError as specified in the repository style guide for expected, user-facing errors.

    if (
      this.options.allowedTools?.length &&
      !this.options.allowedTools.includes(toolName) &&
      !this.options.allowedTools.includes(this.feature + "_" + toolName)
    ) {
      throw new FirebaseError(
        "Tool '" + toolName + "' is not allowed on remote server for feature '" + this.feature + "'."
      );
    }
References
  1. Throw FirebaseError (src/error.ts) for expected, user-facing errors. (link)

src/mcp/onemcp/onemcp_server.spec.ts (234-252)

high

Since callTool should throw a FirebaseError when a disallowed tool is called, this test should be updated to assert that the promise is rejected with a FirebaseError instead of checking for a logged warning.

    it("should throw FirebaseError when calling a tool not in allowedTools", async () => {
      const serverWithFilter = new OneMcpServer(
        feature,
        serverUrl,
        { requiresAuth: false, requiresProject: true },
        { allowedTools: ["allowed_tool"] },
      );

      const fn = (serverWithFilter as any).callTool.bind(serverWithFilter);
      await expect(fn("disallowed_tool", {}, mockContext)).to.be.rejectedWith(
        FirebaseError,
        /is not allowed on remote server/
      );
    });

Comment thread CHANGELOG.md Outdated
@@ -1 +1,2 @@
- Add `MCP-Protocol-Version`, `Mcp-Method`, and `Mcp-Name` HTTP headers to `OneMcpServer` requests per the MCP 0728 standard release candidate (https://blog.modelcontextprotocol.io/posts/2026-07-28-release-candidate/ and https://modelcontextprotocol.io/seps/2243-http-standardization).
- Add tool filtering support to `OneMcpServer` via `allowedTools` configuration option.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit the CHANGELOG for this one - its not a user facing change, but rather an implementation detail

@joehan joehan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just remove the changelog

### Description
Adds support for tool filtering in `OneMcpServer` via an optional `allowedTools?: string[]` parameter in `OneMcpServerOptions` (addressing b/535744232).
- `listTools()` filters remote tool list responses against `allowedTools`.
- `callTool()` guards against invoking tools not present in `allowedTools`.

### Scenarios Tested
- Unit tests in src/mcp/onemcp/onemcp_server.spec.ts verifying `listTools` filters tools when `allowedTools` is configured.
- Unit tests in src/mcp/onemcp/onemcp_server.spec.ts verifying `callTool` throws a `FirebaseError` for unallowed tools.
- Unit tests verifying backward compatibility when `allowedTools` is omitted or empty.

### Sample Commands
npx mocha --require ts-node/register src/mcp/onemcp/onemcp_server.spec.ts
@chkuang-g
chkuang-g force-pushed the chkuang/onemcp-tool-filter branch from a4d74e7 to f40bcb6 Compare July 17, 2026 20:53
@chkuang-g
chkuang-g enabled auto-merge (squash) July 17, 2026 20:53
@chkuang-g
chkuang-g merged commit 745519d into main Jul 17, 2026
52 of 53 checks passed
@chkuang-g
chkuang-g deleted the chkuang/onemcp-tool-filter branch July 17, 2026 21:02
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.

3 participants