|
| 1 | +import { validateToolMetadata, validateThrowsForInvalidArguments, getResponseElements } from "../../../helpers.js"; |
| 2 | +import { describeWithMongoDB, validateAutoConnectBehavior } from "../mongodbHelpers.js"; |
| 3 | + |
| 4 | +describeWithMongoDB("logs tool", (integration) => { |
| 5 | + validateToolMetadata(integration, "mongodb-logs", "Returns the most recent logged mongod events", [ |
| 6 | + { |
| 7 | + type: "string", |
| 8 | + name: "type", |
| 9 | + description: |
| 10 | + "The type of logs to return. Global returns all recent log entries, while startupWarnings returns only warnings and errors from when the process started.", |
| 11 | + required: false, |
| 12 | + }, |
| 13 | + { |
| 14 | + type: "integer", |
| 15 | + name: "limit", |
| 16 | + description: "The maximum number of log entries to return.", |
| 17 | + required: false, |
| 18 | + }, |
| 19 | + ]); |
| 20 | + |
| 21 | + validateThrowsForInvalidArguments(integration, "mongodb-logs", [ |
| 22 | + { extra: true }, |
| 23 | + { type: 123 }, |
| 24 | + { type: "something" }, |
| 25 | + { limit: 0 }, |
| 26 | + { limit: true }, |
| 27 | + { limit: 1025 }, |
| 28 | + ]); |
| 29 | + |
| 30 | + it("should return global logs", async () => { |
| 31 | + await integration.connectMcpClient(); |
| 32 | + const response = await integration.mcpClient().callTool({ |
| 33 | + name: "mongodb-logs", |
| 34 | + arguments: {}, |
| 35 | + }); |
| 36 | + |
| 37 | + const elements = getResponseElements(response); |
| 38 | + |
| 39 | + // Default limit is 50 |
| 40 | + expect(elements.length).toBeLessThanOrEqual(51); |
| 41 | + expect(elements[0].text).toMatch(/Found: \d+ messages/); |
| 42 | + |
| 43 | + for (let i = 1; i < elements.length; i++) { |
| 44 | + const log = JSON.parse(elements[i].text); |
| 45 | + expect(log).toHaveProperty("t"); |
| 46 | + expect(log).toHaveProperty("msg"); |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + it("should return startupWarnings logs", async () => { |
| 51 | + await integration.connectMcpClient(); |
| 52 | + const response = await integration.mcpClient().callTool({ |
| 53 | + name: "mongodb-logs", |
| 54 | + arguments: { |
| 55 | + type: "startupWarnings", |
| 56 | + }, |
| 57 | + }); |
| 58 | + |
| 59 | + const elements = getResponseElements(response); |
| 60 | + expect(elements.length).toBeLessThanOrEqual(51); |
| 61 | + for (let i = 1; i < elements.length; i++) { |
| 62 | + const log = JSON.parse(elements[i].text); |
| 63 | + expect(log).toHaveProperty("t"); |
| 64 | + expect(log).toHaveProperty("msg"); |
| 65 | + expect(log).toHaveProperty("tags"); |
| 66 | + expect(log.tags).toContain("startupWarnings"); |
| 67 | + } |
| 68 | + }); |
| 69 | + |
| 70 | + validateAutoConnectBehavior(integration, "mongodb-logs", () => { |
| 71 | + return { |
| 72 | + args: { |
| 73 | + database: integration.randomDbName(), |
| 74 | + collection: "foo", |
| 75 | + }, |
| 76 | + validate: (content) => { |
| 77 | + const elements = getResponseElements(content); |
| 78 | + expect(elements.length).toBeLessThanOrEqual(51); |
| 79 | + expect(elements[0].text).toMatch(/Found: \d+ messages/); |
| 80 | + }, |
| 81 | + }; |
| 82 | + }); |
| 83 | +}); |
0 commit comments