Skip to content

Commit 4fa8d03

Browse files
committed
refactor: move ListDatabases output schema to tool file and remove validations from UI
1 parent 51fb03b commit 4fa8d03

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

src/schemas/listDatabases.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/tools/mongodb/metadata/listDatabases.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@ import { MongoDBToolBase } from "../mongodbTool.js";
33
import type * as bson from "bson";
44
import type { OperationType } from "../../tool.js";
55
import { formatUntrustedData } from "../../tool.js";
6-
import { ListDatabasesOutputSchema, type ListDatabasesOutput } from "../../../schemas/listDatabases.js";
6+
import { z } from "zod";
77

8-
export { ListDatabasesOutputSchema, type ListDatabasesOutput };
8+
/**
9+
* Schema for the list-databases tool output.
10+
* Used by the MCP protocol for structured content validation.
11+
*/
12+
export const ListDatabasesOutputSchema = {
13+
databases: z.array(
14+
z.object({
15+
name: z.string(),
16+
size: z.number(),
17+
})
18+
),
19+
totalCount: z.number(),
20+
};
21+
22+
/** Type derived from the output schema */
23+
export type ListDatabasesOutput = z.infer<z.ZodObject<typeof ListDatabasesOutputSchema>>;
924

1025
export class ListDatabasesTool extends MongoDBToolBase {
1126
public name = "list-databases";

src/ui/components/ListDatabases/ListDatabases.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react";
2-
import { z } from "zod";
32
import { useRenderData } from "../../hooks/index.js";
43
import {
54
Cell as LGCell,
@@ -11,14 +10,12 @@ import {
1110
TableHead,
1211
} from "@leafygreen-ui/table";
1312
import { tableStyles } from "./ListDatabases.styles.js";
14-
import { ListDatabasesOutputSchema, type ListDatabasesOutput } from "../../../schemas/listDatabases.js";
13+
import type { ListDatabasesOutput } from "../../../tools/mongodb/metadata/listDatabases.js";
1514

1615
const HeaderCell = LGHeaderCell as React.FC<React.ComponentPropsWithoutRef<"th">>;
1716
const Cell = LGCell as React.FC<React.ComponentPropsWithoutRef<"td">>;
1817
const Row = LGRow as React.FC<React.ComponentPropsWithoutRef<"tr">>;
1918

20-
const ListDatabasesDataSchema = z.object(ListDatabasesOutputSchema);
21-
2219
function formatBytes(bytes: number): string {
2320
if (bytes === 0) return "0 Bytes";
2421

@@ -40,10 +37,7 @@ export const ListDatabases = (): React.ReactElement | null => {
4037
return <div>Error: {error}</div>;
4138
}
4239

43-
const validationResult = ListDatabasesDataSchema.safeParse(data);
44-
45-
if (!validationResult.success) {
46-
console.error("[ListDatabases] Validation error:", validationResult.error);
40+
if (!data) {
4741
return null;
4842
}
4943

src/ui/lib/tools/list-databases.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)