Repository navigation
Conversation
… in MCP manifests
f3e2e8e to
fc62b35
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces collection scoping and restriction capabilities for MongoDB sources and tools, allowing administrators to restrict tools to a specific set of database collections via the allowedCollections configuration. It also adds a new mongodb-list-collections tool for discovering available collections and updates parameter manifests to advertise literal allowedValues as JSON Schema enum values to MCP clients. The review feedback suggests a more robust heap allocation pattern in ScopeCollectionParam to avoid taking the address of a loop-scoped variable, which prevents potential linter warnings or developer confusion.
| narrowed := *sp | ||
| narrowed.AllowedValues = anySlice(allowed) | ||
| scoped[i] = &narrowed |
There was a problem hiding this comment.
Taking the address of a loop-scoped variable (&narrowed) can sometimes lead to subtle bugs or trigger static analysis/linter warnings, even though Go 1.22+ handles loop variable lifetimes more safely.
Using new(parameters.StringParameter) to explicitly allocate the struct on the heap and then copying the value is a more robust and idiomatic pattern that avoids any potential linter warnings or developer confusion.
narrowed := new(parameters.StringParameter)
*narrowed = *sp
narrowed.AllowedValues = anySlice(allowed)
scoped[i] = narrowedThere was a problem hiding this comment.
This one's safe as written: narrowed := *sp is declared inside the loop body, so each iteration gets its own copy (even before Go 1.22), and taking its address is fine. The aliasing lint (gosec G601) only applies to range loop variables. Using new() plus a copy would do the same thing,
Description
Adds a
mongodb-list-collectionstool so an agent can find out which collections exist before it picks a runtimecollection.ListCollectionNames(ctx, database). It returns the sorted collection names in a database. When the source hasallowedCollections, it returns only the allowed collections that actually exist.mongodb-list-collections. It takes no parameters (the database comes from config), is annotated read-only by default, and is registered incmd/internal/imports.go.docs/en/integrations/mongodb/tools/.The two features answer different questions. The
enumfrom #4152 tells the agent which collections it is allowed to use (fixed in config). This tool tells it which collections exist right now, including when no allow-list is configured.PR Checklist
CONTRIBUTING.md
bug/issue
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
review
!if this involve a breaking change