Skip to content

Commit c16b622

Browse files
committed
feat: add --local option
1 parent 221722a commit c16b622

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/agent-cli/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ npm run start "place an order" -- --userId user123
1818
# Start a new session
1919
npm run start "hello" -- --new
2020

21+
# Use local MCP server
22+
npm run start "show me the menu" -- --local
23+
2124
# Combine options
22-
npm run start "cancel my order" -- --userId user123 --new
25+
npm run start "cancel my order" -- --userId user123 --new --local
2326
```
2427

2528
The CLI maintains conversation history in `~/.burger-agent-cli/burger-agent-cli.json` for context across sessions.
2629

30+
### Options
31+
32+
- `--userId <userId>`: Specify a user ID for operations that require user context (like placing or cancelling orders)
33+
- `--new`: Start a new conversation session, discarding previous history
34+
- `--verbose`: Show intermediate steps and tool calls during execution
35+
- `--local`: Force connection to localhost MCP server (http://localhost:3000/mcp) instead of using BURGER_MCP_URL environment variable
36+
2737
### `npm run build`
2838

2939
To build the CLI for production to the `dist` folder.

packages/agent-cli/agent-cli.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface CliArgs {
4040
userId?: string;
4141
isNew: boolean;
4242
verbose: boolean;
43+
local: boolean;
4344
}
4445

4546
interface SessionData {
@@ -51,18 +52,20 @@ function parseArgs(): CliArgs {
5152
const args = process.argv.slice(2);
5253

5354
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
54-
console.log('Usage: agent-cli <question> [--userId <userId>] [--new] [--verbose]');
55+
console.log('Usage: agent-cli <question> [--userId <userId>] [--new] [--verbose] [--local]');
5556
console.log(' question: Your question about burger orders');
5657
console.log(' --userId: Optional user ID (needed for some tasks)');
5758
console.log(' --new: Start a new session');
5859
console.log(' --verbose: Enable verbose mode to show intermediate steps');
60+
console.log(' --local: Force connection to localhost MCP server');
5961
process.exit(0);
6062
}
6163

6264
const questionParts: string[] = [];
6365
let userId: string | undefined;
6466
let isNew = false;
6567
let verbose = false;
68+
let local = false;
6669

6770
for (let i = 0; i < args.length; i++) {
6871
const arg = args[i];
@@ -74,6 +77,8 @@ function parseArgs(): CliArgs {
7477
isNew = true;
7578
} else if (arg === '--verbose') {
7679
verbose = true;
80+
} else if (arg === '--local') {
81+
local = true;
7782
} else {
7883
questionParts.push(arg);
7984
}
@@ -86,7 +91,7 @@ function parseArgs(): CliArgs {
8691
process.exit(1);
8792
}
8893

89-
return { question, userId, isNew, verbose };
94+
return { question, userId, isNew, verbose, local };
9095
}
9196

9297
async function getSessionPath(): Promise<string> {
@@ -123,9 +128,10 @@ function convertHistoryToMessages(history: SessionData['history']): BaseMessage[
123128
}
124129

125130
export async function run() {
126-
const { question, userId, isNew, verbose } = parseArgs();
131+
const { question, userId, isNew, verbose, local } = parseArgs();
127132
const azureOpenAiEndpoint = process.env.AZURE_OPENAI_API_ENDPOINT;
128-
const burgerMcpEndpoint = process.env.BURGER_MCP_URL ?? 'http://localhost:3000/mcp';
133+
const localMcpEndpoint = 'http://localhost:3000/mcp';
134+
const burgerMcpEndpoint = local ? localMcpEndpoint : (process.env.BURGER_MCP_URL ?? localMcpEndpoint);
129135

130136
let client: Client | undefined;
131137

0 commit comments

Comments
 (0)