mongodb-logs
Retrieve recent MongoDB database log events to monitor system activity, troubleshoot issues, or review startup warnings for operational insights.
Instructions
Returns the most recent logged mongod events
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | The type of logs to return. Global returns all recent log entries, while startupWarnings returns only warnings and errors from when the process started. | global |
| limit | No | The maximum number of log entries to return. |
Implementation Reference
- src/tools/mongodb/metadata/logs.ts:29-47 (handler)The main handler function 'execute' that implements the 'mongodb-logs' tool. It connects to MongoDB, runs the 'getLog' command on the admin database, processes the logs (trims and limits), and formats the output.
protected async execute({ type, limit }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> { const provider = await this.ensureConnected(); const result = await provider.runCommandWithCheck("admin", { getLog: type, }); // Trim ending newlines so that when we join the logs we don't insert empty lines // between messages. const logs = (result.log as string[]).slice(0, limit).map((l) => l.trimEnd()); let message = `Found: ${result.totalLinesWritten} messages`; if (result.totalLinesWritten > limit) { message += ` (showing only the first ${limit})`; } return { content: formatUntrustedData(message, logs.join("\n")), }; } - Zod schema defining the input arguments for the tool: 'type' (global or startupWarnings, default global) and 'limit' (1-1024, default 50).
protected argsShape = { type: z .enum(["global", "startupWarnings"]) .optional() .default("global") .describe( "The type of logs to return. Global returns all recent log entries, while startupWarnings returns only warnings and errors from when the process started." ), limit: z .number() .int() .max(1024) .min(1) .optional() .default(50) .describe("The maximum number of log entries to return."), }; - src/tools/mongodb/tools.ts:20-20 (registration)Export of the LogsTool class, which allows it to be included in the main tools registry via src/tools/index.ts.
export { LogsTool } from "./metadata/logs.js"; - src/tools/index.ts:7-12 (registration)The AllTools array that registers all tools, including those from MongoDbTools which encompasses the mongodb-logs tool.
export const AllTools: ToolClass[] = Object.values({ ...MongoDbTools, ...AtlasTools, ...AtlasLocalTools, });