sentry_capture_exception
Capture and log exceptions with detailed context, error severity, and user information for effective monitoring and debugging in applications.
Instructions
Capture and send an exception to Sentry
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Additional context data | |
| error | Yes | Error message or description | |
| level | No | Severity level of the error | error |
| tags | No | Key-value pairs to tag the error | |
| user | No | User information |
Implementation Reference
- src/index.ts:721-758 (handler)The main handler for the 'sentry_capture_exception' tool. It processes input arguments, creates an Error object if necessary, configures a Sentry scope with level, tags, context, and user data, and captures the exception using Sentry.captureException. Returns a confirmation message.case "sentry_capture_exception": { const { error, level = "error", tags, context, user } = args as any; // Create an Error object if string provided const errorObj = error instanceof Error ? error : new Error(error); // Create a new scope for this specific error Sentry.withScope((scope) => { scope.setLevel(mapSeverityLevel(level)); if (tags) { Object.entries(tags).forEach(([key, value]) => { scope.setTag(key, value as string); }); } if (context) { Object.entries(context).forEach(([key, value]) => { scope.setContext(key, value as any); }); } if (user) { scope.setUser(user); } Sentry.captureException(errorObj); }); return { content: [ { type: "text", text: `Exception captured: ${error}`, }, ], }; }
- src/index.ts:96-134 (schema)Input schema definition for the 'sentry_capture_exception' tool as part of tool registration in ListToolsRequestSchema handler, specifying required 'error' and optional 'level', 'tags', 'context', 'user' properties.{ name: "sentry_capture_exception", description: "Capture and send an exception to Sentry", inputSchema: { type: "object", properties: { error: { type: "string", description: "Error message or description", }, level: { type: "string", enum: ["fatal", "error", "warning", "info", "debug"], description: "Severity level of the error", default: "error", }, tags: { type: "object", description: "Key-value pairs to tag the error", additionalProperties: { type: "string" }, }, context: { type: "object", description: "Additional context data", additionalProperties: true, }, user: { type: "object", description: "User information", properties: { id: { type: "string" }, email: { type: "string" }, username: { type: "string" }, }, }, }, required: ["error"], }, },
- src/index.ts:694-703 (helper)Helper function that maps input string severity levels to Sentry's SeverityLevel enum, used by the sentry_capture_exception handler to set the exception level.function mapSeverityLevel(level: string): Sentry.SeverityLevel { const severityMap: Record<string, Sentry.SeverityLevel> = { fatal: "fatal", error: "error", warning: "warning", info: "info", debug: "debug", }; return severityMap[level] || "error"; }