Skip to content

fix: tweak the arg shapes to improve tool accuracy #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/mongodb/metadata/explain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ExplainTool extends MongoDBToolBase {
...DbOperationArgs,
method: z
.array(
z.union([
z.discriminatedUnion("name", [
z.object({
name: z.literal("aggregate"),
arguments: z.object(AggregateArgs),
Expand Down
2 changes: 1 addition & 1 deletion src/tools/mongodb/read/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EJSON } from "bson";
import { checkIndexUsage } from "../../../helpers/indexCheck.js";

export const AggregateArgs = {
pipeline: z.array(z.record(z.string(), z.unknown())).describe("An array of aggregation stages to execute"),
pipeline: z.array(z.object({}).passthrough()).describe("An array of aggregation stages to execute"),
};

export class AggregateTool extends MongoDBToolBase {
Expand Down
3 changes: 2 additions & 1 deletion src/tools/mongodb/read/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { checkIndexUsage } from "../../../helpers/indexCheck.js";

export const CountArgs = {
query: z
.record(z.string(), z.unknown())
.object({})
.passthrough()
.optional()
.describe(
"A filter/query parameter. Allows users to filter the documents to count. Matches the syntax of the filter argument of db.collection.count()."
Expand Down
13 changes: 9 additions & 4 deletions src/tools/mongodb/read/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import { checkIndexUsage } from "../../../helpers/indexCheck.js";

export const FindArgs = {
filter: z
.record(z.string(), z.unknown())
.object({})
.passthrough()
.optional()
.describe("The query filter, matching the syntax of the query argument of db.collection.find()"),
projection: z
.record(z.string(), z.unknown())
.object({})
.passthrough()
.optional()
.describe("The projection, matching the syntax of the projection argument of db.collection.find()"),
limit: z.number().optional().default(10).describe("The maximum number of documents to return"),
sort: z
.record(z.string(), z.custom<SortDirection>())
.object({})
.catchall(z.custom<SortDirection>())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This, unfortunately, doesn't correctly set the type for additionalProperties in the JSON schema. This is the reason I had to update the tool description to be extra verbose.

.optional()
.describe("A document, describing the sort order, matching the syntax of the sort argument of cursor.sort()"),
.describe(
"A document, describing the sort order, matching the syntax of the sort argument of cursor.sort(). The keys of the object are the fields to sort on, while the values are the sort directions (1 for ascending, -1 for descending)."
),
};

export class FindTool extends MongoDBToolBase {
Expand Down
Loading