@adtl/gateway 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,103 @@
1
- # Temporary Holding Version
1
+ # @adtl/gateway
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Experimental.** ADTL is a personal open-source project built on draft MCP proposals ([trust-annotations](https://github.com/modelcontextprotocol/experimental-ext-tool-annotations), [SEP-2624 interceptors](https://github.com/modelcontextprotocol/experimental-ext-interceptors)) that are still changing. It is not a security guarantee: don't rely on it to protect production systems yet. Feedback is very welcome.
4
+
5
+ An MCP gateway for AI agents. It sits between your agent (Claude Code, Cursor, any MCP client) and your MCP servers, and:
6
+
7
+ - **labels every tool result**: where it came from, whether it can be trusted, how sensitive it is (MCP's draft `trust-annotations` format)
8
+ - **checks every tool call** against what the session has already seen: allow, ask, or block
9
+ - **writes an audit log** of every decision (no arguments or results are stored)
10
+
11
+ It stops attacks like the 2025 GitHub MCP exfiltration, where a public issue told an agent to post private repository contents in a comment.
12
+
13
+ ## Quick start
14
+
15
+ 1. Describe your tools in `adtl.yaml`:
16
+
17
+ ```yaml
18
+ servers:
19
+ github:
20
+ tools:
21
+ get_issue: { integrity: untrusted, confidentiality: public, egress: none }
22
+ get_file: { integrity: trusted, confidentiality: private, egress: none }
23
+ add_comment: { integrity: trusted, confidentiality: public, egress: public }
24
+
25
+ policy:
26
+ rules:
27
+ - name: private-stays-private
28
+ when: { session.confidentiality: [private, secret], tool.egress: public }
29
+ then: block
30
+ reason: Private data must not reach a public tool
31
+
32
+ gateway:
33
+ upstreams:
34
+ github:
35
+ command: npx
36
+ args: ["-y", "@modelcontextprotocol/server-github"]
37
+ env: { GITHUB_PERSONAL_ACCESS_TOKEN: "${GITHUB_TOKEN}" }
38
+ ```
39
+
40
+ 2. Point your MCP client at the gateway, for example in Claude Code:
41
+
42
+ ```sh
43
+ claude mcp add adtl -- npx -y @adtl/gateway --config /absolute/path/to/adtl.yaml
44
+ ```
45
+
46
+ 3. Your agent now sees the upstream tools as `github__get_issue`, `github__add_comment`, and so on. When a call is stopped, the agent receives an error result that explains why.
47
+
48
+ ## Configuration
49
+
50
+ One file holds both the labels and the gateway settings.
51
+
52
+ ### Labels: what each tool returns, and where it can send data
53
+
54
+ | Key | Values | Meaning |
55
+ |---|---|---|
56
+ | `integrity` | `trusted`, `untrusted` | Can the tool's *result* be trusted to influence actions? Content from strangers (issues, emails, web pages) is untrusted. |
57
+ | `confidentiality` | `public`, `private`, `secret` | Who may see the tool's *result*? |
58
+ | `egress` | `none`, `internal`, `external`, `public` | Where *calling* the tool can send data. |
59
+
60
+ Tools without a rule use the defaults (`untrusted`, `private`, egress `unknown`). That's safe but strict, so describe the tools you use.
61
+
62
+ Labels only get stricter as a session goes on. A session that has read anything untrusted stays untrusted until the session ends.
63
+
64
+ ### Policy
65
+
66
+ Rules match on `session.integrity`, `session.confidentiality`, `tool.egress` and `tool` (`server.tool` globs such as `github.*`), and decide `allow`, `ask` or `block`. When several rules match, the most restrictive decision wins. In this version `ask` is treated as `block`; approvals are planned for v0.2.
67
+
68
+ ### Gateway
69
+
70
+ | Key | Meaning |
71
+ |---|---|
72
+ | `gateway.upstreams.<id>` | A stdio server (`command`, `args`, `env`, `cwd`) or an HTTP server (`url`, `headers`). The `<id>` must match the key under `servers:`. |
73
+ | `gateway.audit` | Path of a JSONL audit log, relative to the config file |
74
+ | `gateway.interceptorTimeoutMs` | Timeout per interceptor call (default 5000) |
75
+ | `gateway.interceptors` | Custom interceptor server command (default: the bundled `@adtl/interceptors`) |
76
+
77
+ `${VAR}` in commands, args, env, URLs and headers is read from the environment, so secrets stay out of the file.
78
+
79
+ ## How it works
80
+
81
+ ```
82
+ agent ──▶ adtl-gateway ──▶ upstream MCP servers
83
+ │
84
+ └─▶ adtl-interceptors (separate process, SEP-2624)
85
+ adtl.policy checks the call before it runs
86
+ adtl.label labels the result after it returns
87
+ ```
88
+
89
+ The gateway fails closed. If an interceptor errors or times out, the call is stopped. If a result can't be labeled, it is withheld. If the interceptors are missing, the gateway refuses to start.
90
+
91
+ ## Limits of this version
92
+
93
+ - Only tools are proxied. Resources and prompts are not passed through yet.
94
+ - `ask` blocks instead of asking. Human approvals are planned for v0.2.
95
+ - Labels last for one gateway process, which is one agent session. They are not carried into files, memory or other agents yet; that's planned for v0.3.
96
+ - Labels are set by your config. Servers' own trust claims can only make labels stricter, unless you set `acceptServerClaims: true`.
97
+
98
+ ## Links
99
+
100
+ - Repository, demo and examples: https://github.com/probita-ai/adtl
101
+ - Related packages: [`@adtl/interceptors`](https://www.npmjs.com/package/@adtl/interceptors), [`@adtl/labels`](https://www.npmjs.com/package/@adtl/labels)
102
+
103
+ License: Apache-2.0
@@ -0,0 +1,30 @@
1
+ export interface AuditEntry {
2
+ ts: string;
3
+ sessionId: string;
4
+ event: "tools/call";
5
+ server: string;
6
+ tool: string;
7
+ /** Final outcome of the call. */
8
+ outcome: "forwarded" | "blocked" | "upstream_error";
9
+ decision?: string;
10
+ reason?: string;
11
+ matched?: unknown;
12
+ callHash?: unknown;
13
+ label?: unknown;
14
+ sessionLabel?: unknown;
15
+ warnings?: string[];
16
+ durationMs: number;
17
+ }
18
+ export interface AuditSink {
19
+ write(entry: AuditEntry): void;
20
+ }
21
+ export declare class JsonlAuditLog implements AuditSink {
22
+ readonly path: string;
23
+ constructor(path: string);
24
+ write(entry: AuditEntry): void;
25
+ }
26
+ export declare class MemoryAuditLog implements AuditSink {
27
+ readonly entries: AuditEntry[];
28
+ write(entry: AuditEntry): void;
29
+ }
30
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,gBAAgB,CAAC;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CAChC;AAED,qBAAa,aAAc,YAAW,SAAS;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM;IAIjC,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;CAG/B;AAED,qBAAa,cAAe,YAAW,SAAS;IAC9C,QAAQ,CAAC,OAAO,EAAE,UAAU,EAAE,CAAM;IACpC,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;CAG/B"}
package/dist/audit.js ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Append-only JSONL audit log. One line per tool call.
3
+ *
4
+ * Arguments and results are never written; the call is identified by its
5
+ * hash, so the log can be shared without leaking the data it describes.
6
+ */
7
+ import { appendFileSync, mkdirSync } from "node:fs";
8
+ import { dirname } from "node:path";
9
+ export class JsonlAuditLog {
10
+ path;
11
+ constructor(path) {
12
+ this.path = path;
13
+ mkdirSync(dirname(path), { recursive: true });
14
+ }
15
+ write(entry) {
16
+ appendFileSync(this.path, `${JSON.stringify(entry)}\n`, "utf8");
17
+ }
18
+ }
19
+ export class MemoryAuditLog {
20
+ entries = [];
21
+ write(entry) {
22
+ this.entries.push(entry);
23
+ }
24
+ }
25
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwBpC,MAAM,OAAO,aAAa;IACH;IAArB,YAAqB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAC/B,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,KAAiB;QACrB,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC;CACF;AAED,MAAM,OAAO,cAAc;IAChB,OAAO,GAAiB,EAAE,CAAC;IACpC,KAAK,CAAC,KAAiB;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;CACF"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * adtl-gateway: an MCP server for your agent that proxies to your real MCP
4
+ * servers through ADTL's interceptors.
5
+ *
6
+ * adtl-gateway --config adtl.yaml
7
+ *
8
+ * Point your MCP client (e.g. Claude Code's .mcp.json) at this command.
9
+ * Logs go to stderr; stdout carries MCP JSON-RPC only.
10
+ */
11
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
12
+ import { EnvExpansionError } from "./config.js";
13
+ import { GATEWAY_VERSION } from "./gateway.js";
14
+ import { GatewayConfigError, loadGatewayConfig, startGateway } from "./startup.js";
15
+ const USAGE = `Usage: adtl-gateway --config <adtl.yaml>
16
+
17
+ Runs an MCP server over stdio that forwards tool calls to the upstream
18
+ servers in the config, checking and labeling each call with ADTL.
19
+
20
+ Options:
21
+ -c, --config <path> ADTL config file with a gateway: section. Required.
22
+ -v, --version Print the version and exit.
23
+ -h, --help Show this help.`;
24
+ function parseArgs(argv) {
25
+ const out = {};
26
+ for (let i = 0; i < argv.length; i++) {
27
+ const a = argv[i];
28
+ if (a === "-h" || a === "--help")
29
+ out.help = true;
30
+ else if (a === "-v" || a === "--version")
31
+ out.version = true;
32
+ else if (a === "-c" || a === "--config")
33
+ out.config = argv[++i];
34
+ else if (a?.startsWith("--config="))
35
+ out.config = a.slice("--config=".length);
36
+ else
37
+ throw new GatewayConfigError(`Unknown argument: ${a}\n\n${USAGE}`);
38
+ }
39
+ return out;
40
+ }
41
+ async function main() {
42
+ const args = parseArgs(process.argv.slice(2));
43
+ // --help and --version print to stdout and exit; MCP is never served in these modes.
44
+ if (args.help)
45
+ return void console.log(USAGE);
46
+ if (args.version)
47
+ return void console.log(GATEWAY_VERSION);
48
+ if (!args.config)
49
+ throw new GatewayConfigError(`Missing --config\n\n${USAGE}`);
50
+ const loaded = await loadGatewayConfig(args.config);
51
+ const started = await startGateway(loaded);
52
+ const server = started.gateway.createServer();
53
+ let closing = false;
54
+ const shutdown = async () => {
55
+ if (closing)
56
+ return;
57
+ closing = true;
58
+ await server.close().catch(() => undefined);
59
+ await started.close();
60
+ process.exit(0);
61
+ };
62
+ server.onclose = () => void shutdown();
63
+ // The agent closing our stdin means the session is over; don't wait for a signal.
64
+ process.stdin.on("end", () => void shutdown());
65
+ process.stdin.on("close", () => void shutdown());
66
+ process.on("SIGINT", () => void shutdown());
67
+ process.on("SIGTERM", () => void shutdown());
68
+ await server.connect(new StdioServerTransport());
69
+ console.error(`[adtl-gateway] ${GATEWAY_VERSION} ready (session ${started.gateway.sessionId})`);
70
+ }
71
+ main().catch((err) => {
72
+ const known = err instanceof GatewayConfigError || err instanceof EnvExpansionError;
73
+ console.error(known ? `[adtl-gateway] ${err.message}` : err);
74
+ process.exit(1);
75
+ });
76
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,199 @@
1
+ /**
2
+ * The `gateway:` section of adtl.yaml.
3
+ *
4
+ * gateway:
5
+ * audit: ./adtl-audit.jsonl # optional JSONL audit log
6
+ * upstreams:
7
+ * github: # id must match `servers.github` in the label config
8
+ * command: npx
9
+ * args: ["-y", "@modelcontextprotocol/server-github"]
10
+ * env: { GITHUB_PERSONAL_ACCESS_TOKEN: "${GITHUB_TOKEN}" }
11
+ * docs:
12
+ * url: https://example.com/mcp
13
+ * headers: { Authorization: "Bearer ${DOCS_TOKEN}" }
14
+ *
15
+ * `${VAR}` in command, args, env, cwd, url and headers is replaced from the
16
+ * gateway's environment. A missing variable is a config error.
17
+ */
18
+ import { z } from "zod";
19
+ export declare const StdioUpstreamSchema: z.ZodObject<{
20
+ command: z.ZodString;
21
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
22
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
23
+ cwd: z.ZodOptional<z.ZodString>;
24
+ }, "strict", z.ZodTypeAny, {
25
+ command: string;
26
+ args: string[];
27
+ env: Record<string, string>;
28
+ cwd?: string | undefined;
29
+ }, {
30
+ command: string;
31
+ args?: string[] | undefined;
32
+ env?: Record<string, string> | undefined;
33
+ cwd?: string | undefined;
34
+ }>;
35
+ export declare const HttpUpstreamSchema: z.ZodObject<{
36
+ url: z.ZodString;
37
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
38
+ }, "strict", z.ZodTypeAny, {
39
+ url: string;
40
+ headers: Record<string, string>;
41
+ }, {
42
+ url: string;
43
+ headers?: Record<string, string> | undefined;
44
+ }>;
45
+ export declare const UpstreamSchema: z.ZodUnion<[z.ZodObject<{
46
+ command: z.ZodString;
47
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
48
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
49
+ cwd: z.ZodOptional<z.ZodString>;
50
+ }, "strict", z.ZodTypeAny, {
51
+ command: string;
52
+ args: string[];
53
+ env: Record<string, string>;
54
+ cwd?: string | undefined;
55
+ }, {
56
+ command: string;
57
+ args?: string[] | undefined;
58
+ env?: Record<string, string> | undefined;
59
+ cwd?: string | undefined;
60
+ }>, z.ZodObject<{
61
+ url: z.ZodString;
62
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
63
+ }, "strict", z.ZodTypeAny, {
64
+ url: string;
65
+ headers: Record<string, string>;
66
+ }, {
67
+ url: string;
68
+ headers?: Record<string, string> | undefined;
69
+ }>]>;
70
+ export type StdioUpstream = z.infer<typeof StdioUpstreamSchema>;
71
+ export type HttpUpstream = z.infer<typeof HttpUpstreamSchema>;
72
+ export type Upstream = z.infer<typeof UpstreamSchema>;
73
+ export declare const GatewayConfigSchema: z.ZodObject<{
74
+ upstreams: z.ZodEffects<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
75
+ command: z.ZodString;
76
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
77
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
78
+ cwd: z.ZodOptional<z.ZodString>;
79
+ }, "strict", z.ZodTypeAny, {
80
+ command: string;
81
+ args: string[];
82
+ env: Record<string, string>;
83
+ cwd?: string | undefined;
84
+ }, {
85
+ command: string;
86
+ args?: string[] | undefined;
87
+ env?: Record<string, string> | undefined;
88
+ cwd?: string | undefined;
89
+ }>, z.ZodObject<{
90
+ url: z.ZodString;
91
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
92
+ }, "strict", z.ZodTypeAny, {
93
+ url: string;
94
+ headers: Record<string, string>;
95
+ }, {
96
+ url: string;
97
+ headers?: Record<string, string> | undefined;
98
+ }>]>>, Record<string, {
99
+ command: string;
100
+ args: string[];
101
+ env: Record<string, string>;
102
+ cwd?: string | undefined;
103
+ } | {
104
+ url: string;
105
+ headers: Record<string, string>;
106
+ }>, Record<string, {
107
+ command: string;
108
+ args?: string[] | undefined;
109
+ env?: Record<string, string> | undefined;
110
+ cwd?: string | undefined;
111
+ } | {
112
+ url: string;
113
+ headers?: Record<string, string> | undefined;
114
+ }>>, Record<string, {
115
+ command: string;
116
+ args: string[];
117
+ env: Record<string, string>;
118
+ cwd?: string | undefined;
119
+ } | {
120
+ url: string;
121
+ headers: Record<string, string>;
122
+ }>, Record<string, {
123
+ command: string;
124
+ args?: string[] | undefined;
125
+ env?: Record<string, string> | undefined;
126
+ cwd?: string | undefined;
127
+ } | {
128
+ url: string;
129
+ headers?: Record<string, string> | undefined;
130
+ }>>;
131
+ /** How to start the interceptor server. Default: the bundled adtl-interceptors with this same config file. */
132
+ interceptors: z.ZodOptional<z.ZodObject<{
133
+ command: z.ZodString;
134
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
135
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
136
+ cwd: z.ZodOptional<z.ZodString>;
137
+ }, "strict", z.ZodTypeAny, {
138
+ command: string;
139
+ args: string[];
140
+ env: Record<string, string>;
141
+ cwd?: string | undefined;
142
+ }, {
143
+ command: string;
144
+ args?: string[] | undefined;
145
+ env?: Record<string, string> | undefined;
146
+ cwd?: string | undefined;
147
+ }>>;
148
+ /** Path of a JSONL audit log. Relative paths are resolved against the config file's directory. */
149
+ audit: z.ZodOptional<z.ZodString>;
150
+ /** Timeout for each interceptor invocation, in milliseconds. */
151
+ interceptorTimeoutMs: z.ZodDefault<z.ZodNumber>;
152
+ }, "strict", z.ZodTypeAny, {
153
+ upstreams: Record<string, {
154
+ command: string;
155
+ args: string[];
156
+ env: Record<string, string>;
157
+ cwd?: string | undefined;
158
+ } | {
159
+ url: string;
160
+ headers: Record<string, string>;
161
+ }>;
162
+ interceptorTimeoutMs: number;
163
+ interceptors?: {
164
+ command: string;
165
+ args: string[];
166
+ env: Record<string, string>;
167
+ cwd?: string | undefined;
168
+ } | undefined;
169
+ audit?: string | undefined;
170
+ }, {
171
+ upstreams: Record<string, {
172
+ command: string;
173
+ args?: string[] | undefined;
174
+ env?: Record<string, string> | undefined;
175
+ cwd?: string | undefined;
176
+ } | {
177
+ url: string;
178
+ headers?: Record<string, string> | undefined;
179
+ }>;
180
+ interceptors?: {
181
+ command: string;
182
+ args?: string[] | undefined;
183
+ env?: Record<string, string> | undefined;
184
+ cwd?: string | undefined;
185
+ } | undefined;
186
+ audit?: string | undefined;
187
+ interceptorTimeoutMs?: number | undefined;
188
+ }>;
189
+ export type GatewayConfig = z.infer<typeof GatewayConfigSchema>;
190
+ export declare const TOOL_SEPARATOR = "__";
191
+ export declare class EnvExpansionError extends Error {
192
+ readonly variable: string;
193
+ constructor(variable: string, where: string);
194
+ }
195
+ /** Replace `${VAR}` with values from `env`. `$${VAR}` keeps a literal `${VAR}`. */
196
+ export declare function expandEnv(value: string, env: NodeJS.ProcessEnv, where: string): string;
197
+ export declare function expandUpstream<T extends Upstream>(id: string, u: T, env: NodeJS.ProcessEnv): T;
198
+ export declare function isHttpUpstream(u: Upstream): u is HttpUpstream;
199
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;EAOrB,CAAC;AAEZ,eAAO,MAAM,kBAAkB;;;;;;;;;EAKpB,CAAC;AAEZ,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;IAAqD,CAAC;AACjF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAQ5B,8GAA8G;;;;;;;;;;;;;;;;;IAE9G,kGAAkG;;IAElG,gEAAgE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGzD,CAAC;AACZ,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,qBAAa,iBAAkB,SAAQ,KAAK;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAIrD;AAED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAOtF;AAMD,wBAAgB,cAAc,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,CAAC,CAY9F;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,IAAI,YAAY,CAE7D"}