Skip to content

Commit 018f752

Browse files
committed
chore: minor fixes and remove unused dependencies
1 parent e11b8c1 commit 018f752

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

package-lock.json

Lines changed: 0 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"@modelcontextprotocol/inspector": "^0.16.5",
6868
"@mongodb-js/oidc-mock-provider": "^0.11.3",
6969
"@redocly/cli": "^2.0.8",
70-
"@testcontainers/mongodb": "^11.7.1",
7170
"@types/express": "^5.0.3",
7271
"@types/node": "^24.5.2",
7372
"@types/proper-lockfile": "^4.1.4",

src/tools/mongodb/search/listSearchIndexes.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
22
import type { ToolArgs, OperationType } from "../../tool.js";
33
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
44
import { formatUntrustedData } from "../../tool.js";
5+
import { EJSON } from "bson";
56

67
export type SearchIndexStatus = {
78
name: string;
@@ -26,7 +27,7 @@ export class ListSearchIndexesTool extends MongoDBToolBase {
2627
return {
2728
content: formatUntrustedData(
2829
`Found ${trimmedIndexDefinitions.length} search and vector search indexes in ${database}.${collection}`,
29-
indexes.map((index) => JSON.stringify(index)).join("\n")
30+
indexes.map((index) => EJSON.stringify(index)).join("\n")
3031
),
3132
};
3233
} else {
@@ -54,7 +55,10 @@ export class ListSearchIndexesTool extends MongoDBToolBase {
5455
}));
5556
}
5657

57-
protected handleError(error: unknown): Promise<CallToolResult> | CallToolResult {
58+
protected handleError(
59+
error: unknown,
60+
{ database, collection }: ToolArgs<typeof DbOperationArgs>
61+
): Promise<CallToolResult> | CallToolResult {
5862
if (error instanceof Error && "codeName" in error && error.codeName === "SearchNotEnabled") {
5963
return {
6064
content: [
@@ -68,7 +72,7 @@ export class ListSearchIndexesTool extends MongoDBToolBase {
6872
return {
6973
content: [
7074
{
71-
text: "Collection does not exist",
75+
text: `Could not retrieve indexes in ${database}.${collection}: ${EJSON.stringify(error)}.`,
7276
type: "text",
7377
},
7478
],

tests/integration/tools/mongodb/search/listSearchIndexes.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import type { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
1212
import type { SearchIndexStatus } from "../../../../../src/tools/mongodb/search/listSearchIndexes.js";
1313

14-
const SEARCH_RETRIES = 10_000;
14+
const SEARCH_RETRIES = 200;
1515
const SEARCH_TIMEOUT = 20_000;
1616

1717
describeWithMongoDB("list search indexes tool in local MongoDB", (integration) => {
@@ -48,6 +48,17 @@ describeWithMongoDB(
4848
await waitUntilSearchIsReady(provider, signal);
4949
});
5050

51+
describe("when the collection does not exist", () => {
52+
it("returns an empty list of indexes", async () => {
53+
const response = await integration.mcpClient().callTool({
54+
name: "list-search-indexes",
55+
arguments: { database: "any", collection: "foo" },
56+
});
57+
const content = getResponseContent(response.content);
58+
expect(content).toEqual("There are no search or vector search indexes in any.foo");
59+
});
60+
});
61+
5162
describe("when there are no indexes", () => {
5263
it("returns an empty list of indexes", async () => {
5364
const response = await integration.mcpClient().callTool({
@@ -107,8 +118,8 @@ describeWithMongoDB(
107118
);
108119

109120
async function waitUntilSearchIsReady(provider: NodeDriverServiceProvider, abortSignal: AbortSignal): Promise<void> {
110-
let success = true;
111-
let lastError: unknown = false;
121+
let success = false;
122+
let lastError: unknown = null;
112123

113124
for (let i = 0; i < SEARCH_RETRIES && !abortSignal.aborted; i++) {
114125
try {
@@ -135,8 +146,8 @@ async function waitUntilIndexIsQueryable(
135146
abortSignal: AbortSignal
136147
): Promise<void> {
137148
let success = false;
138-
let lastIndexStatus: unknown = false;
139-
let lastError: unknown = false;
149+
let lastIndexStatus: unknown = null;
150+
let lastError: unknown = null;
140151

141152
for (let i = 0; i < SEARCH_RETRIES && !abortSignal.aborted; i++) {
142153
try {

0 commit comments

Comments
 (0)