-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add User-Agent tracking for analytics #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add clientUserAgent support to identify context-connectors usage in
Augment backend analytics. This enables tracking:
- Which product is calling (context-connectors vs other SDK consumers)
- Which interface is being used (CLI, SDK, MCP, agent)
- For MCP: which client is connecting (prepared for future use)
User-Agent format: context-connectors/{version} via:{interface}
Changes:
- Add buildClientUserAgent() utility in src/core/utils.ts
- Add clientUserAgent option to Indexer, SearchClient, MultiIndexRunner, CLIAgent
- Pass clientUserAgent to DirectContext and AugmentLanguageModel
- Set appropriate interface IDs in CLI commands (cli-search, cli-index, cli-agent, mcp)
- Export ClientInterface and MCPClientInfo types
- Add unit tests for buildClientUserAgent
Requires auggie-sdk >= 0.1.15 (PR #47 merged, awaiting npm release)
Agent-Id: agent-0d00d75b-1ac5-4e85-a310-90e1af295ee3
🤖 Augment PR SummarySummary: Adds a consistent Changes:
Technical Notes: Version is resolved at runtime from 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/core/utils.test.ts
Outdated
| describe("buildClientUserAgent", () => { | ||
| it("should build basic user agent for cli-search", () => { | ||
| const ua = buildClientUserAgent("cli-search"); | ||
| expect(ua).toMatch(/^context-connectors\/\d+\.\d+\.\d+ via:cli-search$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/core/utils.ts
Outdated
| function getVersion(): string { | ||
| if (cachedVersion === null) { | ||
| const require = createRequire(import.meta.url); | ||
| const pkg = require('../../package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getVersion() assumes ../../package.json is always readable at runtime; in bundled/packaged environments where package.json isn’t present this will throw and make buildClientUserAgent() crash callers. It may be worth making the version lookup resilient so UA building can’t break normal execution.
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
src/core/utils.ts
Outdated
| mcpClientInfo?: MCPClientInfo | ||
| ): string { | ||
| let ua = `context-connectors/${getVersion()} via:${clientInterface}`; | ||
| if (mcpClientInfo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an MCP client (like Claude Desktop or Cursor) connects, we now
capture its name and version from the initialize request and include
it in the User-Agent string.
Format: context-connectors/{version} via:mcp client:{name}/{version}
Example: context-connectors/0.1.3 via:mcp client:claude-desktop/1.0.0
Changes:
- Add updateClientUserAgent() method to MultiIndexRunner
- Handle InitializeRequestSchema in mcp-server.ts to capture client info
- Update User-Agent dynamically after receiving MCP client info
Agent-Id: agent-0d00d75b-1ac5-4e85-a310-90e1af295ee3
Change format from:
context-connectors/{version} via:{interface}
context-connectors/{version} via:mcp client:{name}/{version}
To:
context-connectors/{version}/{interface}
context-connectors/{version}/mcp/{clientName}/{clientVersion}
This matches the auggie CLI format: augment.cli/{version}/{mode}/{clientName}
Also:
- Add sanitizeUserAgentToken() per RFC 9110 (same as auggie CLI)
- Make MCPClientInfo.version optional
- Limit client name to 32 chars, version to 8 chars
Change User-Agent format from context-connectors/{version} to augment.ctxc/{version}
to be consistent with other Augment products (augment.cli, augment.intellij, etc.)
Use augment.ctxc.{product}/{version} format:
- augment.ctxc.cli/{version} for all CLI commands (search, agent, index)
- augment.ctxc.mcp/{version} for MCP server
- augment.ctxc.sdk/{version} for SDK/programmatic usage
MCP with client info: augment.ctxc.mcp/{version}/{clientName}/{clientVersion}
In bundled/packaged environments where package.json isn't present, getVersion() now returns 'unknown' instead of throwing an error. This prevents buildClientUserAgent() from crashing callers.
….json read - Add scripts/generate-version.js to generate src/generated/version.ts at build time - Update utils.ts to import VERSION from generated file instead of reading package.json - Add prebuild script to package.json to run version generation before build - Add src/generated/ to .gitignore (auto-generated files) This makes version lookup resilient in bundled/serverless environments where package.json may not be available at runtime. Agent-Id: agent-0d00d75b-1ac5-4e85-a310-90e1af295ee3
|
augment review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/core/utils.ts
Outdated
| * Shared utility functions | ||
| */ | ||
|
|
||
| import { VERSION } from "../generated/version.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildClientUserAgent() now imports VERSION from ../generated/version.js, but src/generated/ is gitignored and isn’t created by test/cli scripts, so a clean checkout can fail at import time (e.g., vitest run, tsx src/bin/index.ts). Consider ensuring the generator runs for those entry points too, not just via prebuild.
Other Locations
package.json:27
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
src/clients/mcp-server.ts
Outdated
| // Return the standard initialize response | ||
| // The Server class will merge our capabilities with the standard response | ||
| return { | ||
| protocolVersion: "2024-11-05", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This custom initialize handler hardcodes protocolVersion: "2024-11-05"; if an MCP client negotiates a different protocol version, initialization could fail or behave unexpectedly. Consider deriving the response protocol version from the request/SDK defaults so protocol negotiation stays correct.
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
- Add pretest script for unit tests - Add precli scripts for CLI commands - Add pretest:integration for integration tests - Add prepare script for npm install This ensures src/generated/version.ts exists before any script that imports buildClientUserAgent() runs.
- Remove redundant pre-scripts (pretest, precli, etc.) - Keep only prebuild and prepare for the happy path - Use createRequire with try/catch for resilient fallback - Try .js first (compiled), then .ts (dev/test) for compatibility - Falls back to 'unknown' instead of crashing on missing version file
- Read version from package.json at runtime (like auggie-sdk) - Remove generated version file approach - Remove prebuild/prepare scripts - Single source of truth for version
Instead of overriding the initialize handler (which bypassed the SDK's protocol version negotiation), use the oninitialized callback to capture MCP client info after the SDK handles initialization. This ensures: - Protocol version negotiation works correctly with all MCP clients - Client info is still captured for User-Agent tracking - No hardcoded protocol version that could become stale
|
augment review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Use the SDK's oninitialized callback to capture MCP client info | ||
| // This preserves the SDK's protocol version negotiation | ||
| server.oninitialized = () => { | ||
| const clientInfo = server.getClientVersion(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we confirm @modelcontextprotocol/sdk (at our pinned version) actually exposes server.getClientVersion() and the server.oninitialized callback? If either isn’t supported, this will throw at runtime and prevent the MCP server from starting.
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed! Both APIs exist in @modelcontextprotocol/sdk version 1.25.3:
Agent-Id: agent-0d00d75b-1ac5-4e85-a310-90e1af295ee3
Summary
Adds User-Agent tracking to identify context-connectors usage in Augment backend analytics.
User-Agent Format
Consistent with auggie CLI format (
augment.cli/{version}/{mode}):ctxc searchaugment.ctxc.cli/0.1.3ctxc agentaugment.ctxc.cli/0.1.3ctxc indexaugment.ctxc.cli/0.1.3ctxc mcpaugment.ctxc.mcp/0.1.3ctxc mcp+ Claude Desktopaugment.ctxc.mcp/0.1.3/claude-desktop/1.0.0augment.ctxc.sdk/0.1.3MCP Client Info
When an MCP client connects, the User-Agent is updated to include client info:
augment.ctxc.mcp/{version}/{clientName}/{clientVersion}Changes
New utilities (
src/core/utils.ts)buildClientUserAgent(product, mcpClientInfo?)- Constructs User-Agent stringsanitizeForUserAgent(value, maxLength)- RFC 9110 compliant sanitizationgetVersion()- Gets package version at runtimeUpdated configs
IndexerConfig.clientUserAgent- Passed toDirectContext.create()SearchClientConfig.clientUserAgent- Passed toDirectContext.import()MultiIndexRunnerConfig.clientUserAgent- Passed toSearchClientCLIAgentConfig.clientUserAgent- Passed toAugmentLanguageModelCLI commands
cmd-search.ts- Usesaugment.ctxc.clicmd-agent.ts- Usesaugment.ctxc.clicmd-index.ts- Usesaugment.ctxc.climcp-server.ts- Usesaugment.ctxc.mcp, captures MCP client info on initializeDependencies
Requires
@augmentcode/auggie-sdk>= 0.1.15 withclientUserAgentoption (PR #47 merged).Testing
buildClientUserAgentandsanitizeForUserAgent