Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/tools/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,13 @@ function toEJSON<T extends object | undefined>(value: T): T {
export function zEJSON(): z.AnyZodObject {
return z.object({}).passthrough().transform(toEJSON) as unknown as z.AnyZodObject;
}

/**
* Serializes data to EJSON format with proper Int64 preservation.
* This function ensures that Int64 values are not truncated to JavaScript numbers.
* @param value The data to serialize
* @returns EJSON string with preserved Int64 precision
*/
export function serializeWithInt64Preservation(value: unknown): string {
return EJSON.stringify(value, undefined, undefined, { relaxed: false });
}
2 changes: 1 addition & 1 deletion src/tools/mongodb/delete/deleteMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class DeleteManyTool extends MongoDBToolBase {
protected getConfirmationMessage({ database, collection, filter }: ToolArgs<typeof this.argsShape>): string {
const filterDescription =
filter && Object.keys(filter).length > 0
? "```json\n" + `{ "filter": ${EJSON.stringify(filter)} }\n` + "```\n\n"
? "```json\n" + `{ "filter": ${EJSON.stringify(filter, undefined, undefined, { relaxed: false })} }\n` + "```\n\n"
: "- **All documents** (No filter)\n\n";
return (
`You are about to delete documents from the \`${collection}\` collection in the \`${database}\` database:\n\n` +
Expand Down
2 changes: 1 addition & 1 deletion src/tools/mongodb/metadata/dbStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class DbStatsTool extends MongoDBToolBase {
});

return {
content: formatUntrustedData(`Statistics for database ${database}`, EJSON.stringify(result)),
content: formatUntrustedData(`Statistics for database ${database}`, EJSON.stringify(result, undefined, undefined, { relaxed: false })),
};
}
}
2 changes: 1 addition & 1 deletion src/tools/mongodb/read/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class AggregateTool extends MongoDBToolBase {
cursorResults.cappedBy,
].filter((limit): limit is keyof typeof CURSOR_LIMITS_TO_LLM_TEXT => !!limit),
}),
...(cursorResults.documents.length > 0 ? [EJSON.stringify(cursorResults.documents)] : [])
...(cursorResults.documents.length > 0 ? [EJSON.stringify(cursorResults.documents, undefined, undefined, { relaxed: false })] : [])
),
};
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/mongodb/read/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class FindTool extends MongoDBToolBase {
documents: cursorResults.documents,
appliedLimits: [limitOnFindCursor.cappedBy, cursorResults.cappedBy].filter((limit) => !!limit),
}),
...(cursorResults.documents.length > 0 ? [EJSON.stringify(cursorResults.documents)] : [])
...(cursorResults.documents.length > 0 ? [EJSON.stringify(cursorResults.documents, undefined, undefined, { relaxed: false })] : [])
),
};
} finally {
Expand Down
Loading