@hediet/linkrpc-cli 0.0.3-next.20261031.1 → 0.0.3-next.20261102.2
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 +71 -14
- package/dist/chunks/{cli-DQr3bq_u.js → cli-BY9fXhpJ.js} +149 -67
- package/dist/chunks/cli-BY9fXhpJ.js.map +1 -0
- package/dist/chunks/{runApprovalUi-CHLl-QDw.js → runApprovalUi-5soIqxOS.js} +3 -3
- package/dist/chunks/{runApprovalUi-CHLl-QDw.js.map → runApprovalUi-5soIqxOS.js.map} +1 -1
- package/dist/chunks/{runComplete-C__MHMiO.js → runComplete-BWhPmSgi.js} +228 -36
- package/dist/chunks/runComplete-BWhPmSgi.js.map +1 -0
- package/dist/chunks/{runUi-CtNlZncr.js → runUi-Dkm-6D6s.js} +5 -5
- package/dist/chunks/{runUi-CtNlZncr.js.map → runUi-Dkm-6D6s.js.map} +1 -1
- package/dist/chunks/{scroll-B_5Pakou.js → scroll-rkdCKbaP.js} +2 -2
- package/dist/chunks/{scroll-B_5Pakou.js.map → scroll-rkdCKbaP.js.map} +1 -1
- package/dist/chunks/{src-CAZT8apO.js → src-DIsGc3Ft.js} +2 -2
- package/dist/chunks/{src-CAZT8apO.js.map → src-DIsGc3Ft.js.map} +1 -1
- package/dist/hub.js +1 -1
- package/dist/index.js +1 -1
- package/dist/linkrpc.js +1 -1
- package/dist/rpc.js +1 -1
- package/package.json +6 -6
- package/dist/chunks/cli-DQr3bq_u.js.map +0 -1
- package/dist/chunks/runComplete-C__MHMiO.js.map +0 -1
package/README.md
CHANGED
|
@@ -579,7 +579,7 @@ it**. Pick one of:
|
|
|
579
579
|
| Flag / env | Meaning |
|
|
580
580
|
| -------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
581
581
|
| `--endpoint <uri>` | A strict endpoint URI (see below). |
|
|
582
|
-
| `--endpoint-cmd <command>` | Spawn a _server_, hand it a fresh socket + token via `LINKRPC_ENDPOINT`/`LINKRPC_TOKEN`, then connect to it. |
|
|
582
|
+
| `--endpoint-cmd <command>` | Spawn a _server_, hand it a fresh socket + token via `LINKRPC_ENDPOINT`/`LINKRPC_TOKEN`, then connect to it. With the hub profile, the server is a participant of an in-process hub and must claim its granted namespace (`local`) within 30 seconds. |
|
|
583
583
|
| `--endpoint-cmd-stdio <command>` | Spawn a child and talk linkrpc over its stdio. |
|
|
584
584
|
| `LINKRPC_ENDPOINT` (env) | A URI, or a legacy bare socket path / `ws://` URL. Token from `LINKRPC_TOKEN`; enabled by default in the Hub profile and with `--use-env` in the RPC profile. |
|
|
585
585
|
|
|
@@ -936,7 +936,7 @@ idle minutes.
|
|
|
936
936
|
### Hub MCP aggregation
|
|
937
937
|
|
|
938
938
|
`linkrpc hub mcp` is a lightweight stdio MCP server that discovers every MCP
|
|
939
|
-
server published in the selected Hub and aggregates their tools:
|
|
939
|
+
server published in the selected Hub and aggregates their tools: MCP services
|
|
940
940
|
(`mcp.tools`) and forwarded servers (`mcp.forward`, or the legacy
|
|
941
941
|
`vscode.mcp-forward`). No service IDs, filters, or principal overrides are
|
|
942
942
|
required:
|
|
@@ -957,15 +957,19 @@ Endpoint/context/environment and identity selection follow the normal Hub CLI
|
|
|
957
957
|
rules. An explicit endpoint can be supplied before `mcp`, for example
|
|
958
958
|
`linkrpc hub --endpoint npipe://./pipe/my-hub mcp`. Signing and capability
|
|
959
959
|
negotiation remain enabled by default; discovery does not bypass authorization.
|
|
960
|
-
|
|
960
|
+
Service tools are called through their generated methods, so capabilities and
|
|
961
961
|
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
|
-
`--
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
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
|
+
|
|
968
|
+
The same MCP server also serves the LinkRPC script tools (`runLinkRpcScript`,
|
|
969
|
+
`awaitLinkRpcTask`, `cancelLinkRpcTask`) of `@hediet/linkrpc-mcp`, so one MCP
|
|
970
|
+
entry gives both the hub's MCP tools and scripted access to every hub service.
|
|
971
|
+
`--no-scripts` serves only the aggregated MCP tools and does not load the script
|
|
972
|
+
sandbox.
|
|
969
973
|
|
|
970
974
|
The command watches directory changes, refreshes changed tool lists (including
|
|
971
975
|
paginated lists), and retries failed connections while they remain advertised.
|
|
@@ -977,25 +981,63 @@ This version aggregates tools, not resources, prompts, or sampling.
|
|
|
977
981
|
### Publishing MCP servers
|
|
978
982
|
|
|
979
983
|
Producers stay separate. `mcp-publish` publishes one MCP server, given as a
|
|
980
|
-
command after
|
|
984
|
+
command after `--`, as a Streamable HTTP `--url` (with repeatable `--header`,
|
|
985
|
+
or `--header-env <header>=<ENV_VAR>` to read a secret from the environment),
|
|
986
|
+
as `--mcp-config <file>`, or (forward only) as `--stdio`:
|
|
981
987
|
|
|
982
988
|
```sh
|
|
983
|
-
linkrpc hub mcp-publish --
|
|
989
|
+
linkrpc hub mcp-publish --service --forward --serviceId ./everything -- npx -y @modelcontextprotocol/server-everything
|
|
984
990
|
```
|
|
985
991
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
992
|
+
`--serviceId ./<name>` is relative: it claims `<granted namespace>/<name>` for
|
|
993
|
+
free when the connection has a granted serviceId namespace, and otherwise
|
|
994
|
+
requests `<user>@<host>/<name>` from the hub (an approval prompt). The command
|
|
995
|
+
logs the resolved service id. Without `--serviceId`, the granted namespace
|
|
996
|
+
itself is claimed; `tunnel` accepts relative service ids too. The command stops,
|
|
997
|
+
with a non-zero exit code, when its hub connection closes.
|
|
998
|
+
|
|
999
|
+
- `--service` publishes the MCP server as a LinkRPC service: every MCP tool is
|
|
1000
|
+
a method of a generated `mcp.tools.<name>` interface (`--name`, derived from
|
|
1001
|
+
the service ID by default), and `mcp.tools::listTools`/`callTool` list and
|
|
1002
|
+
call tools by name. All callers share one MCP session; a caller can open an
|
|
1003
|
+
exclusive one with `mcp.server::openSession`. Repeatable
|
|
1004
|
+
`--group <group>=<keyword,...>` moves tools whose name contains a keyword into
|
|
1005
|
+
`mcp.tools.<name>.<group>`, so capabilities can cover a whole group, e.g.
|
|
1006
|
+
`--group admin=delete,merge`.
|
|
990
1007
|
- `--forward` relays MCP verbatim over `mcp.forward`. Each connection gets its
|
|
991
1008
|
own MCP session: a fresh child process, or a new HTTP session.
|
|
1009
|
+
- `--mcp-config <file>` reads the server from JSON: `transport`, optional
|
|
1010
|
+
`identities` (accounts), `description`, `id`, and `expose` (flags override
|
|
1011
|
+
`expose`). Each identity adds env vars (stdio) or headers (HTTP); values can be
|
|
1012
|
+
`{ "fromEnv": "NAME" }`. Calls select an account with `mcpIdentity`:
|
|
1013
|
+
|
|
1014
|
+
```json
|
|
1015
|
+
{
|
|
1016
|
+
"transport": { "kind": "streamable-http", "url": "https://api.githubcopilot.com/mcp/" },
|
|
1017
|
+
"identities": [
|
|
1018
|
+
{ "id": "work", "headers": { "Authorization": { "fromEnv": "GITHUB_WORK_AUTHORIZATION" } } },
|
|
1019
|
+
{ "id": "personal", "default": true, "headers": { "Authorization": { "fromEnv": "GITHUB_AUTHORIZATION" } } }
|
|
1020
|
+
],
|
|
1021
|
+
"expose": { "service": {} }
|
|
1022
|
+
}
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
A capability pins an account with the parameter matcher
|
|
1026
|
+
`mcpIdentity: { "exact": "work" }`.
|
|
1027
|
+
- `--stdio` forwards an MCP server that is already running and attached to this
|
|
1028
|
+
process's stdin/stdout, one connection at a time. Later connections reach the
|
|
1029
|
+
same server; the command exits when stdin ends.
|
|
992
1030
|
|
|
993
1031
|
`mcp-forward` is shorthand for `mcp-publish --forward`:
|
|
994
1032
|
|
|
995
1033
|
```sh
|
|
996
|
-
linkrpc hub mcp-forward --serviceId
|
|
1034
|
+
linkrpc hub mcp-forward --serviceId ./component-explorer -- component-explorer mcp -p <config> --use-daemon --no-daemon-autostart
|
|
997
1035
|
```
|
|
998
1036
|
|
|
1037
|
+
To forward a server that must not be restarted per connection, start it
|
|
1038
|
+
yourself and connect its stdio, e.g. with a named pipe pair or a supervisor:
|
|
1039
|
+
`linkrpc hub mcp-forward --stdio --serviceId <id>`.
|
|
1040
|
+
|
|
999
1041
|
Manage that producer and `component-explorer serve -p <same-config>` with your
|
|
1000
1042
|
workspace daemon. The aggregator opens lightweight MCP connections; it does not
|
|
1001
1043
|
start workspace builds or explorer daemons. Each forwarded connection spawns
|
|
@@ -1003,6 +1045,21 @@ the configured MCP child, so producers must use attach-only commands when
|
|
|
1003
1045
|
heavyweight services are managed separately. Children inherit the producer's
|
|
1004
1046
|
environment plus `--env` values.
|
|
1005
1047
|
|
|
1048
|
+
### MCP servers without a running hub
|
|
1049
|
+
|
|
1050
|
+
With the hub profile, `--endpoint-cmd` runs the command as a participant of an
|
|
1051
|
+
in-process hub, so a publisher needs no hub daemon. Every hub client works
|
|
1052
|
+
against it, including the terminal UI:
|
|
1053
|
+
|
|
1054
|
+
```sh
|
|
1055
|
+
linkrpc hub ui --endpoint-cmd "linkrpc hub mcp-publish --service -- npx -y @modelcontextprotocol/server-everything"
|
|
1056
|
+
linkrpc hub call local::mcp.tools.demo::echo --p:message=hi --endpoint-cmd "linkrpc hub mcp-publish --service --name demo -- node server.mjs"
|
|
1057
|
+
```
|
|
1058
|
+
|
|
1059
|
+
The publisher claims the in-process hub's namespace `local`; its tools appear
|
|
1060
|
+
as methods of `local::mcp.tools.<name>`, with forms built from their input
|
|
1061
|
+
schemas. `mcp-publish` stops when its hub connection closes.
|
|
1062
|
+
|
|
1006
1063
|
### Participant proxy
|
|
1007
1064
|
|
|
1008
1065
|
`proxy` stands in for a participant on the hub: the participant is either this
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HubMcpAggregator, McpToolHost, hostMcpServer, mcpServerConfigSchema } from "@hediet/linkrpc-mcp/hub";
|
|
1
|
+
import { B as proxyCommand, Ct as mergeParams, F as disconnectBroker, G as parseConnectionLimit, H as claimServiceId, I as getBrokerStatus, K as parseConnectionLimitMilliseconds, L as readBrokerNotifications, M as readEndpointDiscovery, N as ContextStore, P as formatContextReference, R as stopConnectionBroker, Tt as MethodRefWithOptHash, U as resolveServiceIdToClaim, V as tunnelCommand, W as withStaticHubReflection, Y as resolveCliInvocation, _t as resolvedEndpointToConfig, a as resolveInvocationEndpoint, at as findMethodInSchema, bt as explainValidation, c as resolveLocalEndpoint, ct as cliIdentityTarget, dt as formatPrincipalSource, et as requestReflectionAccess, ft as parsePrincipalSpec, gt as resolveTargetEndpoint, ht as connectViaTransport, i as resolveInvocationContext, it as fetchSchema$1, lt as deleteCliIdentity, m as managedEndpointsInterface, mt as connectViaRootOverlay, n as loadStaticHubSchema, nt as setupSigning, o as resolveSigning, ot as walkHub, pt as connect, q as parseDuration, r as resolveStaticHubSchemaSource, rt as fetchDefaults, s as validationDefault, t as completeForLine, tt as requestTopologyAccess, ut as readCliIdentity, vt as describeObjectParams, wt as parseParamOverride, xt as validateValueAgainstSchema, y as HubHome, yt as describeSchema, z as ConnectionBroker } from "./runComplete-BWhPmSgi.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-
|
|
415
|
+
const { startDaemon, nodeDaemonLaunch } = await import("./src-DIsGc3Ft.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-
|
|
435
|
+
const { startDaemon, stopDaemon, nodeDaemonLaunch } = await import("./src-DIsGc3Ft.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);
|
|
@@ -3382,53 +3382,82 @@ function _unlink(socketPath) {
|
|
|
3382
3382
|
//#endregion
|
|
3383
3383
|
//#region src/commands/mcpPublish.ts
|
|
3384
3384
|
/**
|
|
3385
|
-
*
|
|
3386
|
-
*
|
|
3387
|
-
* `
|
|
3388
|
-
*/
|
|
3389
|
-
const CLAIM_METHOD = `${hubGrantedServiceIdInterface.info.id}::register`;
|
|
3390
|
-
/** Read-only connection facts — `hubGrantedServiceId::get`. */
|
|
3391
|
-
const INFO_METHOD = `${hubGrantedServiceIdInterface.info.id}::get`;
|
|
3392
|
-
/**
|
|
3393
|
-
* Publish one MCP server on the hub until stopped: typed (one LinkRPC method
|
|
3394
|
-
* per tool, one shared MCP session), forwarded (verbatim MCP over
|
|
3395
|
-
* `mcp.forward`, one upstream session per connection), or both.
|
|
3385
|
+
* Publish one MCP server on the hub until stopped: as a service (one LinkRPC
|
|
3386
|
+
* method per tool plus generic `mcp.tools`, one shared MCP session), forwarded
|
|
3387
|
+
* (verbatim MCP over `mcp.forward`), or both.
|
|
3396
3388
|
*/
|
|
3397
3389
|
async function mcpPublishCommand(opts) {
|
|
3398
3390
|
const log = opts.log ?? ((line) => process.stderr.write(line + "\n"));
|
|
3399
|
-
const
|
|
3391
|
+
const stop = Promise.race([opts.stop ?? _untilSignalled$1(), opts.local.closed.then(() => {
|
|
3392
|
+
log("mcp-publish: the hub connection closed");
|
|
3393
|
+
process.exitCode = 1;
|
|
3394
|
+
})]);
|
|
3395
|
+
const resolved = await resolveServiceIdToClaim(opts.local, opts.serviceId);
|
|
3396
|
+
const serviceId = resolved.serviceId;
|
|
3400
3397
|
const connection = new LinkRpcConnection(opts.local.rpcChannel);
|
|
3398
|
+
if (opts.transport.kind === "own-stdio") {
|
|
3399
|
+
if (opts.expose.service !== void 0 || opts.expose.forward === void 0) throw new Error("mcp-publish: an MCP server on this process's stdio can only be forwarded.");
|
|
3400
|
+
const instance = serveMcpForwardInstance({
|
|
3401
|
+
connection,
|
|
3402
|
+
serviceId,
|
|
3403
|
+
transport: streamInstanceTransport(process.stdin, process.stdout),
|
|
3404
|
+
log
|
|
3405
|
+
});
|
|
3406
|
+
try {
|
|
3407
|
+
await claimServiceId(opts.local, serviceId);
|
|
3408
|
+
log(`mcp-publish: claimed '${serviceId}' — forwarding the MCP server on stdio to one connection at a time`);
|
|
3409
|
+
await Promise.race([instance.closed, stop]);
|
|
3410
|
+
log("mcp-publish: stopping");
|
|
3411
|
+
} finally {
|
|
3412
|
+
instance.dispose();
|
|
3413
|
+
}
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3416
|
+
const transport = opts.transport;
|
|
3401
3417
|
const hosted = await hostMcpServer({
|
|
3402
3418
|
connection,
|
|
3403
3419
|
serviceId,
|
|
3404
3420
|
server: mcpServerConfigSchema.parse({
|
|
3405
|
-
id: opts.name ?? interfaceNameFor(serviceId),
|
|
3406
|
-
|
|
3421
|
+
id: opts.name ?? interfaceNameFor(resolved.relative ?? serviceId),
|
|
3422
|
+
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
3423
|
+
transport,
|
|
3424
|
+
...opts.identities !== void 0 ? { identities: opts.identities } : {},
|
|
3407
3425
|
expose: opts.expose
|
|
3408
3426
|
}),
|
|
3409
3427
|
log,
|
|
3410
3428
|
onRefreshError: (error) => log(`mcp-publish: tool refresh failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
3411
3429
|
});
|
|
3412
3430
|
try {
|
|
3413
|
-
await opts.local
|
|
3414
|
-
const modes = [opts.expose.
|
|
3415
|
-
log(`mcp-publish: claimed '${serviceId}' — publishing ${_describe(
|
|
3416
|
-
await
|
|
3431
|
+
await claimServiceId(opts.local, serviceId);
|
|
3432
|
+
const modes = [opts.expose.service && "as a service", opts.expose.forward && "forwarded"].filter(Boolean).join(" and ");
|
|
3433
|
+
log(`mcp-publish: claimed '${serviceId}' — publishing ${_describe(transport)} ${modes}`);
|
|
3434
|
+
await stop;
|
|
3417
3435
|
log("mcp-publish: stopping");
|
|
3418
3436
|
} finally {
|
|
3419
3437
|
await hosted.dispose();
|
|
3420
3438
|
}
|
|
3421
3439
|
}
|
|
3440
|
+
/** `mcp-publish --mcp-config` file: a server config whose `id` and `expose` may come from flags. */
|
|
3441
|
+
const mcpPublishConfigSchema = mcpServerConfigSchema.extend({
|
|
3442
|
+
id: mcpServerConfigSchema.shape.id.optional(),
|
|
3443
|
+
expose: mcpExposeConfigSchema.optional()
|
|
3444
|
+
});
|
|
3445
|
+
async function readMcpPublishConfig(path) {
|
|
3446
|
+
let json;
|
|
3447
|
+
try {
|
|
3448
|
+
json = JSON.parse(await readFile(path, "utf8"));
|
|
3449
|
+
} catch (error) {
|
|
3450
|
+
throw new Error(`mcp-publish: cannot read ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
3451
|
+
}
|
|
3452
|
+
const parsed = mcpPublishConfigSchema.safeParse(json);
|
|
3453
|
+
if (!parsed.success) throw new Error(`mcp-publish: invalid ${path}: ${parsed.error.message}`);
|
|
3454
|
+
return parsed.data;
|
|
3455
|
+
}
|
|
3422
3456
|
/** A valid `mcp.tools.<name>` suffix for `serviceId`, e.g. `my/MCP_server` → `my.mcp-server`. */
|
|
3423
3457
|
function interfaceNameFor(serviceId) {
|
|
3424
3458
|
const name = serviceId.toLowerCase().replace(/[^a-z0-9.-]+/g, ".").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g, "");
|
|
3425
3459
|
return name.length > 0 ? name : "server";
|
|
3426
3460
|
}
|
|
3427
|
-
async function _resolveGrantedServiceId(local) {
|
|
3428
|
-
const granted = (await local.channel.sendRequest(INFO_METHOD, {}))?.grantedServiceIdNamespace ?? "";
|
|
3429
|
-
if (granted.length === 0) throw new Error("mcp-publish: this connection has no granted serviceId namespace to claim; pass an explicit --serviceId.");
|
|
3430
|
-
return granted;
|
|
3431
|
-
}
|
|
3432
3461
|
function _untilSignalled$1() {
|
|
3433
3462
|
return new Promise((resolve) => {
|
|
3434
3463
|
const done = () => {
|
|
@@ -3450,7 +3479,7 @@ const clientInfo = {
|
|
|
3450
3479
|
version: "1.0.0"
|
|
3451
3480
|
};
|
|
3452
3481
|
/**
|
|
3453
|
-
* Serve the tools of every MCP server published on the hub (
|
|
3482
|
+
* Serve the tools of every MCP server published on the hub (MCP services and
|
|
3454
3483
|
* forwarded servers) as one stdio MCP server, optionally with the script tools.
|
|
3455
3484
|
*/
|
|
3456
3485
|
async function mcpCommand(channel, options = {}) {
|
|
@@ -3460,7 +3489,8 @@ async function mcpCommand(channel, options = {}) {
|
|
|
3460
3489
|
const aggregatorOptions = {
|
|
3461
3490
|
requestDirectoryAccess: options.requestDirectoryAccess,
|
|
3462
3491
|
log,
|
|
3463
|
-
clientInfo
|
|
3492
|
+
clientInfo,
|
|
3493
|
+
...options.mcpIdentities !== void 0 ? { mcpIdentityFor: (serviceId) => options.mcpIdentities?.[serviceId] } : {}
|
|
3464
3494
|
};
|
|
3465
3495
|
const transport = new StdioServerTransport(options.input ?? process.stdin, options.output ?? process.stdout);
|
|
3466
3496
|
const input = options.input ?? process.stdin;
|
|
@@ -9149,6 +9179,75 @@ Batch options:
|
|
|
9149
9179
|
process.stdout.write(out + "\n");
|
|
9150
9180
|
});
|
|
9151
9181
|
});
|
|
9182
|
+
/** Options that select the MCP server: a command after `--`, --url, or --mcp-config. */
|
|
9183
|
+
const mcpSourceOptions = (command) => command.option("--url <url>", "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);
|
|
9184
|
+
const mcpExposeOptions = (command) => command.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);
|
|
9185
|
+
const exposeFromFlags = (commandName, cmdOpts) => {
|
|
9186
|
+
if (!cmdOpts.service && !cmdOpts.forward && cmdOpts.mcpConfig === void 0) {
|
|
9187
|
+
process.stderr.write(`linkrpc: ${commandName} requires --service, --forward, or both.\n`);
|
|
9188
|
+
process.exit(2);
|
|
9189
|
+
}
|
|
9190
|
+
if (cmdOpts.group && !cmdOpts.service) {
|
|
9191
|
+
process.stderr.write(`linkrpc: ${commandName} --group requires --service.\n`);
|
|
9192
|
+
process.exit(2);
|
|
9193
|
+
}
|
|
9194
|
+
if (!cmdOpts.service && !cmdOpts.forward) return void 0;
|
|
9195
|
+
const groups = Object.entries(cmdOpts.group ?? {}).map(([groupName, keywords]) => ({
|
|
9196
|
+
name: groupName,
|
|
9197
|
+
keywords: keywords.split(",").filter(Boolean)
|
|
9198
|
+
}));
|
|
9199
|
+
return {
|
|
9200
|
+
...cmdOpts.service ? { service: groups.length > 0 ? { groups } : {} } : {},
|
|
9201
|
+
...cmdOpts.forward ? { forward: { sharing: "exclusive" } } : {}
|
|
9202
|
+
};
|
|
9203
|
+
};
|
|
9204
|
+
/** Validate the MCP server source flags; exits with usage errors. */
|
|
9205
|
+
const resolveMcpSource = async (commandName, mcpCommand, cmdOpts, expose) => {
|
|
9206
|
+
if ([
|
|
9207
|
+
mcpCommand !== void 0 && mcpCommand.length > 0,
|
|
9208
|
+
cmdOpts.url !== void 0,
|
|
9209
|
+
cmdOpts.stdio === true,
|
|
9210
|
+
cmdOpts.mcpConfig !== void 0
|
|
9211
|
+
].filter(Boolean).length !== 1) {
|
|
9212
|
+
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`);
|
|
9213
|
+
process.exit(2);
|
|
9214
|
+
}
|
|
9215
|
+
if (cmdOpts.stdio && expose?.service !== void 0) {
|
|
9216
|
+
process.stderr.write(`linkrpc: ${commandName} --stdio supports only --forward.\n`);
|
|
9217
|
+
process.exit(2);
|
|
9218
|
+
}
|
|
9219
|
+
if (cmdOpts.headerEnv !== void 0 && cmdOpts.url === void 0) {
|
|
9220
|
+
process.stderr.write(`linkrpc: ${commandName} --header-env requires --url.\n`);
|
|
9221
|
+
process.exit(2);
|
|
9222
|
+
}
|
|
9223
|
+
const file = cmdOpts.mcpConfig === void 0 ? void 0 : await readMcpPublishConfig(cmdOpts.mcpConfig);
|
|
9224
|
+
const resolvedExpose = expose ?? file?.expose;
|
|
9225
|
+
if (resolvedExpose === void 0) {
|
|
9226
|
+
process.stderr.write(`linkrpc: ${commandName} requires --service, --forward, or \`expose\` in --mcp-config.\n`);
|
|
9227
|
+
process.exit(2);
|
|
9228
|
+
}
|
|
9229
|
+
const headers = {
|
|
9230
|
+
...cmdOpts.header,
|
|
9231
|
+
...Object.fromEntries(Object.entries(cmdOpts.headerEnv ?? {}).map(([key, variable]) => [key, { fromEnv: variable }]))
|
|
9232
|
+
};
|
|
9233
|
+
return {
|
|
9234
|
+
transport: file !== void 0 ? file.transport : cmdOpts.stdio ? { kind: "own-stdio" } : cmdOpts.url !== void 0 ? {
|
|
9235
|
+
kind: "streamable-http",
|
|
9236
|
+
url: cmdOpts.url,
|
|
9237
|
+
...Object.keys(headers).length > 0 ? { headers } : {}
|
|
9238
|
+
} : {
|
|
9239
|
+
kind: "stdio",
|
|
9240
|
+
command: mcpCommand[0],
|
|
9241
|
+
args: mcpCommand.slice(1),
|
|
9242
|
+
env: {
|
|
9243
|
+
...definedEnv(process.env),
|
|
9244
|
+
...cmdOpts.env
|
|
9245
|
+
}
|
|
9246
|
+
},
|
|
9247
|
+
expose: resolvedExpose,
|
|
9248
|
+
file
|
|
9249
|
+
};
|
|
9250
|
+
};
|
|
9152
9251
|
if (profile === "hub") {
|
|
9153
9252
|
const exportRoutes = new JsonRpcExportRoutes();
|
|
9154
9253
|
program.command("json-rpc-export").description("Export Hub JSON-RPC services through one authenticated raw WebSocket listener.").requiredOption("--target-endpoint <uri>", "Listener URI, e.g. listen:ws://127.0.0.1:8123").option("--target-token <token>", "Local client authentication token (or put token in target URI)").option("--target-token-query-param <name>", "Accepted token query parameter (repeatable; replaces defaults tkn and token)", collectOption).option("--serviceId <id>", "Begin a route; follow each occurrence with --path", (value) => {
|
|
@@ -9210,11 +9309,12 @@ Batch options:
|
|
|
9210
9309
|
local.close();
|
|
9211
9310
|
}
|
|
9212
9311
|
});
|
|
9213
|
-
program.command("mcp").description("Expose the tools of all MCP servers published on the Hub (
|
|
9312
|
+
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, together with the LinkRPC script tools (runLinkRpcScript, awaitLinkRpcTask, cancelLinkRpcTask).").option("--no-scripts", "serve only the aggregated MCP tools, without loading the script sandbox").option("--mcp-identity <serviceId=identity>", "use this MCP identity (account) of a published MCP server instead of its default (repeatable)", collectKeyValue).action(async (cmdOpts) => {
|
|
9214
9313
|
await withChannel(endpoint, getPrincipalSpec(), async (channel, session) => {
|
|
9215
9314
|
await mcpCommand(channel, {
|
|
9315
|
+
...cmdOpts.mcpIdentity !== void 0 ? { mcpIdentities: cmdOpts.mcpIdentity } : {},
|
|
9216
9316
|
requestDirectoryAccess: session === void 0 ? void 0 : (serviceId) => requestDirectoryAccess(session, serviceId, { watch: true }),
|
|
9217
|
-
...cmdOpts.scripts ? {
|
|
9317
|
+
...cmdOpts.scripts !== false ? {
|
|
9218
9318
|
scripts: true,
|
|
9219
9319
|
...session !== void 0 ? { access: session } : {}
|
|
9220
9320
|
} : {}
|
|
@@ -9259,9 +9359,10 @@ Batch options:
|
|
|
9259
9359
|
logMessages: g_logMessages
|
|
9260
9360
|
});
|
|
9261
9361
|
});
|
|
9262
|
-
addTargetEndpointOptions(program.command("tunnel <serviceId>").description("Claim <serviceId> on the source hub (--endpoint*) and forward every request it routes here to a target endpoint over a second connection. The target endpoint is set via --target-endpoint / --target-endpoint-cmd / --target-endpoint-cmd-stdio; when it is --target-endpoint-cmd, the spawned child sees `hubGrantedServiceId::get().grantedServiceIdNamespace` = <serviceId> from its local hub, and global --provision-identity[-slot] applies to it. With `-c, --config`, the source hub is instead appended to the config as an endpoint claiming <serviceId>, and the in-process hub serves it (the config provides the target). Runs until Ctrl-C.")).option("--bidi", "also forward every request/notification the target endpoint emits back to the source hub, exposing the hub to the endpoint (forwards everything, unsigned)").action(async (serviceId, cmdOpts) => {
|
|
9362
|
+
addTargetEndpointOptions(program.command("tunnel <serviceId>").description("Claim <serviceId> (`./<name>`: relative to the granted namespace) on the source hub (--endpoint*) and forward every request it routes here to a target endpoint over a second connection. The target endpoint is set via --target-endpoint / --target-endpoint-cmd / --target-endpoint-cmd-stdio; when it is --target-endpoint-cmd, the spawned child sees `hubGrantedServiceId::get().grantedServiceIdNamespace` = <serviceId> from its local hub, and global --provision-identity[-slot] applies to it. With `-c, --config`, the source hub is instead appended to the config as an endpoint claiming <serviceId>, and the in-process hub serves it (the config provides the target). Runs until Ctrl-C.")).option("--bidi", "also forward every request/notification the target endpoint emits back to the source hub, exposing the hub to the endpoint (forwards everything, unsigned)").action(async (serviceId, cmdOpts) => {
|
|
9263
9363
|
const localEp = needEndpoint(endpoint);
|
|
9264
9364
|
if (g_hubConfigPath !== void 0) {
|
|
9365
|
+
if (serviceId.startsWith("./")) throw new InvalidArgumentError("relative service ids (./<name>) are not supported with --config");
|
|
9265
9366
|
const baseConfig = loadHubConfig(g_hubConfigPath);
|
|
9266
9367
|
const claimEndpoint = resolvedEndpointToConfig(localEp, { claimServiceIds: [serviceId] });
|
|
9267
9368
|
const running = await runHub({
|
|
@@ -9285,6 +9386,7 @@ Batch options:
|
|
|
9285
9386
|
}
|
|
9286
9387
|
const targetEp = resolveTargetEndpointOrExit(cmdOpts, program.opts(), "tunnel");
|
|
9287
9388
|
const local = await connect(localEp, wireLog("source"));
|
|
9389
|
+
serviceId = (await resolveServiceIdToClaim(local, serviceId)).serviceId;
|
|
9288
9390
|
const remote = await connectTargetEndpoint(targetEp, serviceId);
|
|
9289
9391
|
try {
|
|
9290
9392
|
reportIdentity(await setupSigning(local.channel, local.signing, getPrincipalSpec(), { negotiateHubCaps: isHubEndpoint(localEp) }));
|
|
@@ -9404,52 +9506,32 @@ Batch options:
|
|
|
9404
9506
|
broker.close();
|
|
9405
9507
|
}
|
|
9406
9508
|
});
|
|
9407
|
-
const mcpUpstreamOptions = (command) => command.option("--serviceId <serviceId>", "serviceId
|
|
9509
|
+
const mcpUpstreamOptions = (command) => mcpSourceOptions(command).option("--serviceId <serviceId>", "serviceId to claim; `./<name>` is relative to the connection's granted namespace (or a namespace for this user and host, requested from the hub). Default: the granted namespace").option("--stdio", "forward the running MCP server attached to this process's stdin/stdout, one connection at a time");
|
|
9408
9510
|
const runMcpPublish = async (commandName, mcpCommand, cmdOpts, expose, name) => {
|
|
9409
9511
|
const localEp = needEndpoint(endpoint);
|
|
9410
|
-
|
|
9411
|
-
process.stderr.write(`linkrpc: ${commandName} requires either an MCP server command after \`--\` or --url, e.g. \`${commandName} -- npx -y @modelcontextprotocol/server-everything\`.\n`);
|
|
9412
|
-
process.exit(2);
|
|
9413
|
-
}
|
|
9414
|
-
const transport = cmdOpts.url !== void 0 ? {
|
|
9415
|
-
kind: "streamable-http",
|
|
9416
|
-
url: cmdOpts.url,
|
|
9417
|
-
...cmdOpts.header ? { headers: cmdOpts.header } : {}
|
|
9418
|
-
} : {
|
|
9419
|
-
kind: "stdio",
|
|
9420
|
-
command: mcpCommand[0],
|
|
9421
|
-
args: mcpCommand.slice(1),
|
|
9422
|
-
env: {
|
|
9423
|
-
...definedEnv(process.env),
|
|
9424
|
-
...cmdOpts.env
|
|
9425
|
-
}
|
|
9426
|
-
};
|
|
9512
|
+
const source = await resolveMcpSource(commandName, mcpCommand, cmdOpts, expose);
|
|
9427
9513
|
const local = await connect(localEp, wireLog("hub"));
|
|
9428
9514
|
try {
|
|
9429
9515
|
reportIdentity(await setupSigning(local.channel, local.signing, getPrincipalSpec(), { negotiateHubCaps: isHubEndpoint(localEp) }));
|
|
9516
|
+
const id = name ?? source.file?.id;
|
|
9430
9517
|
await mcpPublishCommand({
|
|
9431
9518
|
...cmdOpts.serviceId !== void 0 ? { serviceId: cmdOpts.serviceId } : {},
|
|
9432
|
-
...
|
|
9519
|
+
...id !== void 0 ? { name: id } : {},
|
|
9520
|
+
...source.file?.identities !== void 0 ? { identities: source.file.identities } : {},
|
|
9521
|
+
...source.file?.description !== void 0 ? { description: source.file.description } : {},
|
|
9433
9522
|
local,
|
|
9434
|
-
transport,
|
|
9435
|
-
expose
|
|
9523
|
+
transport: source.transport,
|
|
9524
|
+
expose: source.expose
|
|
9436
9525
|
});
|
|
9437
9526
|
} finally {
|
|
9438
9527
|
local.close();
|
|
9439
9528
|
}
|
|
9440
9529
|
};
|
|
9441
|
-
mcpUpstreamOptions(program.command("mcp-forward [mcpCommand...]").description("
|
|
9530
|
+
mcpUpstreamOptions(program.command("mcp-forward [mcpCommand...]").description("Shorthand for `mcp-publish --forward`: relay an MCP server verbatim through the hub (--endpoint*) over `mcp.forward`. The MCP server is a command after `--` (a fresh process per connection), --url (a new HTTP session per connection), or --stdio (the running server attached to this process's stdin/stdout, one connection at a time). By default it claims this connection's granted serviceId namespace. Runs until Ctrl-C.")).action(async (mcpCommand, cmdOpts) => {
|
|
9442
9531
|
await runMcpPublish("mcp-forward", mcpCommand, cmdOpts, { forward: { sharing: "exclusive" } }, void 0);
|
|
9443
9532
|
});
|
|
9444
|
-
mcpUpstreamOptions(program.command("mcp-publish [mcpCommand...]").description("Publish an MCP server through the hub (--endpoint*). --
|
|
9445
|
-
|
|
9446
|
-
process.stderr.write("linkrpc: mcp-publish requires --typed, --forward, or both.\n");
|
|
9447
|
-
process.exit(2);
|
|
9448
|
-
}
|
|
9449
|
-
await runMcpPublish("mcp-publish", mcpCommand, cmdOpts, {
|
|
9450
|
-
...cmdOpts.typed ? { typed: {} } : {},
|
|
9451
|
-
...cmdOpts.forward ? { forward: { sharing: "exclusive" } } : {}
|
|
9452
|
-
}, cmdOpts.name);
|
|
9533
|
+
mcpExposeOptions(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."))).action(async (mcpCommand, cmdOpts) => {
|
|
9534
|
+
await runMcpPublish("mcp-publish", mcpCommand, cmdOpts, exposeFromFlags("mcp-publish", cmdOpts), cmdOpts.name);
|
|
9453
9535
|
});
|
|
9454
9536
|
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) => {
|
|
9455
9537
|
await withResolvedSigning(endpoint, getPrincipalSpec(), async (_conn, session) => {
|
|
@@ -9484,7 +9566,7 @@ Batch options:
|
|
|
9484
9566
|
process.once("SIGINT", onSignal);
|
|
9485
9567
|
process.once("SIGTERM", onSignal);
|
|
9486
9568
|
try {
|
|
9487
|
-
const { runApprovalUi } = await import("./runApprovalUi-
|
|
9569
|
+
const { runApprovalUi } = await import("./runApprovalUi-5soIqxOS.js");
|
|
9488
9570
|
await runApprovalUi({
|
|
9489
9571
|
client,
|
|
9490
9572
|
signal: stop.signal
|
|
@@ -9499,7 +9581,7 @@ Batch options:
|
|
|
9499
9581
|
registerViewCommands(program, (action) => withChannel(endpoint, getPrincipalSpec(), action));
|
|
9500
9582
|
program.command("ui").description("Launch the terminal UI (form-based browser of services + methods).").action(async () => {
|
|
9501
9583
|
const acquired = await acquireConnection(endpoint);
|
|
9502
|
-
const { runUi } = await import("./runUi-
|
|
9584
|
+
const { runUi } = await import("./runUi-Dkm-6D6s.js");
|
|
9503
9585
|
try {
|
|
9504
9586
|
await runUi({
|
|
9505
9587
|
endpoint: acquired.ep,
|
|
@@ -9755,7 +9837,7 @@ function hasEndpointOverrides(values) {
|
|
|
9755
9837
|
async function withChannel(endpoint, principalSpec, fn, opts = {}) {
|
|
9756
9838
|
const sign = resolveSigning(g_invocation?.profile ?? "rpc", g_invocation?.values ?? {}, opts.requireSigning);
|
|
9757
9839
|
const acquired = await acquireConnection(endpoint);
|
|
9758
|
-
const conn = await connect(acquired.ep, acquired.running === void 0 ? wireLog("hub") : void 0);
|
|
9840
|
+
const conn = await connect(acquired.ep, acquired.running === void 0 ? wireLog("hub") : void 0, { cmdEnvLocalHub: g_invocation?.profile === "hub" });
|
|
9759
9841
|
try {
|
|
9760
9842
|
const schemaSource = g_invocation?.values.schema;
|
|
9761
9843
|
const channel = schemaSource === void 0 ? conn.channel : withStaticHubReflection(conn.channel, await loadStaticHubSchema(schemaSource));
|
|
@@ -10079,4 +10161,4 @@ function definedEnv(env) {
|
|
|
10079
10161
|
//#endregion
|
|
10080
10162
|
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 };
|
|
10081
10163
|
|
|
10082
|
-
//# sourceMappingURL=cli-
|
|
10164
|
+
//# sourceMappingURL=cli-BY9fXhpJ.js.map
|