Forward MCP client identity in the API User-Agent - #130
Conversation
|
Warning Review limit reached
Next review available in: 40 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe server captures MCP client name and version after initialization. User-Agent utilities sanitize and format this identity. Mailtrap clients append the identity to a version-aware base User-Agent and create the default client lazily. ChangesMCP identity forwarding
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant MCPClient as MCP client
participant MCPServer as src/server.ts
participant APIClients as src/client.ts
participant MailtrapAPI as Mailtrap API
MCPClient->>MCPServer: complete initialization with client name and version
MCPServer->>APIClients: setMcpClientInfo(client metadata)
APIClients->>MailtrapAPI: send request with dynamically built User-Agent
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/__tests__/client.test.ts (1)
30-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for
getDefaultClient/requireClientidentity capture timing.These tests exercise
getSandboxClient, which rebuilds itsMailtrapClienton every call. They do not exercisegetDefaultClient(used byrequireClient), which memoizes its client instance after the first call insrc/client.ts. Add a test that callsgetDefaultClient(or a function that uses it) once beforesetMcpClientInfo, then again after, to confirm intended behavior. This directly documents and would catch the caching risk noted in thesrc/client.tsreview.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/__tests__/client.test.ts` around lines 30 - 45, Add coverage in the client identity tests for the memoized getDefaultClient/requireClient path: obtain the default client once before setMcpClientInfo, set the MCP identity, then obtain it again and assert the intended User-Agent behavior. Keep the existing getSandboxClient tests unchanged and use the public helper that exercises getDefaultClient where appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/client.ts`:
- Around line 6-7: Remove the defaultClient memoization used by getDefaultClient
and construct a fresh MailtrapClient on every call, so later setMcpClientInfo
updates are reflected in the User-Agent. Keep the existing client configuration
and other getters unchanged.
---
Nitpick comments:
In `@src/__tests__/client.test.ts`:
- Around line 30-45: Add coverage in the client identity tests for the memoized
getDefaultClient/requireClient path: obtain the default client once before
setMcpClientInfo, set the MCP identity, then obtain it again and assert the
intended User-Agent behavior. Keep the existing getSandboxClient tests unchanged
and use the public helper that exercises getDefaultClient where appropriate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a7807afa-4963-4ae8-8bd3-902af63c9454
📒 Files selected for processing (6)
src/__tests__/client.test.tssrc/client.tssrc/config/index.tssrc/server.tssrc/utils/__tests__/userAgent.test.tssrc/utils/userAgent.ts
The MCP server sent a generic User-Agent for every Mailtrap API call, so we could not tell which AI client (Claude Desktop, Cursor, Windsurf, ...) was driving a request. Capture the client name and version reported during the `initialize` handshake and append them to the outgoing API User-Agent, e.g. `mailtrap-mcp/0.6.0 (+https://github.com/mailtrap/mailtrap-mcp) (client: Claude Desktop/1.5.3)`. The identity is read lazily from `server.getClientVersion()` at client construction. That value is populated during the `initialize` request, which always precedes any tool call that builds an API client, so the User-Agent is never stale and no client caches a value captured before the identity was known. The name/version are sanitized before going into the header. The base User-Agent also gains the server version.
486ec1f to
c4abb4f
Compare
What
The MCP server sent a generic User-Agent for every Mailtrap API call, so we couldn't tell which AI client (Claude Desktop, Cursor, Windsurf, Lovable, …) was driving a request. This forwards the client identity so adoption can be measured per client.
How
name+versionfrom theinitializehandshake (server.oninitialized→getClientVersion()).mailtrap-mcp/0.6.0 (+https://github.com/mailtrap/mailtrap-mcp) (client: Claude Desktop/1.5.3).Summary by CodeRabbit
New Features
User-Agent.User-Agentnow includes the server version and repository information.Tests