File tree Expand file tree Collapse file tree 2 files changed +32
-22
lines changed
src/tools/mongodb/metadata Expand file tree Collapse file tree 2 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,17 @@ import { MongoDBToolBase } from "../mongodbTool.js";
33import * as bson from "bson" ;
44import { OperationType } from "../../tool.js" ;
55
6+ export function listDatabasesResponse ( databases : { name : string ; sizeOnDisk : string } [ ] ) : CallToolResult {
7+ return {
8+ content : databases . map ( ( db ) => {
9+ return {
10+ text : `Name: ${ db . name } , Size: ${ db . sizeOnDisk } bytes` ,
11+ type : "text" ,
12+ } ;
13+ } ) ,
14+ } ;
15+ }
16+
617export class ListDatabasesTool extends MongoDBToolBase {
718 protected name = "list-databases" ;
819 protected description = "List all databases for a MongoDB connection" ;
@@ -13,13 +24,13 @@ export class ListDatabasesTool extends MongoDBToolBase {
1324 const provider = await this . ensureConnected ( ) ;
1425 const dbs = ( await provider . listDatabases ( "" ) ) . databases as { name : string ; sizeOnDisk : bson . Long } [ ] ;
1526
16- return {
17- content : dbs . map ( ( db ) => {
27+ return listDatabasesResponse (
28+ dbs . map ( ( db ) => {
1829 return {
19- text : `Name: ${ db . name } , Size: ${ db . sizeOnDisk . toString ( ) } bytes` ,
20- type : "text" ,
30+ name : db . name ,
31+ sizeOnDisk : db . sizeOnDisk . toString ( ) ,
2132 } ;
22- } ) ,
23- } ;
33+ } )
34+ ) ;
2435 }
2536}
Original file line number Diff line number Diff line change 11import { describeAccuracyTests } from "./sdk/describe-accuracy-tests.js" ;
22import { getAvailableModels } from "./sdk/models.js" ;
33import { AccuracyTestConfig } from "./sdk/describe-accuracy-tests.js" ;
4+ import { listDatabasesResponse } from "../../src/tools/mongodb/metadata/listDatabases.js" ;
45
5- function describeListDatabasesAccuracyTests ( prompt : string ) : AccuracyTestConfig {
6+ function callsListDatabases ( prompt : string ) : AccuracyTestConfig {
67 return {
78 injectConnectedAssumption : true ,
89 prompt : prompt ,
910 mockedTools : {
1011 "list-databases" : function listDatabases ( ) {
11- return {
12- content : [
13- {
14- type : "text" ,
15- text : "Name: db1" ,
16- } ,
17- {
18- type : "text" ,
19- text : "Name: db2" ,
20- } ,
21- ] ,
22- } ;
12+ return listDatabasesResponse ( [
13+ {
14+ name : "db1" ,
15+ sizeOnDisk : "1024" ,
16+ } ,
17+ {
18+ name : "db2" ,
19+ sizeOnDisk : "2048" ,
20+ } ,
21+ ] ) ;
2322 } ,
2423 } ,
2524 expectedToolCalls : [
@@ -32,7 +31,7 @@ function describeListDatabasesAccuracyTests(prompt: string): AccuracyTestConfig
3231}
3332
3433describeAccuracyTests ( "list-databases" , getAvailableModels ( ) , [
35- describeListDatabasesAccuracyTests ( "How many databases do I have?" ) ,
36- describeListDatabasesAccuracyTests ( "List all the databases in my cluster." ) ,
37- describeListDatabasesAccuracyTests ( "Is there a sample_mflix database in my cluster?" ) ,
34+ callsListDatabases ( "How many databases do I have?" ) ,
35+ callsListDatabases ( "List all the databases in my cluster." ) ,
36+ callsListDatabases ( "Is there a sample_mflix database in my cluster?" ) ,
3837] ) ;
You can’t perform that action at this time.
0 commit comments