Skip to content

fix(cli): pace generated MCP clients#2809

Merged
mergify[bot] merged 1 commit into
mainfrom
fix/mcp-client-rate-limit-2706
Jun 7, 2026
Merged

fix(cli): pace generated MCP clients#2809
mergify[bot] merged 1 commit into
mainfrom
fix/mcp-client-rate-limit-2706

Conversation

@tmchow

@tmchow tmchow commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

Generated MCP servers now construct their client with a non-zero MCP rate limit instead of passing 0 and disabling pacing. This keeps agent-driven MCP fan-out on the adaptive limiter path while preserving the existing no-cache behavior for fresh MCP reads.

The generator test now covers both normal and sniffed specs, asserts the old client.New(..., 0) call is absent, and compiles the generated module. Golden MCP fixtures were updated for the emitted constant and call-site change.

Closes #2706

Tests

  • go test ./internal/generator -run '^TestGenerateMCPNewClientUsesPoliteRateLimitAndSkipsCache$'
  • scripts/golden.sh verify
  • scripts/verify-generator-output.sh
  • go test ./internal/pipeline
  • go test ./...
  • go build -o ./cli-printing-press ./cmd/cli-printing-press
  • golangci-lint run ./...

Note: the first go test ./... run hit unrelated internal/pipeline live-check 5s subprocess timeouts under load. A targeted go test ./internal/pipeline rerun passed, followed by a passing full go test ./... rerun.

@mergify

mergify Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 require-ready-label-and-ci

Wonderful, this rule succeeded.
  • #changes-requested-reviews-by = 0
  • #review-threads-unresolved = 0
  • check-success = build-and-test
  • check-success = generated-test
  • check-success = go-lint
  • check-success = golden
  • check-success = pr-title
  • check-success = test
  • any of:
    • label = ready-to-merge
    • all of:
      • head = release-please--branches--main
      • title ~= ^chore\(main\): release
  • any of:
    • -files ~= ^(\.github/workflows/|\.github/scripts/|scripts/|\.github/CODEOWNERS$)
    • author = tmchow
    • approved-reviews-by = mvanhorn
    • approved-reviews-by = tmchow
    • author = mvanhorn
  • any of:
    • check-success = Greptile Review
    • label = queued
    • check-neutral = Greptile Review
    • check-skipped = Greptile Review
    • head ~= ^mergify/merge-queue/
    • all of:
      • head = release-please--branches--main
      • title ~= ^chore\(main\): release

@greptile-apps

greptile-apps Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a gap where generated MCP clients for non-sniffed specs passed rate=0 to client.New, disabling pacing entirely, while sniffed-spec clients correctly used rate=2. The fix introduces a defaultMCPRateLimit = 2 constant and removes the SpecSource-based branch so all generated MCP clients share the same adaptive-limiter path.

  • Template (mcp_tools.go.tmpl): removes the {{- if eq .SpecSource "sniffed"}} branch and replaces both client.New(cfg, 60*time.Second, 2) and client.New(cfg, 60*time.Second, 0) with a single call using the new named constant.
  • Test (generator_test.go): renames the helper, adds assertions for the constant value, a NotContains guard against re-introducing rate=0, and a requireGeneratedCompiles call to validate the output compiles.
  • Golden files (6 files): all updated consistently to reflect the new constant and call-site change.

Confidence Score: 5/5

Safe to merge. The change is narrowly scoped to the rate-limit argument of client.New in the MCP client factory, with all six golden fixtures updated and the test extended to compile-check the generated output.

The old branching logic left non-sniffed MCP clients with pacing fully disabled. The fix is a one-liner in the template backed by a named constant, the test guards against the old rate=0 call ever reappearing, and all golden files are consistently updated. No credential paths are touched, no behaviour outside the MCP rate-limit path changes.

No files require special attention. The template and its six golden outputs are all in sync.

Important Files Changed

Filename Overview
internal/generator/templates/mcp_tools.go.tmpl Removes SpecSource-based branch for rate-limit selection; all generated MCP clients now use defaultMCPRateLimit = 2 constant instead of 0 for non-sniffed specs.
internal/generator/generator_test.go Test renamed, extended with assertions for the new constant and NotContains guard against re-introducing rate=0, and strengthened with a compile check on the generated output.
testdata/golden/expected/generate-golden-api/printing-press-golden/internal/mcp/tools.go Golden file updated consistently: adds defaultMCPRateLimit = 2 constant and replaces client.New(..., 0) with client.New(..., defaultMCPRateLimit).
testdata/golden/expected/generate-golden-api-rich-auth/printing-press-rich-auth/internal/mcp/tools.go Golden file updated consistently with the same constant + call-site change; rich-auth variant correctly reflects the template change.
testdata/golden/expected/generate-fastapi-operationids/fastapi-operationids-golden/internal/mcp/tools.go Golden file updated consistently; no issues.
testdata/golden/expected/generate-mcp-api/mcp-cloudflare/internal/mcp/tools.go Golden file updated consistently; no issues.
testdata/golden/expected/generate-public-param-names/public-param-golden/internal/mcp/tools.go Golden file updated consistently; no issues.
testdata/golden/expected/generate-tier-routing-api/tier-routing-golden/internal/mcp/tools.go Golden file updated consistently; no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Generator: Generate MCP tools.go] --> B{SpecSource? — OLD}
    B -->|sniffed| C["client.New(cfg, 60s, 2)\n✅ paced"]
    B -->|other| D["client.New(cfg, 60s, 0)\n❌ unpaced"]

    E[Generator: Generate MCP tools.go] --> F["client.New(cfg, 60s, defaultMCPRateLimit)\ndefaultMCPRateLimit = 2\n✅ always paced — NEW"]

    C --> G[c.NoCache = true]
    D --> G
    F --> H[c.NoCache = true]
Loading

Reviews (1): Last reviewed commit: "fix(cli): pace generated MCP clients" | Re-trigger Greptile

@tmchow tmchow added the ready-to-merge Allow Mergify to queue and merge this PR when protections pass label Jun 7, 2026
mergify Bot added a commit that referenced this pull request Jun 7, 2026
@mergify mergify Bot added the queued PR is in the Mergify merge queue label Jun 7, 2026
mergify Bot added a commit that referenced this pull request Jun 7, 2026
mergify Bot added a commit that referenced this pull request Jun 7, 2026
mergify Bot added a commit that referenced this pull request Jun 7, 2026
@mergify mergify Bot merged commit 477ed2f into main Jun 7, 2026
31 checks passed
@mergify mergify Bot deleted the fix/mcp-client-rate-limit-2706 branch June 7, 2026 19:13
@mergify

mergify Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 24 minutes 9 seconds in the queue, including 23 minutes 55 seconds running CI.

Required conditions to merge

@mergify mergify Bot removed the queued PR is in the Mergify merge queue label Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Allow Mergify to queue and merge this PR when protections pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generator-emitted MCP client passes rate=0 to client.New, bypassing the rate limiter

1 participant