Skip to content

Commit 81b4dbf

Browse files
committed
Merge origin/main into dynamic-mcp-tools
Merge commits: - ff69f62: Fix search/list/read operations to use indexed commit ref (#13) - ef6a46a: feat: add consistent User-Agent string (#14) Resolved conflicts: - src/clients/mcp-server.ts: Kept Discovery mode logic while integrating User-Agent changes - src/clients/multi-index-runner.ts: Added clientUserAgent parameter and updateClientUserAgent method Fixed type errors from main branch: - Removed invalid clientUserAgent parameter from DirectContext.create/import calls - Removed invalid clientUserAgent parameter from AugmentLanguageModel config All tests pass and build succeeds.
2 parents dcf2386 + ff69f62 commit 81b4dbf

17 files changed

+1689
-986
lines changed

package-lock.json

Lines changed: 962 additions & 956 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"cli": "tsx src/bin/index.ts",
2121
"cli:index": "tsx src/bin/index.ts index",
2222
"cli:search": "tsx src/bin/index.ts search",
23-
"test:integration": "tsx test/augment-provider.ts && tsx test/cli-agent.ts",
23+
"test:integration": "tsx test/augment-provider.ts && tsx test/cli-agent.ts && tsx test/resolved-ref.ts",
2424
"format": "biome format --write .",
2525
"lint": "biome check .",
2626
"lint:fix": "biome check --write ."
@@ -68,7 +68,7 @@
6868
}
6969
},
7070
"dependencies": {
71-
"@augmentcode/auggie-sdk": "^0.1.14",
71+
"@augmentcode/auggie-sdk": "^0.1.15",
7272
"cheerio": "^1.1.2",
7373
"commander": "^12.0.0",
7474
"ignore": "^5.3.0",

src/bin/cmd-agent.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as readline from "readline";
77
import { CLIAgent, type Provider } from "../clients/cli-agent.js";
88
import { MultiIndexRunner } from "../clients/multi-index-runner.js";
99
import { CompositeStoreReader, parseIndexSpecs } from "../stores/index.js";
10+
import { buildClientUserAgent } from "../core/utils.js";
1011

1112
const PROVIDER_DEFAULTS: Record<Provider, string> = {
1213
openai: "gpt-5-mini",
@@ -50,9 +51,13 @@ export const agentCommand = new Command("agent")
5051
const store = await CompositeStoreReader.fromSpecs(specs);
5152

5253
// Create multi-index runner
54+
// Build User-Agent for analytics tracking
55+
const clientUserAgent = buildClientUserAgent("cli");
56+
5357
const runner = await MultiIndexRunner.create({
5458
store,
5559
searchOnly: options.searchOnly,
60+
clientUserAgent,
5661
});
5762

5863
console.log("\x1b[1;36mContext Connectors Minimal Agent\x1b[0m");
@@ -73,6 +78,7 @@ export const agentCommand = new Command("agent")
7378
model,
7479
maxSteps: options.maxSteps,
7580
verbose: options.verbose,
81+
clientUserAgent,
7682
});
7783
await agent.initialize();
7884

src/bin/cmd-index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Indexer } from "../core/indexer.js";
77
import { Source } from "../sources/types.js";
88
import { FilesystemStore } from "../stores/filesystem.js";
99
import { getS3Config } from "../stores/s3-config.js";
10+
import { buildClientUserAgent } from "../core/utils.js";
1011

1112
// Shared store options
1213
interface StoreOptions {
@@ -49,7 +50,9 @@ async function runIndex(
4950
sourceType: string
5051
) {
5152
console.log(`Indexing ${sourceType} source...`);
52-
const indexer = new Indexer();
53+
const indexer = new Indexer({
54+
clientUserAgent: buildClientUserAgent("cli"),
55+
});
5356
const result = await indexer.index(source, store, indexKey);
5457

5558
console.log(`\nIndexing complete!`);

src/bin/cmd-search.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getSourceIdentifier } from "../core/types.js";
99
import { getS3Config } from "../stores/s3-config.js";
1010
import { parseIndexSpec } from "../stores/index-spec.js";
1111
import type { IndexStoreReader } from "../stores/types.js";
12+
import { buildClientUserAgent } from "../core/utils.js";
1213

1314
export const searchCommand = new Command("search")
1415
.description("Search indexed content and answer questions (use --raw for raw results)")
@@ -83,6 +84,7 @@ export const searchCommand = new Command("search")
8384
const client = new SearchClient({
8485
store,
8586
indexName: indexKey,
87+
clientUserAgent: buildClientUserAgent("cli"),
8688
});
8789

8890
await client.initialize();

src/clients/cli-agent.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ export interface CLIAgentSingleConfig {
7979
stream?: boolean;
8080
/** Custom system prompt. Uses a sensible default if not provided. */
8181
systemPrompt?: string;
82+
/**
83+
* Custom User-Agent string for analytics tracking.
84+
* When provided, this is sent to the Augment API for usage analytics.
85+
* Only used when provider is 'augment'.
86+
*/
87+
clientUserAgent?: string;
8288
}
8389

8490
/**
@@ -110,6 +116,12 @@ export interface CLIAgentMultiConfig {
110116
stream?: boolean;
111117
/** Custom system prompt. Uses a sensible default if not provided. */
112118
systemPrompt?: string;
119+
/**
120+
* Custom User-Agent string for analytics tracking.
121+
* When provided, this is sent to the Augment API for usage analytics.
122+
* Only used when provider is 'augment'.
123+
*/
124+
clientUserAgent?: string;
113125
}
114126

115127
/** Configuration for the CLI agent */
@@ -136,7 +148,8 @@ Be concise but thorough. Reference specific files and line numbers when helpful.
136148
*/
137149
async function loadModel(
138150
provider: Provider,
139-
modelName: string
151+
modelName: string,
152+
clientUserAgent?: string
140153
): Promise<LanguageModel> {
141154
switch (provider) {
142155
case "openai": {
@@ -179,6 +192,7 @@ async function loadModel(
179192
return new AugmentLanguageModel(modelName, {
180193
apiKey: credentials.apiKey,
181194
apiUrl: credentials.apiUrl,
195+
clientUserAgent,
182196
}) as unknown as LanguageModel;
183197
}
184198
default:
@@ -223,6 +237,7 @@ export class CLIAgent {
223237
private readonly verbose: boolean;
224238
private readonly stream: boolean;
225239
private readonly systemPrompt: string;
240+
private readonly clientUserAgent?: string;
226241
private readonly tools: ToolSet;
227242
private messages: CoreMessage[] = [];
228243

@@ -242,6 +257,7 @@ export class CLIAgent {
242257
this.verbose = config.verbose ?? false;
243258
this.stream = config.stream ?? true;
244259
this.systemPrompt = config.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
260+
this.clientUserAgent = config.clientUserAgent;
245261
this.tools = this.runner ? this.createMultiIndexTools() : this.createSingleClientTools();
246262
}
247263

@@ -393,7 +409,7 @@ export class CLIAgent {
393409
* @throws Error if the provider package is not installed
394410
*/
395411
async initialize(): Promise<void> {
396-
this.model = await loadModel(this.provider, this.modelName);
412+
this.model = await loadModel(this.provider, this.modelName, this.clientUserAgent);
397413
}
398414

399415
/**

src/clients/mcp-server.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ import {
4040
import type { IndexStoreReader, IndexStore } from "../stores/types.js";
4141
import type { Source } from "../sources/types.js";
4242
import { MultiIndexRunner } from "./multi-index-runner.js";
43+
import { buildClientUserAgent, type MCPClientInfo } from "../core/utils.js";
4344
import {
4445
SEARCH_DESCRIPTION,
4546
LIST_FILES_DESCRIPTION,
4647
READ_FILE_DESCRIPTION,
4748
withListIndexesReference,
4849
withIndexList,
4950
} from "./tool-descriptions.js";
50-
5151
/**
5252
* Configuration for the MCP server.
5353
*/
@@ -81,7 +81,6 @@ export interface MCPServerConfig {
8181
*/
8282
discovery?: boolean;
8383
}
84-
8584
/**
8685
* Create an MCP server instance.
8786
*
@@ -105,14 +104,20 @@ export async function createMCPServer(
105104
config: MCPServerConfig
106105
): Promise<Server> {
107106
// Create shared runner for multi-index operations
107+
// Build User-Agent for analytics tracking
108+
const clientUserAgent = buildClientUserAgent("mcp");
109+
108110
const runner = await MultiIndexRunner.create({
109111
store: config.store,
110112
indexNames: config.indexNames,
111113
searchOnly: config.searchOnly,
114+
clientUserAgent,
112115
});
113116

117+
const { indexNames, indexes } = runner;
114118
const searchOnly = !runner.hasFileOperations();
115-
119+
// Format index list for tool descriptions
120+
const indexListStr = runner.getIndexListString();
116121
// Create MCP server
117122
const server = new Server(
118123
{
@@ -125,7 +130,19 @@ export async function createMCPServer(
125130
},
126131
}
127132
);
128-
133+
// Use the SDK's oninitialized callback to capture MCP client info
134+
// This preserves the SDK's protocol version negotiation
135+
server.oninitialized = () => {
136+
const clientInfo = server.getClientVersion();
137+
if (clientInfo) {
138+
const mcpClientInfo: MCPClientInfo = {
139+
name: clientInfo.name,
140+
version: clientInfo.version,
141+
};
142+
const updatedUserAgent = buildClientUserAgent("mcp", mcpClientInfo);
143+
runner.updateClientUserAgent(updatedUserAgent);
144+
}
145+
};
129146
// Define tool type for type safety
130147
type Tool = {
131148
name: string;
@@ -152,12 +169,10 @@ export async function createMCPServer(
152169
readFileDescription = withListIndexesReference(READ_FILE_DESCRIPTION);
153170
} else {
154171
// Fixed mode: include enum with index list
155-
const indexListStr = runner.getIndexListString();
156172
searchDescription = withIndexList(SEARCH_DESCRIPTION, indexListStr);
157173
listFilesDescription = withIndexList(LIST_FILES_DESCRIPTION, indexListStr);
158174
readFileDescription = withIndexList(READ_FILE_DESCRIPTION, indexListStr);
159175
}
160-
161176
// List available tools
162177
server.setRequestHandler(ListToolsRequestSchema, async () => {
163178
const tools: Tool[] = [
@@ -194,7 +209,6 @@ export async function createMCPServer(
194209
},
195210
},
196211
];
197-
198212
// Only advertise file tools if not in search-only mode
199213
if (!searchOnly) {
200214
tools.push(
@@ -274,10 +288,8 @@ export async function createMCPServer(
274288
}
275289
);
276290
}
277-
278291
return { tools };
279292
});
280-
281293
// Handle tool calls
282294
server.setRequestHandler(CallToolRequestSchema, async (request) => {
283295
const { name, arguments: args } = request.params;
@@ -302,7 +314,6 @@ export async function createMCPServer(
302314
try {
303315
const indexName = args?.index_name as string;
304316
const client = await runner.getClient(indexName);
305-
306317
switch (name) {
307318
case "search": {
308319
const result = await client.search(args?.query as string, {
@@ -314,7 +325,6 @@ export async function createMCPServer(
314325
],
315326
};
316327
}
317-
318328
case "list_files": {
319329
if (searchOnly) {
320330
return {
@@ -335,7 +345,6 @@ export async function createMCPServer(
335345
content: [{ type: "text", text }],
336346
};
337347
}
338-
339348
case "read_file": {
340349
if (searchOnly) {
341350
return {
@@ -365,7 +374,6 @@ export async function createMCPServer(
365374
content: [{ type: "text", text: result.contents ?? "" }],
366375
};
367376
}
368-
369377
default:
370378
return {
371379
content: [{ type: "text", text: `Unknown tool: ${name}` }],
@@ -379,10 +387,8 @@ export async function createMCPServer(
379387
};
380388
}
381389
});
382-
383390
return server;
384391
}
385-
386392
/**
387393
* Run an MCP server with stdio transport.
388394
*
@@ -413,4 +419,3 @@ export async function runMCPServer(config: MCPServerConfig): Promise<void> {
413419
const transport = new StdioServerTransport();
414420
await server.connect(transport);
415421
}
416-

0 commit comments

Comments
 (0)