Skip to content

Commit 902a604

Browse files
committed
The issue of unsupported int64 was resolved using AIGC.
1 parent ecbcfa6 commit 902a604

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

src/tools/args.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@ function toEJSON<T extends object | undefined>(value: T): T {
8484
export function zEJSON(): z.AnyZodObject {
8585
return z.object({}).passthrough().transform(toEJSON) as unknown as z.AnyZodObject;
8686
}
87+
88+
/**
89+
* Serializes data to EJSON format with proper Int64 preservation.
90+
* This function ensures that Int64 values are not truncated to JavaScript numbers.
91+
* @param value The data to serialize
92+
* @returns EJSON string with preserved Int64 precision
93+
*/
94+
export function serializeWithInt64Preservation(value: unknown): string {
95+
return EJSON.stringify(value, undefined, undefined, { relaxed: false });
96+
}

src/tools/mongodb/delete/deleteMany.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class DeleteManyTool extends MongoDBToolBase {
5858
protected getConfirmationMessage({ database, collection, filter }: ToolArgs<typeof this.argsShape>): string {
5959
const filterDescription =
6060
filter && Object.keys(filter).length > 0
61-
? "```json\n" + `{ "filter": ${EJSON.stringify(filter)} }\n` + "```\n\n"
61+
? "```json\n" + `{ "filter": ${EJSON.stringify(filter, undefined, undefined, { relaxed: false })} }\n` + "```\n\n"
6262
: "- **All documents** (No filter)\n\n";
6363
return (
6464
`You are about to delete documents from the \`${collection}\` collection in the \`${database}\` database:\n\n` +

src/tools/mongodb/metadata/dbStats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class DbStatsTool extends MongoDBToolBase {
2121
});
2222

2323
return {
24-
content: formatUntrustedData(`Statistics for database ${database}`, EJSON.stringify(result)),
24+
content: formatUntrustedData(`Statistics for database ${database}`, EJSON.stringify(result, undefined, undefined, { relaxed: false })),
2525
};
2626
}
2727
}

src/tools/mongodb/read/aggregate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class AggregateTool extends MongoDBToolBase {
138138
cursorResults.cappedBy,
139139
].filter((limit): limit is keyof typeof CURSOR_LIMITS_TO_LLM_TEXT => !!limit),
140140
}),
141-
...(cursorResults.documents.length > 0 ? [EJSON.stringify(cursorResults.documents)] : [])
141+
...(cursorResults.documents.length > 0 ? [EJSON.stringify(cursorResults.documents, undefined, undefined, { relaxed: false })] : [])
142142
),
143143
};
144144
} finally {

src/tools/mongodb/read/find.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class FindTool extends MongoDBToolBase {
9898
documents: cursorResults.documents,
9999
appliedLimits: [limitOnFindCursor.cappedBy, cursorResults.cappedBy].filter((limit) => !!limit),
100100
}),
101-
...(cursorResults.documents.length > 0 ? [EJSON.stringify(cursorResults.documents)] : [])
101+
...(cursorResults.documents.length > 0 ? [EJSON.stringify(cursorResults.documents, undefined, undefined, { relaxed: false })] : [])
102102
),
103103
};
104104
} finally {

0 commit comments

Comments
 (0)