Skip to content

DRIVERS-3529 Add env.agent to handshake metadata for agentic client identification - #1967

Open
aclark4life wants to merge 1 commit into
mongodb:masterfrom
aclark4life:DRIVERS-3529
Open

DRIVERS-3529 Add env.agent to handshake metadata for agentic client identification#1967
aclark4life wants to merge 1 commit into
mongodb:masterfrom
aclark4life:DRIVERS-3529

Conversation

@aclark4life

@aclark4life aclark4life commented Jul 22, 2026

Copy link
Copy Markdown

Summary

Adds a client.env.agent field to the MongoDB Handshake metadata so that agent-mediated usage of MongoDB (AI coding assistants / agentic clients such as Claude Code, Cursor, Gemini CLI) can be distinguished from direct human usage. See DRIVERS-3529.

Changes

  • Add env.agent to the client document structure.

  • New Agent subsection defining detection via an ordered environment-variable table (first populated match wins):

    Order Env var client.env.agent value
    1 AI_AGENT raw value
    2 AGENT raw value
    3 CLAUDECODE claude-code
    4 CURSOR_AGENT cursor
    5 GEMINI_CLI gemini-cli
    6 CODEX_SANDBOX codex
    7 AUGMENT_AGENT augment
    8 OPENCODE_CLIENT opencode

    Generic vars (AI_AGENT/AGENT) report their raw value; the six known agents report a fixed label. Generic wins over known. "Populated" = present with a non-empty value. Omitted entirely when none are populated; determination MUST NOT raise a user-visible error.

  • Preserve env.agent alongside env.name in the size-limit truncation cascade.

  • Add prose Test 2: Test that agent metadata is properly captured (renumbers the auth test to Test 3).

Open questions for reviewers

  • Fixed label taxonomy: chose kebab-case (claude-code, gemini-cli) for a normalized, tool-agnostic taxonomy per the design memo. Product Analytics owns the taxonomy — happy to switch to the raw env-var forms if preferred.

Notes

Per the aligned approach with @jkovacs, v1 targets the top-traffic drivers (Node, Python). The other language tickets are split from DRIVERS-3529 and blocked on this spec change. PyMongo implementation is tracked under PYTHON-5929.


Please complete the following before merging:

  • Is the relevant DRIVERS ticket in the PR title?
  • Update changelog.
  • Test changes in at least one language driver.
  • Test these changes against all server versions and topologies (including standalone, replica set, and sharded clusters).

@aclark4life
aclark4life marked this pull request as ready for review July 22, 2026 19:05
@aclark4life
aclark4life requested a review from a team as a code owner July 22, 2026 19:05
@aclark4life
aclark4life requested a review from vbabanin July 22, 2026 19:05
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