Skip to content

feat(mcp): analytics MCP tools#331

Open
jamby77 wants to merge 14 commits into
feature/329-mcp-ai-toolsfrom
feature/329-mcp-analytics-tools
Open

feat(mcp): analytics MCP tools#331
jamby77 wants to merge 14 commits into
feature/329-mcp-ai-toolsfrom
feature/329-mcp-analytics-tools

Conversation

@jamby77

@jamby77 jamby77 commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Adds three read-only analytics MCP tools:

  • get_forecast — capacity forecast per metric kind (opsPerSec, usedMemory, cpuTotal, memFragmentation)
  • get_latency_regressions — persisted p99 latency-regression events (companion to get_anomalies, same store pre-filtered to command_p99), with a graceful note when BetterDB Pro is absent
  • get_largest_keys — largest keys by memory from key-analytics snapshots (companion to get_hot_keys), license-gated

Server side: new community McpAnalyticsController (forecast + latency regressions, optional anomaly-service injection) and a proprietary McpKeyAnalyticsController mirroring the cache-proposals MCP controller so the keyAnalytics license gate (402) actually runs; bundle-absent installs get a friendly client-side message instead of a raw 404.

Stacked on #330. Part of #329.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BeJC3cWSEXFGD7MLMXaCiH


Note

Medium Risk
Changes MCP route ownership and license gating for anomalies/largest-keys, and alters anomaly and largest-key query semantics—worth validating against community vs Pro installs and existing MCP clients.

Overview
Adds read-only MCP analytics tools (get_forecast, get_latency_regressions, get_largest_keys) backed by new HTTP routes, and improves how missing Pro features show up in the client.

API / modules: Community McpAnalyticsController exposes GET …/forecast/:metricKind via MetricForecastingModule. Anomalies and largest-keys MCP endpoints move out of the monolithic McpController into proprietary McpAnomalyController (anomaly detection license + metricType validation) and McpKeyAnalyticsController (keyAnalytics license). createAgentTokenProviders centralizes cloud-mode agent token wiring across MCP-related modules; McpModule drops optional anomaly module import from the core controller.

Data behavior: getLargestKeys now ranks by memoryBytes (with multi-snapshot dedupe and a higher storage fetch cap before applying limit). AnomalyService.getRecentAnomalies unions persisted events with the in-memory cache for recent windows so storage-only events (e.g. command_p99) and cache-only failures both appear.

MCP client: HTTP errors carry status via ApiHttpError; 404 on gated/missing routes returns friendly unavailableResult text instead of a raw failure (anomalies, forecast, largest keys).

UI: Key Analytics “Largest Keys” copy clarifies memory-based ranking and tracking limits.

Reviewed by Cursor Bugbot for commit 6736dbf. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread packages/mcp/src/index.ts
@jamby77
jamby77 force-pushed the feature/329-mcp-analytics-tools branch from f8890e3 to ade4490 Compare July 22, 2026 12:39
@jamby77

jamby77 commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ade4490. Configure here.

@jamby77
jamby77 force-pushed the feature/329-mcp-analytics-tools branch from ade4490 to e8368e1 Compare July 22, 2026 12:45

@jamby77 jamby77 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stack review, #331 layer: one licensing gap, two issues on the get_largest_keys tool contract, and a wiring duplication.

Comment thread apps/api/src/mcp/mcp-analytics.controller.ts Outdated
Comment thread packages/mcp/src/index.ts Outdated
Comment thread packages/mcp/src/index.ts
Comment thread proprietary/key-analytics/key-analytics.module.ts Outdated

@jamby77 jamby77 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more from the stack review, on reuse.

Comment thread apps/api/src/mcp/mcp-analytics.controller.ts Outdated
@jamby77
jamby77 force-pushed the feature/329-mcp-analytics-tools branch from e8368e1 to 839748d Compare July 23, 2026 07:18
Comment thread proprietary/key-analytics/key-analytics.service.ts Outdated
Comment thread apps/api/src/mcp/mcp.module.ts
@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread proprietary/key-analytics/key-analytics.service.ts Outdated
Comment thread packages/mcp/src/index.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

4 issues from previous reviews remain unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a36c4cd. Configure here.

@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a36c4cd. Configure here.

Comment thread proprietary/key-analytics/key-analytics.service.ts
@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread proprietary/key-analytics/key-analytics.service.ts
Comment thread proprietary/anomaly-detection/mcp-anomaly.controller.ts
@jamby77
jamby77 force-pushed the feature/329-mcp-analytics-tools branch from a36c4cd to f4daf18 Compare July 23, 2026 08:46
@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread proprietary/key-analytics/key-analytics.service.ts
Comment thread proprietary/key-analytics/mcp-key-analytics.controller.ts
@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread proprietary/anomaly-detection/anomaly.service.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

1 issue from previous review remains unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6946a7c. Configure here.

@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit dee1143. Configure here.

@jamby77
jamby77 force-pushed the feature/329-mcp-analytics-tools branch from dee1143 to c77f3ae Compare July 23, 2026 09:19
@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread proprietary/anomaly-detection/anomaly.service.ts
@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread packages/mcp/src/index.ts
@jamby77

jamby77 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6736dbf. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant