• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 14614840974

23 Apr 2025 09:33AM UTC coverage: 76.675% (+23.5%) from 53.208%
14614840974

Pull #83

github

fmenezes
fix: styles
Pull Request #83: chore: add atlas tests

81 of 152 branches covered (53.29%)

Branch coverage included in aggregate %.

28 of 39 new or added lines in 6 files covered. (71.79%)

4 existing lines in 3 files now uncovered.

560 of 684 relevant lines covered (81.87%)

27.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.84
/src/tools/mongodb/metadata/collectionSchema.ts
1
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js";
16✔
3
import { ToolArgs, OperationType } from "../../tool.js";
4
import { parseSchema, SchemaField } from "mongodb-schema";
16✔
5

6
export class CollectionSchemaTool extends MongoDBToolBase {
16✔
7
    protected name = "collection-schema";
16✔
8
    protected description = "Describe the schema for a collection";
16✔
9
    protected argsShape = DbOperationArgs;
16✔
10

11
    protected operationType: OperationType = "metadata";
16✔
12

13
    protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
14
        const provider = await this.ensureConnected();
×
15
        const documents = await provider.find(database, collection, {}, { limit: 5 }).toArray();
×
16
        const schema = await parseSchema(documents);
×
17

18
        return {
×
19
            content: [
20
                {
21
                    text: `Found ${schema.fields.length} fields in the schema for \`${database}.${collection}\``,
22
                    type: "text",
23
                },
24
                {
25
                    text: this.formatFieldOutput(schema.fields),
26
                    type: "text",
27
                },
28
            ],
29
        };
30
    }
31

32
    private formatFieldOutput(fields: SchemaField[]): string {
33
        let result = "| Field | Type | Confidence |\n";
×
34
        result += "|-------|------|-------------|\n";
×
35
        for (const field of fields) {
×
36
            const fieldType = Array.isArray(field.type) ? field.type.join(", ") : field.type;
×
37
            result += `| ${field.name} | \`${fieldType}\` | ${(field.probability * 100).toFixed(0)}% |\n`;
×
38
        }
39
        return result;
×
40
    }
41
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc