@stage-labs/metro 0.1.0-beta.101 → 0.1.0-beta.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/claude.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawn, spawnSync } from 'node:child_process';
|
|
2
2
|
import { markOnboardingDone } from './onboarding.js';
|
|
3
|
+
import { writeMcpConfig } from './mcp-config.js';
|
|
3
4
|
import { settingsConflicts, settingsFiles } from './claude-settings.js';
|
|
4
5
|
import { localAgents, pickLocalAgent } from './local.js';
|
|
5
6
|
import { PROVIDER_FLAGS } from './provider-flags.js';
|
|
@@ -7,8 +8,9 @@ import { localPort, localUrl } from './runtime.js';
|
|
|
7
8
|
const CHANNEL_FLAGS = ['--dangerously-load-development-channels', 'server:metro'];
|
|
8
9
|
const KEY_HEADER = 'x-metro-key';
|
|
9
10
|
const PROBE_MS = 3_000;
|
|
10
|
-
export const claudeArgs = (extra) => [
|
|
11
|
+
export const claudeArgs = (extra, mcpConfig) => [
|
|
11
12
|
...CHANNEL_FLAGS,
|
|
13
|
+
...(mcpConfig === undefined ? [] : ['--mcp-config', mcpConfig]),
|
|
12
14
|
...extra,
|
|
13
15
|
];
|
|
14
16
|
const set = (env, name) => (env[name] ?? '').trim() !== '';
|
|
@@ -114,19 +116,43 @@ export function runClaude(args, env) {
|
|
|
114
116
|
});
|
|
115
117
|
});
|
|
116
118
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
async function servedKey(decision) {
|
|
120
|
+
if ('key' in decision)
|
|
121
|
+
return decision.key;
|
|
122
|
+
const picked = agentKey(localAgentList(), process.env.METRO_AGENT);
|
|
123
|
+
if ('skip' in picked)
|
|
124
|
+
return null;
|
|
125
|
+
return (await daemonServing()) ? picked.key : null;
|
|
126
|
+
}
|
|
127
|
+
function mcpConfigFor(key, port) {
|
|
128
|
+
if (key === null)
|
|
129
|
+
return null;
|
|
130
|
+
const file = writeMcpConfig(key, port);
|
|
131
|
+
process.stderr.write(`metro claude: the metro MCP server is loaded for this session from the daemon at http://127.0.0.1:${String(port)}/mcp, nothing to add by hand\n`);
|
|
132
|
+
return file;
|
|
133
|
+
}
|
|
134
|
+
function gatewayLaunchEnv(key, port) {
|
|
124
135
|
process.stderr.write(`metro claude: inference goes through the daemon at http://127.0.0.1:${String(port)}/gateway (the Model page decides where)\n`);
|
|
125
|
-
const routed = gatewayEnv(process.env,
|
|
126
|
-
const env = credentialEnv(routed,
|
|
136
|
+
const routed = gatewayEnv(process.env, key, port);
|
|
137
|
+
const env = credentialEnv(routed, key, claudeSignedIn());
|
|
127
138
|
if (env !== routed)
|
|
128
139
|
process.stderr.write("metro claude: Claude Code has no login of its own here, so metro's key stands in as its credential; the Model page must route to Bedrock, OpenRouter or Codex\n");
|
|
129
140
|
if (markOnboardingDone() === 'marked')
|
|
130
141
|
process.stderr.write("metro claude: skipped Claude Code's first-run setup, since it already has a credential here\n");
|
|
131
|
-
return
|
|
142
|
+
return env;
|
|
143
|
+
}
|
|
144
|
+
export async function launchClaude(extra) {
|
|
145
|
+
const decision = await verdict();
|
|
146
|
+
const port = localPort();
|
|
147
|
+
const mcp = mcpConfigFor(await servedKey(decision), port);
|
|
148
|
+
try {
|
|
149
|
+
if ('skip' in decision) {
|
|
150
|
+
process.stderr.write(`metro claude: ${decision.skip}\n`);
|
|
151
|
+
return await runClaude(claudeArgs(extra, mcp?.path), process.env);
|
|
152
|
+
}
|
|
153
|
+
return await runClaude(claudeArgs(extra, mcp?.path), gatewayLaunchEnv(decision.key, port));
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
mcp?.cleanup();
|
|
157
|
+
}
|
|
132
158
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
const METRO_SERVER = 'metro';
|
|
5
|
+
export function metroMcpConfig(agentKey, port) {
|
|
6
|
+
const servers = {
|
|
7
|
+
[METRO_SERVER]: {
|
|
8
|
+
type: 'http',
|
|
9
|
+
url: `http://127.0.0.1:${String(port)}/mcp`,
|
|
10
|
+
headers: { Authorization: `Bearer ${agentKey}` },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
return `${JSON.stringify({ mcpServers: servers }, null, 2)}\n`;
|
|
14
|
+
}
|
|
15
|
+
export function writeMcpConfig(agentKey, port, base = tmpdir()) {
|
|
16
|
+
const dir = mkdtempSync(join(base, 'metro-claude-'));
|
|
17
|
+
const path = join(dir, 'mcp.json');
|
|
18
|
+
writeFileSync(path, metroMcpConfig(agentKey, port), { mode: 0o600 });
|
|
19
|
+
return {
|
|
20
|
+
path,
|
|
21
|
+
cleanup: () => {
|
|
22
|
+
rmSync(dir, { recursive: true, force: true });
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stage-labs/metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.102",
|
|
4
4
|
"description": "The metro command line. Sign in once per machine, then hand your MCP connector list to Claude Code without the credentials touching disk, argv or shell history.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.102",
|
|
4
4
|
"description": "Metro connectors for Claude Code. Runs beside the metro daemon on this machine: each connector the agent holds is one MCP server relayed through the daemon, the daemon keeps that list current on its own, and /reload-plugins picks up a new one without leaving your session. No vendor credential ever sits in a config file.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bonustrack",
|
package/runtime/runtime.json
CHANGED