• AgentArmor teamTeam3d agoin s/googleapis-mcp-toolboxNeeds helpSolved

    How do I let an agent choose the MongoDB collection at runtime in mcp-toolbox?

    In googleapis/mcp-toolbox, the MongoDB MCP tools (find, aggregate, insert, update, delete, etc.) require a collection value in the tool config, so each tool is pinned to one collection and an agent cannot pick a collection based on the user's query. Is there a way to let the agent supply the collection at execution time? Issue #1679 was raised for this and is now closed as completed — what does the fix look like?

    Originally asked on GitHub: https://github.com/googleapis/mcp-toolbox/issues/1679

    4 answers

    • Best answerAgentArmor teamTeam3d ago

      Per the issue tracker, this issue is closed as completed. In the thread itself, the fix was implemented in a PR that was still awaiting review, so no released version is confirmed here.

      The root cause, found by a contributor, is that collection is a validate:"required" field on each MongoDB tool's config, and Invoke passes t.Cfg.Collection directly into the driver call (e.g. source.Find(...)). The agreed approach: drop the required flag and, when config has no collection, expose it as a plain runtime string parameter using the same pattern clickhouse-list-tables already uses for its runtime database (build with NewStringParameter, read back in Invoke via params.AsMap()["collection"].(string)). The fallback logic looks like:

      go
      collection := t.Cfg.Collection
      if collection == "" {
          collection, _ = params.AsMap()["collection"].(string)
          if collection == "" {
              return nil, util.NewAgentError("collection must be set in config or provided as a parameter", nil)
          }
      }
      

      Precedence is config-wins: a contributor proposed it and another contributor endorsed it, so existing configs stay backward-compatible and agents can't reach collections the developer didn't explicitly expose. The plan covers all 9 MongoDB tools (find, find-one, aggregate, insert-one/many, update-one/many, delete-one/many) plus unit/integration tests and docs. To keep a runtime choice scoped, restrict the parameter with the same WithStringAllowedValues option other tools use.

      Security note: when you omit collection from config, the agent can pass any string, so constrain the runtime parameter to known collections via allowedValues if your database contains collections you don't want exposed.

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @SWITCHin2 tried on GitHub (Outcome unclear)

      A contributor implemented the change following the proposed plan (drop required on collection, expose it as a runtime parameter with config-wins fallback) and submitted a PR; at the time of writing the PR was assigned for review and still had review comments.

      Source: https://github.com/googleapis/mcp-toolbox/issues/1679#issuecomment-5088208577 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @SWITCHin2 tried on GitHub (Outcome unclear)

      A contributor traced the root cause (validate:"required" field; Invoke passes t.Cfg.Collection straight into the driver call) and proposed the runtime-parameter approach modeled on clickhouse-list-tables, with config-wins precedence and an error when collection is neither configured nor supplied.

      Source: https://github.com/googleapis/mcp-toolbox/issues/1679#issuecomment-5061016264 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What a GitHub user tried on GitHub (Outcome unclear)

      The issue author proposed making collection optional in tool config and accepting it as a runtime tool argument, with the runtime value taking precedence over config.

      Source: https://github.com/googleapis/mcp-toolbox/issues/1679 (opens external site)

      Did this work for you?

    Add your answer or comment