@jini-ai/mcp 0.3.4 → 0.4.0

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/README.md +97 -22
  3. package/dist/agent-install/install.d.ts +20 -4
  4. package/dist/agent-install/install.js +11 -11
  5. package/dist/bin/serve.d.ts +25 -13
  6. package/dist/bin/serve.js +42 -21
  7. package/dist/client/client.d.ts +28 -8
  8. package/dist/client/client.js +25 -21
  9. package/dist/core/config.d.ts +57 -18
  10. package/dist/core/config.js +76 -48
  11. package/dist/core/index.d.ts +1 -2
  12. package/dist/core/index.js +1 -2
  13. package/dist/core/install-info.d.ts +4 -1
  14. package/dist/core/install-info.js +5 -5
  15. package/dist/core/tokens.d.ts +39 -13
  16. package/dist/core/tokens.js +54 -24
  17. package/dist/federation/adapter.http.d.ts +67 -0
  18. package/dist/federation/adapter.http.js +414 -0
  19. package/dist/federation/approvals/call-confirmation.d.ts +23 -0
  20. package/dist/federation/approvals/call-confirmation.js +124 -0
  21. package/dist/federation/approvals/index.d.ts +4 -0
  22. package/dist/federation/approvals/index.js +4 -0
  23. package/dist/federation/approvals/ports.d.ts +107 -0
  24. package/dist/federation/approvals/ports.js +2 -0
  25. package/dist/federation/approvals/revocation.d.ts +61 -0
  26. package/dist/federation/approvals/revocation.js +52 -0
  27. package/dist/federation/bootstrap.d.ts +100 -0
  28. package/dist/federation/bootstrap.js +182 -0
  29. package/dist/federation/config.d.ts +68 -0
  30. package/dist/federation/config.js +40 -0
  31. package/dist/federation/index.d.ts +14 -0
  32. package/dist/federation/index.js +14 -0
  33. package/dist/federation/mcp-protocol.d.ts +115 -0
  34. package/dist/federation/mcp-protocol.js +151 -0
  35. package/dist/federation/messages.d.ts +54 -0
  36. package/dist/federation/messages.js +35 -0
  37. package/dist/federation/ports.d.ts +287 -0
  38. package/dist/federation/ports.js +5 -0
  39. package/dist/federation/presets.d.ts +66 -0
  40. package/dist/federation/presets.js +30 -0
  41. package/dist/federation/refusal-notice.d.ts +198 -0
  42. package/dist/federation/refusal-notice.js +193 -0
  43. package/dist/federation/registrations.d.ts +171 -0
  44. package/dist/federation/registrations.js +181 -0
  45. package/dist/federation/reload.d.ts +112 -0
  46. package/dist/federation/reload.js +110 -0
  47. package/dist/federation/stdio/adapter.stdio.d.ts +157 -0
  48. package/dist/federation/stdio/adapter.stdio.js +526 -0
  49. package/dist/federation/stdio/default-connect.d.ts +29 -0
  50. package/dist/federation/stdio/default-connect.js +92 -0
  51. package/dist/federation/stdio/index.d.ts +4 -0
  52. package/dist/federation/stdio/index.js +4 -0
  53. package/dist/federation/stdio/stdio-launch-resolver.d.ts +139 -0
  54. package/dist/federation/stdio/stdio-launch-resolver.js +227 -0
  55. package/dist/federation/testing/adapter.memory.d.ts +177 -0
  56. package/dist/federation/testing/adapter.memory.js +189 -0
  57. package/dist/federation/testing/index.d.ts +3 -0
  58. package/dist/federation/testing/index.js +3 -0
  59. package/dist/federation/testing/tool-approvals.memory.d.ts +27 -0
  60. package/dist/federation/testing/tool-approvals.memory.js +38 -0
  61. package/dist/federation/tool-approvals.d.ts +97 -0
  62. package/dist/federation/tool-approvals.js +42 -0
  63. package/dist/federation/trust.d.ts +471 -0
  64. package/dist/federation/trust.js +707 -0
  65. package/dist/index.d.ts +175 -2
  66. package/dist/index.js +172 -2
  67. package/dist/server/daemon-client.d.ts +16 -4
  68. package/dist/server/daemon-client.js +41 -19
  69. package/dist/server/ports.d.ts +9 -0
  70. package/dist/server/ports.js +2 -0
  71. package/dist/server/resource-protocol.d.ts +14 -4
  72. package/dist/server/resource-protocol.js +6 -6
  73. package/dist/server/resources/active-resource.js +3 -3
  74. package/dist/server/sdk-transport.d.ts +11 -0
  75. package/dist/server/sdk-transport.js +31 -0
  76. package/dist/server/tool-protocol.d.ts +31 -9
  77. package/dist/server/tool-protocol.js +20 -18
  78. package/dist/server/tool-server.d.ts +60 -43
  79. package/dist/server/tool-server.js +51 -27
  80. package/dist/server/tools/component-catalog-tools.js +7 -7
  81. package/dist/server/tools/delegated-tool.d.ts +7 -4
  82. package/dist/server/tools/delegated-tool.js +14 -15
  83. package/dist/server/tools/run-tools.js +15 -15
  84. package/dist/server/tools/tool-catalog-tools.js +7 -7
  85. package/dist/tools/ask-choice/index.d.ts +123 -0
  86. package/dist/tools/ask-choice/index.js +98 -0
  87. package/dist/tools/ask-choice/pending.d.ts +11 -0
  88. package/dist/tools/ask-choice/pending.js +34 -0
  89. package/dist/tools/ask-choice/question.d.ts +16 -0
  90. package/dist/tools/ask-choice/question.js +60 -0
  91. package/dist/tools/ask-choice/schema.d.ts +91 -0
  92. package/dist/tools/ask-choice/schema.js +27 -0
  93. package/dist/tools/ask-choice/types.d.ts +106 -0
  94. package/dist/tools/ask-choice/types.js +2 -0
  95. package/package.json +43 -5
@@ -0,0 +1,157 @@
1
+ import type { FederationMessages } from "../messages.js";
2
+ import type { McpSessionPort, McpStdioChannel, McpClientInfo } from "../ports.js";
3
+ import type { ResolvedStdioLaunch } from "./stdio-launch-resolver.js";
4
+ /**
5
+ * The working directory one stdio child is spawned in.
6
+ *
7
+ * An explicit `cwd` always wins. Otherwise a package runner gets a neutral directory instead of the
8
+ * daemon's own cwd, because npm reads the cwd's project tree BEFORE it runs anything: in this dev
9
+ * checkout that tree links `@jini-ai/*` to a pnpm monorepo whose `workspace:*` ranges npm cannot
10
+ * parse, so `npx -y namecom-mcp@latest` died with `EUNSUPPORTEDPROTOCOL` on every daemon boot
11
+ * (2026-09-29) while the same command worked from any other directory. A package fetched by name
12
+ * never needs host app's project directory; a host's own `package.json` is the wrong input for it.
13
+ *
14
+ * Anything else keeps inheriting the daemon's cwd exactly as before — a relative `command` (a
15
+ * package runner given as `./node_modules/.bin/npx` included) or a server that reads files relative
16
+ * to where it was started depends on it.
17
+ *
18
+ * @complexity O(1).
19
+ */
20
+ export declare function resolveStdioChildCwd({ resolved }: {
21
+ resolved: ResolvedStdioLaunch;
22
+ }, { neutralDir }?: {
23
+ neutralDir?: string | undefined;
24
+ }): string | undefined;
25
+ /**
26
+ * Appends one stderr chunk and keeps only the last {@link STDERR_TAIL_CHARS} characters.
27
+ * @complexity O(n) in the chunk length.
28
+ */
29
+ export declare function keepStderrTail({ tail, chunk }: {
30
+ tail: string;
31
+ chunk: string;
32
+ }): string;
33
+ /**
34
+ * A child's stderr tail that is redacted BEFORE it is truncated.
35
+ *
36
+ * Truncating first cut a token printed just before ~600 characters of diagnostics in half, leaving a
37
+ * fragment no exact-value replacement can match (codex review 2026-09-29). So each chunk is redacted
38
+ * as it arrives, and the last `longest secret - 1` characters are held back from the kept tail until
39
+ * the next chunk — they may be the start of a secret split across chunks. Only redacted text is
40
+ * ever truncated, so the kept tail can begin mid-`[redacted]` but never mid-secret.
41
+ *
42
+ * @param secretValues - The child's own `env` values, as spawned.
43
+ * @complexity O(c · v) per chunk of length c.
44
+ */
45
+ export declare function createStderrTail({ secretValues }: {
46
+ secretValues: readonly string[];
47
+ }): {
48
+ append(required: {
49
+ chunk: string;
50
+ }): void;
51
+ text(): string;
52
+ };
53
+ /**
54
+ * The close reason for a child that exited: code and signal, plus what it last printed to stderr.
55
+ *
56
+ * Every value of the connection's own `env` is replaced with `[redacted]` first. That env holds the
57
+ * row's unsealed credentials, and a server that echoes its config on failure would otherwise carry a
58
+ * token into `connectFailures` — which the admissions route serves to the admin UI and whose contract
59
+ * (`bootstrap.ts`) is "never a raw env value or secret".
60
+ *
61
+ * @param secretValues - The child's own `env` values, as spawned.
62
+ * @complexity O(s · v) in stderr length and env value count.
63
+ */
64
+ export declare function describeChildExit({ code, signal, stderrTail, secretValues }: {
65
+ code: number | null;
66
+ signal: NodeJS.Signals | null;
67
+ stderrTail: string;
68
+ secretValues: readonly string[];
69
+ }): string;
70
+ /**
71
+ * Performs the MCP handshake over `channel` and returns the connected session.
72
+ *
73
+ * @param deps.channel - The transport seam. `spawnMcpStdioChannel` in production, a scripted
74
+ * double in tests.
75
+ * @param deps.requestTimeoutMs - Per-request ceiling, applied to the handshake too.
76
+ * @throws {Error} If `initialize` fails, times out, or the channel dies during it.
77
+ * @complexity O(1) beyond the remote's round-trip.
78
+ */
79
+ export declare function connectMcpStdioSession(deps: {
80
+ channel: McpStdioChannel;
81
+ requestTimeoutMs: number;
82
+ clientInfo: McpClientInfo;
83
+ messages: FederationMessages;
84
+ }): Promise<McpSessionPort>;
85
+ /**
86
+ * The production {@link McpStdioChannel}: a child process, its stdin, and newline-framed stdout.
87
+ *
88
+ * Deliberately logic-free — reassembly and nothing else — because everything above it is already
89
+ * under test through the channel seam, and code that only runs when a real process exists is code
90
+ * that only fails in production.
91
+ *
92
+ * `env` REPLACES rather than extends the parent environment, which is the security-relevant choice:
93
+ * the daemon's own `process.env` holds `host daemon credential` (`daemon-auth.ts`), and handing
94
+ * that to a third-party vendor's child process would give it host app's own daemon credential — the
95
+ * exact inversion of the `mcp-injection.ts` grant, and a far worse one. A federated server receives
96
+ * what `config.ts` explicitly puts in `env`, plus what {@link buildMcpChildEnv} inherits and nothing else.
97
+ *
98
+ * Takes a {@link ResolvedStdioLaunch} rather than an {@link McpStdioLaunchSpec} (S2 of the
99
+ * desktop-npx plan): the launch has already passed through the injected `McpStdioLaunchResolver`
100
+ * by the time it gets here, so `resolved.command`/`resolved.args` are already whatever the resolver
101
+ * decided to run, and `resolved.launchEnv` is threaded into {@link buildMcpChildEnv} alongside the
102
+ * connection's own `env`. On every non-desktop deployment `resolved` is the identity resolver's
103
+ * output — `command`/`args`/`env` unchanged, `launchEnv: {}` — so this stays byte-identical to
104
+ * before the resolver existed.
105
+ *
106
+ * @complexity O(n) in bytes received.
107
+ */
108
+ export declare function spawnMcpStdioChannel(resolved: ResolvedStdioLaunch & {
109
+ messages: FederationMessages;
110
+ }): McpStdioChannel;
111
+ /** {@link buildMcpChildEnv}'s input. Everything past `specEnv` is a test seam that defaults to the
112
+ * real process; production passes only `command` and `specEnv`. */
113
+ interface McpChildEnvInput {
114
+ /** The child's `command`, compared against `execPath` on win32. */
115
+ readonly command: string;
116
+ /** The connection's own `env`, which wins over anything inherited AND over `launchEnv`. */
117
+ readonly specEnv: Readonly<Record<string, string>>;
118
+ /**
119
+ * The stdio launch resolver's own additions (S2 of the desktop-npx plan) — `ELECTRON_RUN_AS_NODE`,
120
+ * `PATH`, `npm_config_*` — from `stdio-launch-resolver.ts`'s {@link ResolvedStdioLaunch.launchEnv}.
121
+ * Layered between the inherited allowlist and `specEnv`: it can add variables the parent process
122
+ * never had, but the connection's own `env` still wins over it, including an explicit `PATH` that
123
+ * deliberately drops the toolchain shims — the user's own call, per plan §4. Defaults to `{}`, so
124
+ * omitting it (every caller before this parameter existed, and every non-desktop deployment today)
125
+ * leaves the result byte-identical.
126
+ */
127
+ readonly launchEnv?: Readonly<Record<string, string>> | undefined;
128
+ readonly platform?: NodeJS.Platform | undefined;
129
+ readonly parentEnv?: NodeJS.ProcessEnv | undefined;
130
+ readonly execPath?: string | undefined;
131
+ }
132
+ /**
133
+ * The complete environment one federated MCP child is spawned with.
134
+ *
135
+ * On every platform: {@link INHERITED_ENV_VARS} from the parent, then `launchEnv`, then the
136
+ * connection's own `env` over the top of both. On darwin and linux, with `launchEnv` empty (every
137
+ * non-desktop deployment), that is ALL — byte-identical to what this adapter has always sent.
138
+ *
139
+ * On win32, two further additions:
140
+ *
141
+ * 1. {@link WIN32_INHERITED_ENV_VARS}, which Windows programs need to start.
142
+ * 2. `ELECTRON_RUN_AS_NODE`, but ONLY when the child's `command` is this process's own executable
143
+ * and this process itself runs with it set. host app Desktop registers its own Electron binary as the
144
+ * command of its `host-desktop` connection on win32, where no launcher script can be exec'd, and
145
+ * without this variable that binary opens a second GUI app instead of running the bridge script.
146
+ * Carrying it here rather than in the connection's `env` matters: a row's `env` is sealed with the
147
+ * site's root key, so a flag in it fails the whole save with `SECRET_STORE_UNCONFIGURED` on a
148
+ * site that has none. The rule is narrow on purpose — "a child that is this very binary runs in
149
+ * the mode this binary runs in" — so no third-party child ever has its runtime mode changed.
150
+ *
151
+ * Empty parent values are skipped, as they always were.
152
+ *
153
+ * @complexity O(k) in the number of inherited names.
154
+ */
155
+ export declare function buildMcpChildEnv({ command, specEnv, }: Pick<McpChildEnvInput, "command" | "specEnv">, { launchEnv, platform, parentEnv, execPath, }?: Omit<McpChildEnvInput, "command" | "specEnv">): Record<string, string>;
156
+ export {};
157
+ //# sourceMappingURL=adapter.stdio.d.ts.map