Repository navigation
Count tool calls per workspace against plan limits (dry-run) - #1996
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds per-workspace limits on tool calls, by plan, in dry-run by default: calls are counted and logged, never refused.
Today one workspace can load the shared backend for hours. On Cloud the only general limit is
McpPrincipalRateLimitGuard, 1,000 MCP requests per minute per caller. Per-tool limits exist only where an admin set them on a role. On 2026-12-05 one trial workspace made 25,000 tool calls in a day, more than 4,000 in some hours. The backend's median /mcp time was highest in exactly those hours.Three limits per workspace (
workspace-call-limits.ts):The values come from the peaks of 2026-11-28 to 12-05 on Cloud. Per minute, only 2 trial bursts would have gone over. Per hour, 2 trial and 3 starter workspaces would have gone over, most of them sustained polling. No team or business workspace would have.
MCP_WORKSPACE_LIMITS:off: nothing is counted.dry-run: counted and logged, never refused. This is the default on Cloud.on: a call over a limit gets a tool error withretryAfter, and the refusal is logged like the existing per-tool rate limit. A refused call uses no quota.Self-hosted defaults to
off.The dry-run also logs, once an hour, how many calls repeated the same tool and arguments within 10 s. That tells us whether a default short cache for repeated reads is worth building.
Changes
mcp-server/workspace-call-limits.ts:WorkspaceCallLimiter.LicenseGuardService.codeRunPlanForOrg, cached for 60 s, with in-flight lookups shared.dynamic-mcp-tools.ts:executeToolbecomes a thin wrapper: admit, runexecuteToolUnlimited, release infinally.ExecuteToolContextandExecuteToolResult.@Optional, so existing fixtures keep working.mcp-server.module.ts: registers the provider.docker-compose.cloud.yml: passesMCP_WORKSPACE_LIMITSthrough. Empty means dry-run.docs/deployment.md,.env.example, regeneratedllms-full.txt.Log lines to watch in dry-run:
[workspace limits dry-run] org …abc123 (trial): more than 1000 tool calls in an hour... would have refused N calls ... in the hour that just ended[workspace limits] repeats in the last hour: ...Ids are shortened. No emails, arguments or results are logged.
Type
Testing
workspace-call-limits.spec.ts: modes; plans; dry-run never refuses; per-minute, per-hour and concurrency refusals inon; refusals use no quota; windows reset; workspaces stay apart; plan lookup failure lets the call through; plan cache; repeat statistics.dynamic-mcp-tools.workspace-limits.spec.ts: the slot is released after success and after a throw; a refusal does not run the tool and is logged; it works without the limiter.prisma generate:npx tsc --noEmit -p tsconfig.json: clean.npx eslinton the changed files: clean.npx jest --maxWorkers=4 src/mcp-server src/license: 85 suites passed, 3 skipped (baseline), 1,984 tests.node scripts/generate-llms-txt.mjs --check: fresh.docker compose -f docker-compose.cloud.yml config: the variable is present and empty.Checklist
npm test): full suite in CICloud: dry-run after deploy; nothing is refused.
oncomes later, by settingMCP_WORKSPACE_LIMITS=onin.envafter a week of logs.Self-hosted: off by default. An admin can opt in.
No database migration. No change under
ee/.Related Issues
Daily check 2026-12-05 (backend slow at peak hours; one workspace polling for hours).