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";
3
3
import * as bson from "bson" ;
4
4
import { OperationType } from "../../tool.js" ;
5
5
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
+
6
17
export class ListDatabasesTool extends MongoDBToolBase {
7
18
protected name = "list-databases" ;
8
19
protected description = "List all databases for a MongoDB connection" ;
@@ -13,13 +24,13 @@ export class ListDatabasesTool extends MongoDBToolBase {
13
24
const provider = await this . ensureConnected ( ) ;
14
25
const dbs = ( await provider . listDatabases ( "" ) ) . databases as { name : string ; sizeOnDisk : bson . Long } [ ] ;
15
26
16
- return {
17
- content : dbs . map ( ( db ) => {
27
+ return listDatabasesResponse (
28
+ dbs . map ( ( db ) => {
18
29
return {
19
- text : `Name: ${ db . name } , Size: ${ db . sizeOnDisk . toString ( ) } bytes` ,
20
- type : "text" ,
30
+ name : db . name ,
31
+ sizeOnDisk : db . sizeOnDisk . toString ( ) ,
21
32
} ;
22
- } ) ,
23
- } ;
33
+ } )
34
+ ) ;
24
35
}
25
36
}
Original file line number Diff line number Diff line change 1
1
import { describeAccuracyTests } from "./sdk/describe-accuracy-tests.js" ;
2
2
import { getAvailableModels } from "./sdk/models.js" ;
3
3
import { AccuracyTestConfig } from "./sdk/describe-accuracy-tests.js" ;
4
+ import { listDatabasesResponse } from "../../src/tools/mongodb/metadata/listDatabases.js" ;
4
5
5
- function describeListDatabasesAccuracyTests ( prompt : string ) : AccuracyTestConfig {
6
+ function callsListDatabases ( prompt : string ) : AccuracyTestConfig {
6
7
return {
7
8
injectConnectedAssumption : true ,
8
9
prompt : prompt ,
9
10
mockedTools : {
10
11
"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
+ ] ) ;
23
22
} ,
24
23
} ,
25
24
expectedToolCalls : [
@@ -32,7 +31,7 @@ function describeListDatabasesAccuracyTests(prompt: string): AccuracyTestConfig
32
31
}
33
32
34
33
describeAccuracyTests ( "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?" ) ,
38
37
] ) ;
You can’t perform that action at this time.
0 commit comments