@hediet/linkrpc-cli 0.0.3-next.20261101.1 → 0.0.3-next.20261102.1

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/README.md CHANGED
@@ -962,6 +962,9 @@ consent apply per tool; a forwarded server needs one capability for all its
962
962
  tools. Inaccessible directories and failed servers are reported on stderr;
963
963
  stdout contains only MCP protocol frames.
964
964
 
965
+ `--mcp-identity <serviceId>=<identity>` (repeatable) uses another account of a
966
+ published MCP server than its default and lists only that account's tools.
967
+
965
968
  `--scripts` additionally serves the LinkRPC script tools (`runLinkRpcScript`,
966
969
  `awaitLinkRpcTask`, `cancelLinkRpcTask`) of `@hediet/linkrpc-mcp` on the same
967
970
  connection, so one MCP entry gives both the hub's MCP tools and scripted access
@@ -977,8 +980,9 @@ This version aggregates tools, not resources, prompts, or sampling.
977
980
  ### Publishing MCP servers
978
981
 
979
982
  Producers stay separate. `mcp-publish` publishes one MCP server, given as a
980
- command after `--`, as a Streamable HTTP `--url` (with repeatable `--header`),
981
- or (forward only) as `--stdio`:
983
+ command after `--`, as a Streamable HTTP `--url` (with repeatable `--header`,
984
+ or `--header-env <header>=<ENV_VAR>` to read a secret from the environment),
985
+ as `--mcp-config <file>`, or (forward only) as `--stdio`:
982
986
 
983
987
  ```sh
984
988
  linkrpc hub mcp-publish --service --forward --serviceId <authorized-service-id> -- npx -y @modelcontextprotocol/server-everything
@@ -994,6 +998,24 @@ linkrpc hub mcp-publish --service --forward --serviceId <authorized-service-id>
994
998
  `--group admin=delete,merge`.
995
999
  - `--forward` relays MCP verbatim over `mcp.forward`. Each connection gets its
996
1000
  own MCP session: a fresh child process, or a new HTTP session.
1001
+ - `--mcp-config <file>` reads the server from JSON: `transport`, optional
1002
+ `identities` (accounts), `description`, `id`, and `expose` (flags override
1003
+ `expose`). Each identity adds env vars (stdio) or headers (HTTP); values can be
1004
+ `{ "fromEnv": "NAME" }`. Calls select an account with `mcpIdentity`:
1005
+
1006
+ ```json
1007
+ {
1008
+ "transport": { "kind": "streamable-http", "url": "https://api.githubcopilot.com/mcp/" },
1009
+ "identities": [
1010
+ { "id": "work", "headers": { "Authorization": { "fromEnv": "GITHUB_WORK_AUTHORIZATION" } } },
1011
+ { "id": "personal", "default": true, "headers": { "Authorization": { "fromEnv": "GITHUB_AUTHORIZATION" } } }
1012
+ ],
1013
+ "expose": { "service": {} }
1014
+ }
1015
+ ```
1016
+
1017
+ A capability pins an account with the parameter matcher
1018
+ `mcpIdentity: { "exact": "work" }`.
997
1019
  - `--stdio` forwards an MCP server that is already running and attached to this
998
1020
  process's stdin/stdout, one connection at a time. Later connections reach the
999
1021
  same server; the command exits when stdin ends.
@@ -1,5 +1,5 @@
1
- import { $ as requestTopologyAccess, B as proxyCommand, Ct as MethodRefWithOptHash, F as disconnectBroker, G as parseDuration, H as withStaticHubReflection, I as getBrokerStatus, L as readBrokerNotifications, M as readEndpointDiscovery, N as ContextStore, P as formatContextReference, Q as requestReflectionAccess, R as stopConnectionBroker, St as parseParamOverride, U as parseConnectionLimit, V as tunnelCommand, W as parseConnectionLimitMilliseconds, _t as describeSchema, a as resolveInvocationEndpoint, c as resolveLocalEndpoint, ct as readCliIdentity, dt as connect, et as setupSigning, ft as connectViaRootOverlay, gt as describeObjectParams, ht as resolvedEndpointToConfig, i as resolveInvocationContext, it as walkHub, lt as formatPrincipalSource, m as managedEndpointsInterface, mt as resolveTargetEndpoint, n as loadStaticHubSchema, nt as fetchSchema$1, o as resolveSigning, ot as cliIdentityTarget, pt as connectViaTransport, q as resolveCliInvocation, r as resolveStaticHubSchemaSource, rt as findMethodInSchema, s as validationDefault, st as deleteCliIdentity, t as completeForLine, tt as fetchDefaults, ut as parsePrincipalSpec, vt as explainValidation, xt as mergeParams, y as HubHome, yt as validateValueAgainstSchema, z as ConnectionBroker } from "./runComplete-haCYSPzH.js";
2
- import { HubMcpAggregator, McpToolHost, hostMcpServer, mcpServerConfigSchema, serveMcpForwardInstance, streamInstanceTransport } from "@hediet/linkrpc-mcp/hub";
1
+ import { $ as requestTopologyAccess, B as proxyCommand, Ct as MethodRefWithOptHash, F as disconnectBroker, G as parseDuration, H as withStaticHubReflection, I as getBrokerStatus, L as readBrokerNotifications, M as readEndpointDiscovery, N as ContextStore, P as formatContextReference, Q as requestReflectionAccess, R as stopConnectionBroker, St as parseParamOverride, U as parseConnectionLimit, V as tunnelCommand, W as parseConnectionLimitMilliseconds, _t as describeSchema, a as resolveInvocationEndpoint, c as resolveLocalEndpoint, ct as readCliIdentity, dt as connect, et as setupSigning, ft as connectViaRootOverlay, gt as describeObjectParams, ht as resolvedEndpointToConfig, i as resolveInvocationContext, it as walkHub, lt as formatPrincipalSource, m as managedEndpointsInterface, mt as resolveTargetEndpoint, n as loadStaticHubSchema, nt as fetchSchema$1, o as resolveSigning, ot as cliIdentityTarget, pt as connectViaTransport, q as resolveCliInvocation, r as resolveStaticHubSchemaSource, rt as findMethodInSchema, s as validationDefault, st as deleteCliIdentity, t as completeForLine, tt as fetchDefaults, ut as parsePrincipalSpec, vt as explainValidation, xt as mergeParams, y as HubHome, yt as validateValueAgainstSchema, z as ConnectionBroker } from "./runComplete-7So63j8K.js";
2
+ import { HubMcpAggregator, McpToolHost, hostMcpServer, mcpExposeConfigSchema, mcpServerConfigSchema, serveMcpForwardInstance, streamInstanceTransport } from "@hediet/linkrpc-mcp/hub";
3
3
  import { ErrorCode, INTERFACE_TEMPLATES_EXTENSION, LinkRpcConnection, RpcError, computeInterfaceHash, connectTransports, createSchemaToZod, directoryInterface, exportStaticHubSchema, generateTsContract, generateTsInterface, interfaceTemplateArgumentsEquivalent, interfaceTemplateMemberName, interfaceTemplatesEqual, isAssignable, jcsCanonicalize, matchParams, schemaToZod, validateInterfaceTemplates } from "@hediet/linkrpc";
4
4
  import { WebSocketTransport, connectNdjson, connectToHub, formatEndpointUri, isHubEndpoint, openWebSocket, parseEndpointUri, runInitializeHandshake, traceMessageTransport as traceMessageTransport$1 } from "@hediet/linkrpc/node";
5
5
  import { SocketServer } from "@hediet/linkrpc-hub/hub/server/node";
@@ -412,7 +412,7 @@ function contextNamespace(reference) {
412
412
  async function useLocalManagement(start, action) {
413
413
  const home = HubHome.resolve();
414
414
  if (start) {
415
- const { startDaemon, nodeDaemonLaunch } = await import("./src-DSdS3hm7.js");
415
+ const { startDaemon, nodeDaemonLaunch } = await import("./src-JoLhzxlD.js");
416
416
  if (await startDaemon({
417
417
  home,
418
418
  launch: nodeDaemonLaunch(home)
@@ -432,7 +432,7 @@ async function useLocalManagement(start, action) {
432
432
  }
433
433
  }
434
434
  async function restartLocalDaemon() {
435
- const { startDaemon, stopDaemon, nodeDaemonLaunch } = await import("./src-DSdS3hm7.js");
435
+ const { startDaemon, stopDaemon, nodeDaemonLaunch } = await import("./src-JoLhzxlD.js");
436
436
  const home = HubHome.resolve();
437
437
  process.stderr.write("Restarting the local Hub daemon: clients will disconnect and managed workloads will stop. OS autostart settings are unchanged.\n");
438
438
  await stopDaemon(home);
@@ -3422,7 +3422,9 @@ async function mcpPublishCommand(opts) {
3422
3422
  serviceId,
3423
3423
  server: mcpServerConfigSchema.parse({
3424
3424
  id: opts.name ?? interfaceNameFor(serviceId),
3425
+ ...opts.description !== void 0 ? { description: opts.description } : {},
3425
3426
  transport,
3427
+ ...opts.identities !== void 0 ? { identities: opts.identities } : {},
3426
3428
  expose: opts.expose
3427
3429
  }),
3428
3430
  log,
@@ -3438,6 +3440,22 @@ async function mcpPublishCommand(opts) {
3438
3440
  await hosted.dispose();
3439
3441
  }
3440
3442
  }
3443
+ /** `mcp-publish --mcp-config` file: a server config whose `id` and `expose` may come from flags. */
3444
+ const mcpPublishConfigSchema = mcpServerConfigSchema.extend({
3445
+ id: mcpServerConfigSchema.shape.id.optional(),
3446
+ expose: mcpExposeConfigSchema.optional()
3447
+ });
3448
+ async function readMcpPublishConfig(path) {
3449
+ let json;
3450
+ try {
3451
+ json = JSON.parse(await readFile(path, "utf8"));
3452
+ } catch (error) {
3453
+ throw new Error(`mcp-publish: cannot read ${path}: ${error instanceof Error ? error.message : String(error)}`);
3454
+ }
3455
+ const parsed = mcpPublishConfigSchema.safeParse(json);
3456
+ if (!parsed.success) throw new Error(`mcp-publish: invalid ${path}: ${parsed.error.message}`);
3457
+ return parsed.data;
3458
+ }
3441
3459
  /** A valid `mcp.tools.<name>` suffix for `serviceId`, e.g. `my/MCP_server` → `my.mcp-server`. */
3442
3460
  function interfaceNameFor(serviceId) {
3443
3461
  const name = serviceId.toLowerCase().replace(/[^a-z0-9.-]+/g, ".").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g, "");
@@ -3479,7 +3497,8 @@ async function mcpCommand(channel, options = {}) {
3479
3497
  const aggregatorOptions = {
3480
3498
  requestDirectoryAccess: options.requestDirectoryAccess,
3481
3499
  log,
3482
- clientInfo
3500
+ clientInfo,
3501
+ ...options.mcpIdentities !== void 0 ? { mcpIdentityFor: (serviceId) => options.mcpIdentities?.[serviceId] } : {}
3483
3502
  };
3484
3503
  const transport = new StdioServerTransport(options.input ?? process.stdin, options.output ?? process.stdout);
3485
3504
  const input = options.input ?? process.stdin;
@@ -9229,9 +9248,10 @@ Batch options:
9229
9248
  local.close();
9230
9249
  }
9231
9250
  });
9232
- program.command("mcp").description("Expose the tools of all MCP servers published on the Hub (MCP services and forwarded servers) as one stdio MCP server.").option("--scripts", "also serve the LinkRPC script tools (runLinkRpcScript, awaitLinkRpcTask, cancelLinkRpcTask)").action(async (cmdOpts) => {
9251
+ program.command("mcp").description("Expose the tools of all MCP servers published on the Hub (MCP services and forwarded servers) as one stdio MCP server.").option("--scripts", "also serve the LinkRPC script tools (runLinkRpcScript, awaitLinkRpcTask, cancelLinkRpcTask)").option("--mcp-identity <serviceId=identity>", "use this MCP identity (account) of a published MCP server instead of its default (repeatable)", collectKeyValue).action(async (cmdOpts) => {
9233
9252
  await withChannel(endpoint, getPrincipalSpec(), async (channel, session) => {
9234
9253
  await mcpCommand(channel, {
9254
+ ...cmdOpts.mcpIdentity !== void 0 ? { mcpIdentities: cmdOpts.mcpIdentity } : {},
9235
9255
  requestDirectoryAccess: session === void 0 ? void 0 : (serviceId) => requestDirectoryAccess(session, serviceId, { watch: true }),
9236
9256
  ...cmdOpts.scripts ? {
9237
9257
  scripts: true,
@@ -9423,25 +9443,40 @@ Batch options:
9423
9443
  broker.close();
9424
9444
  }
9425
9445
  });
9426
- const mcpUpstreamOptions = (command) => command.option("--serviceId <serviceId>", "serviceId prefix to claim (default: the connection's granted serviceId namespace)").option("--url <url>", "publish a Streamable HTTP MCP server instead of a command after `--`").option("--header <key=value>", "HTTP header sent to the --url server (repeatable)", collectKeyValue).option("--env <key=value>", "env var for the spawned MCP server child (repeatable)", collectKeyValue).option("--stdio", "forward the running MCP server attached to this process's stdin/stdout, one connection at a time");
9446
+ const mcpUpstreamOptions = (command) => command.option("--serviceId <serviceId>", "serviceId prefix to claim (default: the connection's granted serviceId namespace)").option("--url <url>", "publish a Streamable HTTP MCP server instead of a command after `--`").option("--header <key=value>", "HTTP header sent to the --url server (repeatable)", collectKeyValue).option("--header-env <key=ENV_VAR>", "HTTP header read from an environment variable when a session opens, e.g. `Authorization=SLACK_AUTHORIZATION` (repeatable)", collectKeyValue).option("--mcp-config <file>", "JSON file with the MCP server: `transport`, optional `identities` (accounts), `description`, and `expose`").option("--env <key=value>", "env var for the spawned MCP server child (repeatable)", collectKeyValue).option("--stdio", "forward the running MCP server attached to this process's stdin/stdout, one connection at a time");
9427
9447
  const runMcpPublish = async (commandName, mcpCommand, cmdOpts, expose, name) => {
9428
9448
  const localEp = needEndpoint(endpoint);
9429
9449
  if ([
9430
9450
  mcpCommand !== void 0 && mcpCommand.length > 0,
9431
9451
  cmdOpts.url !== void 0,
9432
- cmdOpts.stdio === true
9452
+ cmdOpts.stdio === true,
9453
+ cmdOpts.mcpConfig !== void 0
9433
9454
  ].filter(Boolean).length !== 1) {
9434
- process.stderr.write(`linkrpc: ${commandName} requires exactly one of an MCP server command after \`--\`, --url, or --stdio, e.g. \`${commandName} -- npx -y @modelcontextprotocol/server-everything\`.\n`);
9455
+ process.stderr.write(`linkrpc: ${commandName} requires exactly one of an MCP server command after \`--\`, --url, --stdio, or --mcp-config, e.g. \`${commandName} -- npx -y @modelcontextprotocol/server-everything\`.\n`);
9435
9456
  process.exit(2);
9436
9457
  }
9437
- if (cmdOpts.stdio && expose.service !== void 0) {
9458
+ if (cmdOpts.stdio && expose?.service !== void 0) {
9438
9459
  process.stderr.write(`linkrpc: ${commandName} --stdio supports only --forward.\n`);
9439
9460
  process.exit(2);
9440
9461
  }
9441
- const transport = cmdOpts.stdio ? { kind: "own-stdio" } : cmdOpts.url !== void 0 ? {
9462
+ if (cmdOpts.headerEnv !== void 0 && cmdOpts.url === void 0) {
9463
+ process.stderr.write(`linkrpc: ${commandName} --header-env requires --url.\n`);
9464
+ process.exit(2);
9465
+ }
9466
+ const file = cmdOpts.mcpConfig === void 0 ? void 0 : await readMcpPublishConfig(cmdOpts.mcpConfig);
9467
+ const resolvedExpose = expose ?? file?.expose;
9468
+ if (resolvedExpose === void 0) {
9469
+ process.stderr.write(`linkrpc: ${commandName} requires --service, --forward, or \`expose\` in --mcp-config.\n`);
9470
+ process.exit(2);
9471
+ }
9472
+ const headers = {
9473
+ ...cmdOpts.header,
9474
+ ...Object.fromEntries(Object.entries(cmdOpts.headerEnv ?? {}).map(([key, variable]) => [key, { fromEnv: variable }]))
9475
+ };
9476
+ const transport = file !== void 0 ? file.transport : cmdOpts.stdio ? { kind: "own-stdio" } : cmdOpts.url !== void 0 ? {
9442
9477
  kind: "streamable-http",
9443
9478
  url: cmdOpts.url,
9444
- ...cmdOpts.header ? { headers: cmdOpts.header } : {}
9479
+ ...Object.keys(headers).length > 0 ? { headers } : {}
9445
9480
  } : {
9446
9481
  kind: "stdio",
9447
9482
  command: mcpCommand[0],
@@ -9454,12 +9489,15 @@ Batch options:
9454
9489
  const local = await connect(localEp, wireLog("hub"));
9455
9490
  try {
9456
9491
  reportIdentity(await setupSigning(local.channel, local.signing, getPrincipalSpec(), { negotiateHubCaps: isHubEndpoint(localEp) }));
9492
+ const id = name ?? file?.id;
9457
9493
  await mcpPublishCommand({
9458
9494
  ...cmdOpts.serviceId !== void 0 ? { serviceId: cmdOpts.serviceId } : {},
9459
- ...name !== void 0 ? { name } : {},
9495
+ ...id !== void 0 ? { name: id } : {},
9496
+ ...file?.identities !== void 0 ? { identities: file.identities } : {},
9497
+ ...file?.description !== void 0 ? { description: file.description } : {},
9460
9498
  local,
9461
9499
  transport,
9462
- expose
9500
+ expose: resolvedExpose
9463
9501
  });
9464
9502
  } finally {
9465
9503
  local.close();
@@ -9469,7 +9507,7 @@ Batch options:
9469
9507
  await runMcpPublish("mcp-forward", mcpCommand, cmdOpts, { forward: { sharing: "exclusive" } }, void 0);
9470
9508
  });
9471
9509
  mcpUpstreamOptions(program.command("mcp-publish [mcpCommand...]").description("Publish an MCP server through the hub (--endpoint*). --service publishes it as a LinkRPC service: one method per tool on generated `mcp.tools.<name>` interfaces (split with --group), generic `mcp.tools::listTools`/`callTool`, and `mcp.server`; callers share one MCP session. --forward relays verbatim MCP over `mcp.forward`. Pass one or both. The MCP server is a command after `--`, --url, or (forward only) --stdio. Runs until Ctrl-C.")).option("--service", "publish the MCP server as a LinkRPC service").option("--forward", "relay MCP verbatim over mcp.forward").option("--name <name>", "generated interface name, `mcp.tools.<name>` (default: derived from the serviceId)").option("--group <name=keywords>", "move tools whose name contains one of the comma-separated keywords into `mcp.tools.<name>.<group>` (repeatable; first match wins)", collectKeyValue).action(async (mcpCommand, cmdOpts) => {
9472
- if (!cmdOpts.service && !cmdOpts.forward) {
9510
+ if (!cmdOpts.service && !cmdOpts.forward && cmdOpts.mcpConfig === void 0) {
9473
9511
  process.stderr.write("linkrpc: mcp-publish requires --service, --forward, or both.\n");
9474
9512
  process.exit(2);
9475
9513
  }
@@ -9481,10 +9519,10 @@ Batch options:
9481
9519
  name: groupName,
9482
9520
  keywords: keywords.split(",").filter(Boolean)
9483
9521
  }));
9484
- await runMcpPublish("mcp-publish", mcpCommand, cmdOpts, {
9522
+ await runMcpPublish("mcp-publish", mcpCommand, cmdOpts, cmdOpts.service || cmdOpts.forward ? {
9485
9523
  ...cmdOpts.service ? { service: groups.length > 0 ? { groups } : {} } : {},
9486
9524
  ...cmdOpts.forward ? { forward: { sharing: "exclusive" } } : {}
9487
- }, cmdOpts.name);
9525
+ } : void 0, cmdOpts.name);
9488
9526
  });
9489
9527
  program.command("identity").description("Inspect the persistent principal used by connected CLI commands.").command("show").description("Print the resolved persistent CLI identity.").option("--json", "stable machine-readable JSON output").action(async (opts) => {
9490
9528
  await withResolvedSigning(endpoint, getPrincipalSpec(), async (_conn, session) => {
@@ -9519,7 +9557,7 @@ Batch options:
9519
9557
  process.once("SIGINT", onSignal);
9520
9558
  process.once("SIGTERM", onSignal);
9521
9559
  try {
9522
- const { runApprovalUi } = await import("./runApprovalUi-BHomYhFQ.js");
9560
+ const { runApprovalUi } = await import("./runApprovalUi-GJf_57fQ.js");
9523
9561
  await runApprovalUi({
9524
9562
  client,
9525
9563
  signal: stop.signal
@@ -9534,7 +9572,7 @@ Batch options:
9534
9572
  registerViewCommands(program, (action) => withChannel(endpoint, getPrincipalSpec(), action));
9535
9573
  program.command("ui").description("Launch the terminal UI (form-based browser of services + methods).").action(async () => {
9536
9574
  const acquired = await acquireConnection(endpoint);
9537
- const { runUi } = await import("./runUi-cl0J7cZB.js");
9575
+ const { runUi } = await import("./runUi-Di-OpGlw.js");
9538
9576
  try {
9539
9577
  await runUi({
9540
9578
  endpoint: acquired.ep,
@@ -10114,4 +10152,4 @@ function definedEnv(env) {
10114
10152
  //#endregion
10115
10153
  export { formatCondition as _, formatCommandLegend as a, targetId as b, safeTerminalText as c, ObservablePromise as d, observableValue as f, resolveViewTarget as g, Disposable as h, dispatchHostKey as i, approvalDetailLines as l, derived as m, views as n, hostCommands as o, autorun as p, ViewFrame as r, matchesKey as s, runCli as t, ObservableLazyPromise as u, interfaceTarget as v, matchesTarget as y };
10116
10154
 
10117
- //# sourceMappingURL=cli-CUctSk0X.js.map
10155
+ //# sourceMappingURL=cli-CvHY2xLj.js.map