@adtl/gateway 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +113 -2
- package/dist/audit.d.ts +33 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +25 -0
- package/dist/audit.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +82 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +207 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +96 -0
- package/dist/config.js.map +1 -0
- package/dist/gateway.d.ts +34 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +166 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/invoker.d.ts +65 -0
- package/dist/invoker.d.ts.map +1 -0
- package/dist/invoker.js +121 -0
- package/dist/invoker.js.map +1 -0
- package/dist/startup.d.ts +23 -0
- package/dist/startup.d.ts.map +1 -0
- package/dist/startup.js +136 -0
- package/dist/startup.js.map +1 -0
- package/package.json +59 -4
- package/src/audit.ts +50 -0
- package/src/cli.ts +84 -0
- package/src/config.ts +106 -0
- package/src/gateway.ts +213 -0
- package/src/index.ts +5 -0
- package/src/invoker.ts +186 -0
- package/src/startup.ts +161 -0
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,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @adtl/gateway
|
|
2
2
|
|
|
3
|
-
|
|
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.mode` | `active` (default) or `audit`. See [Trying a policy safely](#trying-a-policy-safely). |
|
|
75
|
+
| `gateway.interceptorTimeoutMs` | Timeout per interceptor call (default 5000) |
|
|
76
|
+
| `gateway.interceptors` | Custom interceptor server command (default: the bundled `@adtl/interceptors`) |
|
|
77
|
+
|
|
78
|
+
`${VAR}` in commands, args, env, URLs and headers is read from the environment, so secrets stay out of the file.
|
|
79
|
+
|
|
80
|
+
### Trying a policy safely
|
|
81
|
+
|
|
82
|
+
Run in audit mode first to see what your policy would stop, without stopping anything:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
adtl-gateway --config adtl.yaml --audit
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
or set `gateway.mode: audit` in the file. In audit mode every call goes through and results are not changed. Labels are still tracked, so the decisions are the same as in active mode. Each line in the audit log gets `"mode": "audit"`, and a call the policy would have stopped is logged as `"outcome": "forwarded"` with `"decision": "ask"` or `"block"`, the reason and the matching rules. Once the log looks right, remove the flag.
|
|
89
|
+
|
|
90
|
+
## How it works
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
agent ──▶ adtl-gateway ──▶ upstream MCP servers
|
|
94
|
+
│
|
|
95
|
+
└─▶ adtl-interceptors (separate process, SEP-2624)
|
|
96
|
+
adtl.policy checks the call before it runs
|
|
97
|
+
adtl.label labels the result after it returns
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
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. (In audit mode such failures are logged as warnings instead.)
|
|
101
|
+
|
|
102
|
+
## Limits of this version
|
|
103
|
+
|
|
104
|
+
- Only tools are proxied. Resources and prompts are not passed through yet.
|
|
105
|
+
- `ask` blocks instead of asking. Human approvals are planned for v0.2.
|
|
106
|
+
- 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.
|
|
107
|
+
- Labels are set by your config. Servers' own trust claims can only make labels stricter, unless you set `acceptServerClaims: true`.
|
|
108
|
+
|
|
109
|
+
## Links
|
|
110
|
+
|
|
111
|
+
- Repository, demo and examples: https://github.com/probita-ai/adtl
|
|
112
|
+
- Related packages: [`@adtl/interceptors`](https://www.npmjs.com/package/@adtl/interceptors), [`@adtl/labels`](https://www.npmjs.com/package/@adtl/labels)
|
|
113
|
+
|
|
114
|
+
License: Apache-2.0
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
/** The policy's decision. In audit mode a call can be forwarded with decision "ask" or "block". */
|
|
10
|
+
decision?: string;
|
|
11
|
+
/** Present when the gateway ran in audit mode: nothing was stopped or changed. */
|
|
12
|
+
mode?: "audit";
|
|
13
|
+
reason?: string;
|
|
14
|
+
matched?: unknown;
|
|
15
|
+
callHash?: unknown;
|
|
16
|
+
label?: unknown;
|
|
17
|
+
sessionLabel?: unknown;
|
|
18
|
+
warnings?: string[];
|
|
19
|
+
durationMs: number;
|
|
20
|
+
}
|
|
21
|
+
export interface AuditSink {
|
|
22
|
+
write(entry: AuditEntry): void;
|
|
23
|
+
}
|
|
24
|
+
export declare class JsonlAuditLog implements AuditSink {
|
|
25
|
+
readonly path: string;
|
|
26
|
+
constructor(path: string);
|
|
27
|
+
write(entry: AuditEntry): void;
|
|
28
|
+
}
|
|
29
|
+
export declare class MemoryAuditLog implements AuditSink {
|
|
30
|
+
readonly entries: AuditEntry[];
|
|
31
|
+
write(entry: AuditEntry): void;
|
|
32
|
+
}
|
|
33
|
+
//# 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,mGAAmG;IACnG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,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;AA2BpC,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 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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 [--audit]
|
|
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> [--audit]
|
|
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
|
+
--audit Log what would be stopped, but stop nothing
|
|
23
|
+
(same as gateway.mode: audit).
|
|
24
|
+
-v, --version Print the version and exit.
|
|
25
|
+
-h, --help Show this help.`;
|
|
26
|
+
function parseArgs(argv) {
|
|
27
|
+
const out = {};
|
|
28
|
+
for (let i = 0; i < argv.length; i++) {
|
|
29
|
+
const a = argv[i];
|
|
30
|
+
if (a === "-h" || a === "--help")
|
|
31
|
+
out.help = true;
|
|
32
|
+
else if (a === "-v" || a === "--version")
|
|
33
|
+
out.version = true;
|
|
34
|
+
else if (a === "-c" || a === "--config")
|
|
35
|
+
out.config = argv[++i];
|
|
36
|
+
else if (a?.startsWith("--config="))
|
|
37
|
+
out.config = a.slice("--config=".length);
|
|
38
|
+
else if (a === "--audit")
|
|
39
|
+
out.audit = true;
|
|
40
|
+
else
|
|
41
|
+
throw new GatewayConfigError(`Unknown argument: ${a}\n\n${USAGE}`);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
async function main() {
|
|
46
|
+
const args = parseArgs(process.argv.slice(2));
|
|
47
|
+
// --help and --version print to stdout and exit; MCP is never served in these modes.
|
|
48
|
+
if (args.help)
|
|
49
|
+
return void console.log(USAGE);
|
|
50
|
+
if (args.version)
|
|
51
|
+
return void console.log(GATEWAY_VERSION);
|
|
52
|
+
if (!args.config)
|
|
53
|
+
throw new GatewayConfigError(`Missing --config\n\n${USAGE}`);
|
|
54
|
+
const loaded = await loadGatewayConfig(args.config);
|
|
55
|
+
if (args.audit)
|
|
56
|
+
loaded.gateway.mode = "audit";
|
|
57
|
+
const started = await startGateway(loaded);
|
|
58
|
+
const server = started.gateway.createServer();
|
|
59
|
+
let closing = false;
|
|
60
|
+
const shutdown = async () => {
|
|
61
|
+
if (closing)
|
|
62
|
+
return;
|
|
63
|
+
closing = true;
|
|
64
|
+
await server.close().catch(() => undefined);
|
|
65
|
+
await started.close();
|
|
66
|
+
process.exit(0);
|
|
67
|
+
};
|
|
68
|
+
server.onclose = () => void shutdown();
|
|
69
|
+
// The agent closing our stdin means the session is over; don't wait for a signal.
|
|
70
|
+
process.stdin.on("end", () => void shutdown());
|
|
71
|
+
process.stdin.on("close", () => void shutdown());
|
|
72
|
+
process.on("SIGINT", () => void shutdown());
|
|
73
|
+
process.on("SIGTERM", () => void shutdown());
|
|
74
|
+
await server.connect(new StdioServerTransport());
|
|
75
|
+
console.error(`[adtl-gateway] ${GATEWAY_VERSION} ready (session ${started.gateway.sessionId})`);
|
|
76
|
+
}
|
|
77
|
+
main().catch((err) => {
|
|
78
|
+
const known = err instanceof GatewayConfigError || err instanceof EnvExpansionError;
|
|
79
|
+
console.error(known ? `[adtl-gateway] ${err.message}` : err);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEnF,MAAM,KAAK,GAAG;;;;;;;;;;uCAUyB,CAAC;AASxC,SAAS,SAAS,CAAC,IAAc;IAC/B,MAAM,GAAG,GAAS,EAAE,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,QAAQ;YAAE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;aAC7C,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,WAAW;YAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;aACxD,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,UAAU;YAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aAC3D,IAAI,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC;YAAE,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;aACzE,IAAI,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