Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

🎃 Export the audit log as CSV or JSON from /logs

未关闭
#849 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

Start with the list filters in packages/backend/src/audit/audit.controller.ts and orgScope()/getRecentInvocations() in audit.service.ts; then read the logs page and audit client paths listed in the issue. Run the backend tests with cd packages/backend && npm test and add the specified CSV utility tests. Done means the streamed export honors filters, admin and organization restrictions, row cap and truncation header, with the frontend button and API docs updated.

由索引模型根据 Issue 内容生成。

描述

enhancement hacktoberfest help wanted

Part of the October Challenge #846.

Why

The Audit Log page (/logs) only lets you page through tool calls 50 at a time. Admins who need to send a compliance report, look into an incident in a spreadsheet, or attach evidence to a support ticket have nothing to download. Most API gateways and MCP platforms (Kong, Tyk, Apigee, Postman monitors) have a "download logs" button. This issue adds a streamed export that applies the filters the user already has set.

Self-hosted vs Cloud

  • Self-hosted: enabled in Community and Business. Not a Business feature: do not touch ee/.
  • Cloud (DEPLOYMENT_MODE=cloud): enabled, behaves the same. Cloud is multi-tenant, so the export must always be scoped to the caller's organization: refuse with 403 when req.user.organizationId is not set, and never fall back to unscoped rows. One tenant can hold millions of rows (see the comment in bound-payload.ts), so the row cap and the throttle are required.
  • Who can use it: ADMIN only (@Roles('ADMIN') + RolesGuard). Every role can view the list today, but a bulk download of the whole org's call payloads is a bigger step, so it is limited to admins. Hide the button for other roles. The data is always filtered to the caller's organization.

What to build

  1. Backend: GET /api/audit/invocations/export?format=csv|json in audit.controller.ts. It takes the same filters as the list (status, search, connectorId, mcpServerId, toolId) plus optional ISO from/to on createdAt.
  2. Move the where construction out of getRecentInvocations() into one helper (e.g. buildInvocationWhere(filters)) that both the list and the export call, so the two cannot drift apart.
  3. Stream the response: read in batches (e.g. 1000 rows, keyset pagination on createdAt/id, newest first) and write each batch to res. Never load everything into memory. Cap at AUDIT_EXPORT_MAX_ROWS (default 50000). Send X-Export-Truncated: true when the cap was hit (do a count first). Set Content-Disposition: attachment; filename="anythingmcp-logs-YYYY-MM-DD.csv". Throttle with @Throttle({ default: { limit: 5, ttl: 60_000 } }).
  4. Columns (only data the page already shows): createdAt (ISO), status, durationMs, tool, connector, connectorType, mcpServer, userEmail, authMethod, apiKeyName, error. JSON additionally includes the input/output excerpts exactly as stored. Do not export intent, costMicros, usedProxy, the raw clientInfo blob, internal ids other than the invocation id, or anything else the UI does not show.
  5. CSV safety: RFC 4180 quoting (wrap in quotes, double any "), and escape formula injection: prefix any cell that starts with =, +, -, @, tab or CR with '. Put this in a small pure function (e.g. packages/backend/src/audit/csv.util.ts) so it can be unit-tested. JSON: either one array or NDJSON. Pick one and document it.
  6. Frontend: an "Export" button (with a CSV/JSON choice) in the page actions next to Refresh. Call it with the current filters, fetch with the Bearer token, download the result as a Blob (same pattern as connectors/page.tsx:139-149), and show a notice when X-Export-Truncated is set. Add an audit.exportInvocations() helper in lib/api.ts. The shared request() helper parses JSON, so it can't be used for the file.

Where to look

  • packages/backend/src/audit/audit.controller.ts:13-38: the list endpoint and its filters.
  • packages/backend/src/audit/audit.service.ts:176-225: orgScope() and getRecentInvocations().
  • packages/backend/src/audit/bound-payload.ts:16: _amcp_truncated marker. Stored payloads are excerpts, so don't try to recover full bodies.
  • packages/backend/src/knowledge-graph/kg.controller.ts:22,52: RolesGuard + @Roles('ADMIN') pattern.
  • packages/backend/src/auth/login.controller.ts:137: @Throttle pattern.
  • packages/backend/src/auth/login.controller.ts:87: @Res() usage with Express.
  • packages/frontend/src/app/logs/page.tsx:116-134 (filters), :183-207 (the exportButton variable is actually Refresh; rename it), :204-208 (actions).
  • packages/frontend/src/app/settings/layout.tsx:54: user?.role === 'ADMIN' check.
  • packages/frontend/src/lib/api.ts:735-747: audit client.

Acceptance criteria

  • Export applies every active filter, and only the caller's org rows are ever returned (unit test: organizationId is in the where; a missing org gives 403).
  • Non-admins get 403, and the button is hidden for them.
  • Results are streamed in batches, the row cap is honored, and the truncation header is set.
  • csv.util.spec.ts covers quoting, newlines inside cells, and =cmd|' /C calc'!A0-style injection.
  • audit.service.spec.ts / a new controller spec covers the shared where-builder (cd packages/backend && npm test).
  • docs/api-reference.md Audit section (line 219) documents the endpoint. Also fix the existing examples at lines 226-236, which use toolName/from/to params the list endpoint does not support.

Out of scope

  • Scheduled exports, emailing exports, S3/SIEM push.
  • Exporting security events or product events.
  • Changing what is stored in tool_invocations, or the retention policy.

Size

M (1–2 days)

How to claim

Comment "I'd like to work on this" and we'll assign you. Rules in #846.

主要语言
TypeScript
星标
856
派生
82
平均合并
7 小时 46 分钟
30 天内合并 PR
221

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

HelpCode-ai/anythingmcp 的其他 Issue

查看 HelpCode-ai/anythingmcp 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。