baton-proxy 0.2.0__tar.gz → 0.2.2__tar.gz

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 (50) hide show
  1. baton_proxy-0.2.2/CHANGELOG.md +73 -0
  2. baton_proxy-0.2.2/PKG-INFO +412 -0
  3. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/pyproject.toml +1 -1
  4. baton_proxy-0.2.2/src/baton_proxy/__init__.py +13 -0
  5. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/src/baton_proxy/emitter.py +179 -2
  6. baton_proxy-0.2.2/src/baton_proxy/proxy.py +1075 -0
  7. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/src/baton_proxy/report.py +50 -14
  8. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/src/baton_proxy/scan.py +25 -15
  9. baton_proxy-0.2.2/src/baton_proxy/transport_http.py +287 -0
  10. baton_proxy-0.2.2/tests/fixture_http_server.py +222 -0
  11. baton_proxy-0.2.2/tests/fixture_responses.py +166 -0
  12. baton_proxy-0.2.2/tests/fixture_server.py +39 -0
  13. baton_proxy-0.2.2/tests/test_a1_emit_e2e.py +326 -0
  14. baton_proxy-0.2.2/tests/test_a1_proxy.py +254 -0
  15. baton_proxy-0.2.2/tests/test_http_bridge.py +629 -0
  16. baton_proxy-0.2.2/tests/test_pending_eviction.py +152 -0
  17. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_report.py +76 -0
  18. baton_proxy-0.2.0/CHANGELOG.md +0 -44
  19. baton_proxy-0.2.0/PKG-INFO +0 -213
  20. baton_proxy-0.2.0/src/baton_proxy/__init__.py +0 -9
  21. baton_proxy-0.2.0/src/baton_proxy/proxy.py +0 -571
  22. baton_proxy-0.2.0/src/baton_proxy/scan_tasks.py +0 -53
  23. baton_proxy-0.2.0/tests/fixture_server.py +0 -115
  24. baton_proxy-0.2.0/tests/test_pending_eviction.py +0 -70
  25. baton_proxy-0.2.0/tests/test_scan_tasks.py +0 -27
  26. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/.github/workflows/release.yml +0 -0
  27. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/.github/workflows/test.yml +0 -0
  28. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/.gitignore +0 -0
  29. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/LICENSE +0 -0
  30. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/Makefile +0 -0
  31. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/README.md +0 -0
  32. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/examples/live-claude-invocation/instructions.md +0 -0
  33. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/examples/live-claude-invocation/result.md +0 -0
  34. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/examples/live-claude-invocation/setup.sh +0 -0
  35. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/examples/live-claude-invocation/unregister.sh +0 -0
  36. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/src/baton_proxy/__main__.py +0 -0
  37. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/src/baton_proxy/_llm_text.py +0 -0
  38. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/src/baton_proxy/config.py +0 -0
  39. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/src/baton_proxy/scrub.py +0 -0
  40. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/src/baton_proxy/sinks.py +0 -0
  41. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/__init__.py +0 -0
  42. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_config.py +0 -0
  43. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_emitter.py +0 -0
  44. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_injection.py +0 -0
  45. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_llm_text.py +0 -0
  46. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_proxy_env.py +0 -0
  47. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_scan.py +0 -0
  48. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_scrub.py +0 -0
  49. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/tests/test_sinks.py +0 -0
  50. {baton_proxy-0.2.0 → baton_proxy-0.2.2}/uv.lock +0 -0
@@ -0,0 +1,73 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.2.2] — 2026-07-04
11
+
12
+ ### Added
13
+ - **HTTPS bridge** (`baton-proxy --url <url>`): wrap a remote Streamable HTTP MCP server (spec 2025-03-26), not just a local stdio subprocess. The proxy stays stdio-facing to the client and forwards each message as an HTTP POST, streaming the JSON or SSE response back. Bearer auth via `BATON_UPSTREAM_AUTH_TOKEN`; read timeout via `BATON_UPSTREAM_TIMEOUT` (default 60s); captures and echoes `Mcp-Session-Id` and pins `MCP-Protocol-Version` after the handshake; sends a named `User-Agent` + `Via` header (urllib's default UA is Cloudflare-banned on many hosted endpoints). Stdlib only — no new dependencies.
14
+ - **Resource & prompt capture (A1)**: the proxy now emits lifecycle events for `resources/read`, `resources/list`, `prompts/get`, and `prompts/list`, alongside the existing `tools/call` capture.
15
+
16
+ ### Fixed
17
+ - HTTP bridge fail-open: a 2xx upstream reply that answers nothing (empty body, `202`, or an SSE stream with no matching frame) no longer leaves the client blocked on that request; a malformed or non-object client message no longer crashes the bridge. Both now emit a synthetic error event and hand the client a JSON-RPC error rather than hanging.
18
+ - SSE responses: only `event: message` frames are parsed as JSON-RPC — a server interleaving a keepalive/ping/custom event with a data payload no longer injects a bogus message to the client.
19
+ - stdio: the two pump threads are serialized on stdout, so a synthesized `baton_annotate` response can no longer interleave with a real upstream response and corrupt the wire.
20
+ - `BATON_UPSTREAM_TIMEOUT=inf`/`nan` falls back to the default instead of silently disabling the read timeout.
21
+ - Calls still in flight at shutdown are resolved with a synthetic error, so a mid-call upstream exit no longer leaves a dangling `*_start` with no end/error.
22
+
23
+ ### Packaging
24
+ - `pyproject.toml` references the `LICENSE` file instead of inline SPDX text.
25
+
26
+ ## [0.2.1] — 2026-06-23
27
+
28
+ ### Changed
29
+ - `baton-proxy scan` now drives the agent to record each friction through `baton_annotate` (intent + `signal_type` + `suggested_improvement`) the moment it hits it, instead of only summarizing at the end. Scan reports are synthesized from captured annotation events, so mechanical-only error findings that used to render thin (generic intent, no fix) now carry the agent's restated intent and a concrete suggested fix. (A live `scan --config github` went from 1 thin finding to 7 with verbatim fixes.)
30
+
31
+ ### Fixed
32
+ - `synthesize_scan` now folds a model-filed reactive into the mechanical error finding for the same tool even when the reactive names that tool only in its text (not a structured `tool` field), matching only when exactly one errored tool name appears. Previously a tool that both errored and got annotated could surface as two near-duplicate findings, inflating the headline friction count.
33
+
34
+ ### Removed
35
+ - Pinned per-server task plans (`scan_tasks.py`). They existed only to make the cold-visitor homepage-demo finding reproducible; the config-only scan flow retired that demo path, leaving no consumer. Every scan now uses the adversarial generic driver plan.
36
+
37
+ ## [0.2.0] — 2026-06-23
38
+
39
+ ### Added
40
+ - `baton-proxy scan --config <name>`: one-command preflight friction report. Resolves an MCP server you've already configured in Claude (from `./.mcp.json` or `~/.claude.json`, reusing its saved credentials), wraps it, drives a headless `claude` agent through it, and renders a local `baton-report.md` from captured events — no permanent install or Claude-config change. The report anchors on mechanical tool errors plus model-flagged friction signals, and is labeled preflight/inferred. Warns when `ANTHROPIC_API_KEY` is set (it bills the API account over a Claude login session).
41
+
42
+ ## [0.1.2] — 2026-06-12
43
+
44
+ ### Fixed
45
+ - `sdk_version` field in emitted events was hardcoded to `"baton-proxy/0.0.1"` and never picked up version bumps. Now derived from `baton_proxy.__version__` at module load. Caught while dogfooding the 0.1.1 install — events from a `pipx`-installed proxy were reporting the stale version.
46
+
47
+ ## [0.1.1] — 2026-06-12
48
+
49
+ Docs-only release to refresh the PyPI project description. No code changes.
50
+
51
+ ### Changed
52
+ - README diagram now shows the full sink fan-out (`stderr:` / `file://` / Baton Console) instead of just the Console.
53
+ - Intro broadens "emits to a Baton Console" to "emits to one or more sinks", matching what `BATON_EVENT_SINK` actually accepts.
54
+ - New "Related" section links [`baton-sdk`](https://github.com/good-timing/baton) (the in-process integration alternative) and the [Baton wire-protocol spec](https://github.com/good-timing/baton/blob/main/docs/SPEC.md).
55
+ - Quick-start install line gains a one-line rationale for `pipx` vs `pip`.
56
+
57
+ ## [0.1.0] — 2026-06-12
58
+
59
+ Initial public release on PyPI.
60
+
61
+ ### Added
62
+ - Subprocess-wrap MCP proxy: wraps a stdio MCP server, intercepts the handshake, injects friction-capture tools into the upstream server's `tools/list`.
63
+ - `baton_annotate` tool: lets Claude emit a per-call annotation event when it hits friction (unprompted).
64
+ - `baton_session_report` tool: returns a vendor-shareable markdown report of the session's friction (errors, slow calls, annotations). Local-sink installs only.
65
+ - Friction event emission per real tool call (`tool_call_start` / `tool_call_end` / `tool_call_error`) carrying session id, monotonic sequence, and the upstream MCP request's `_meta` block.
66
+ - Multi-sink fan-out via `BATON_EVENT_SINK`: `stderr:`, `file://`, and `http(s)://` schemes, comma-separated. Zero-config default writes to `stderr:` + `file:///tmp/baton-proxy.jsonl`.
67
+ - Consent guard: refuses to start when an `http(s)://` sink is paired with the placeholder `BATON_CONSENT_TOKEN=local`, or when an `http(s)://` sink is configured without `BATON_API_KEY`.
68
+ - Fail-open delivery: emission runs on a background thread; Console outage never blocks the MCP pipe.
69
+
70
+ [Unreleased]: https://github.com/good-timing/baton-proxy/compare/v0.1.2...HEAD
71
+ [0.1.2]: https://github.com/good-timing/baton-proxy/compare/v0.1.1...v0.1.2
72
+ [0.1.1]: https://github.com/good-timing/baton-proxy/compare/v0.1.0...v0.1.1
73
+ [0.1.0]: https://github.com/good-timing/baton-proxy/releases/tag/v0.1.0
@@ -0,0 +1,412 @@
1
+ Metadata-Version: 2.4
2
+ Name: baton-proxy
3
+ Version: 0.2.2
4
+ Summary: Subprocess-wrap MCP proxy that injects an annotation tool and emits friction events.
5
+ Author: Good Timing, Inc.
6
+ License: Apache License
7
+ Version 2.0, January 2004
8
+ http://www.apache.org/licenses/
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+ 1. Definitions.
13
+
14
+ "License" shall mean the terms and conditions for use, reproduction,
15
+ and distribution as defined by Sections 1 through 9 of this document.
16
+
17
+ "Licensor" shall mean the copyright owner or entity authorized by
18
+ the copyright owner that is granting the License.
19
+
20
+ "Legal Entity" shall mean the union of the acting entity and all
21
+ other entities that control, are controlled by, or are under common
22
+ control with that entity. For the purposes of this definition,
23
+ "control" means (i) the power, direct or indirect, to cause the
24
+ direction or management of such entity, whether by contract or
25
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or (iii) beneficial ownership of such entity.
27
+
28
+ "You" (or "Your") shall mean an individual or Legal Entity
29
+ exercising permissions granted by this License.
30
+
31
+ "Source" form shall mean the preferred form for making modifications,
32
+ including but not limited to software source code, documentation
33
+ source, and configuration files.
34
+
35
+ "Object" form shall mean any form resulting from mechanical
36
+ transformation or translation of a Source form, including but
37
+ not limited to compiled object code, generated documentation,
38
+ and conversions to other media types.
39
+
40
+ "Work" shall mean the work of authorship, whether in Source or
41
+ Object form, made available under the License, as indicated by a
42
+ copyright notice that is included in or attached to the work
43
+ (an example is provided in the Appendix below).
44
+
45
+ "Derivative Works" shall mean any work, whether in Source or Object
46
+ form, that is based on (or derived from) the Work and for which the
47
+ editorial revisions, annotations, elaborations, or other modifications
48
+ represent, as a whole, an original work of authorship. For the purposes
49
+ of this License, Derivative Works shall not include works that remain
50
+ separable from, or merely link (or bind by name) to the interfaces of,
51
+ the Work and Derivative Works thereof.
52
+
53
+ "Contribution" shall mean any work of authorship, including
54
+ the original version of the Work and any modifications or additions
55
+ to that Work or Derivative Works thereof, that is intentionally
56
+ submitted to Licensor for inclusion in the Work by the copyright owner
57
+ or by an individual or Legal Entity authorized to submit on behalf of
58
+ the copyright owner. For the purposes of this definition, "submitted"
59
+ means any form of electronic, verbal, or written communication sent
60
+ to the Licensor or its representatives, including but not limited to
61
+ communication on electronic mailing lists, source code control systems,
62
+ and issue tracking systems that are managed by, or on behalf of, the
63
+ Licensor for the purpose of discussing and improving the Work, but
64
+ excluding communication that is conspicuously marked or otherwise
65
+ designated in writing by the copyright owner as "Not a Contribution."
66
+
67
+ "Contributor" shall mean Licensor and any individual or Legal Entity
68
+ on behalf of whom a Contribution has been received by Licensor and
69
+ subsequently incorporated within the Work.
70
+
71
+ 2. Grant of Copyright License. Subject to the terms and conditions of
72
+ this License, each Contributor hereby grants to You a perpetual,
73
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
74
+ copyright license to reproduce, prepare Derivative Works of,
75
+ publicly display, publicly perform, sublicense, and distribute the
76
+ Work and such Derivative Works in Source or Object form.
77
+
78
+ 3. Grant of Patent License. Subject to the terms and conditions of
79
+ this License, each Contributor hereby grants to You a perpetual,
80
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
81
+ (except as stated in this section) patent license to make, have made,
82
+ use, offer to sell, sell, import, and otherwise transfer the Work,
83
+ where such license applies only to those patent claims licensable
84
+ by such Contributor that are necessarily infringed by their
85
+ Contribution(s) alone or by combination of their Contribution(s)
86
+ with the Work to which such Contribution(s) was submitted. If You
87
+ institute patent litigation against any entity (including a
88
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
89
+ or a Contribution incorporated within the Work constitutes direct
90
+ or contributory patent infringement, then any patent licenses
91
+ granted to You under this License for that Work shall terminate
92
+ as of the date such litigation is filed.
93
+
94
+ 4. Redistribution. You may reproduce and distribute copies of the
95
+ Work or Derivative Works thereof in any medium, with or without
96
+ modifications, and in Source or Object form, provided that You
97
+ meet the following conditions:
98
+
99
+ (a) You must give any other recipients of the Work or
100
+ Derivative Works a copy of this License; and
101
+
102
+ (b) You must cause any modified files to carry prominent notices
103
+ stating that You changed the files; and
104
+
105
+ (c) You must retain, in the Source form of any Derivative Works
106
+ that You distribute, all copyright, patent, trademark, and
107
+ attribution notices from the Source form of the Work,
108
+ excluding those notices that do not pertain to any part of
109
+ the Derivative Works; and
110
+
111
+ (d) If the Work includes a "NOTICE" text file as part of its
112
+ distribution, then any Derivative Works that You distribute must
113
+ include a readable copy of the attribution notices contained
114
+ within such NOTICE file, excluding those notices that do not
115
+ pertain to any part of the Derivative Works, in at least one
116
+ of the following places: within a NOTICE text file distributed
117
+ as part of the Derivative Works; within the Source form or
118
+ documentation, if provided along with the Derivative Works; or,
119
+ within a display generated by the Derivative Works, if and
120
+ wherever such third-party notices normally appear. The contents
121
+ of the NOTICE file are for informational purposes only and
122
+ do not modify the License. You may add Your own attribution
123
+ notices within Derivative Works that You distribute, alongside
124
+ or as an addendum to the NOTICE text from the Work, provided
125
+ that such additional attribution notices cannot be construed
126
+ as modifying the License.
127
+
128
+ You may add Your own copyright statement to Your modifications and
129
+ may provide additional or different license terms and conditions
130
+ for use, reproduction, or distribution of Your modifications, or
131
+ for any such Derivative Works as a whole, provided Your use,
132
+ reproduction, and distribution of the Work otherwise complies with
133
+ the conditions stated in this License.
134
+
135
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
136
+ any Contribution intentionally submitted for inclusion in the Work
137
+ by You to the Licensor shall be under the terms and conditions of
138
+ this License, without any additional terms or conditions.
139
+ Notwithstanding the above, nothing herein shall supersede or modify
140
+ the terms of any separate license agreement you may have executed
141
+ with Licensor regarding such Contributions.
142
+
143
+ 6. Trademarks. This License does not grant permission to use the trade
144
+ names, trademarks, service marks, or product names of the Licensor,
145
+ except as required for describing the origin of the Work and
146
+ reproducing the content of the NOTICE file.
147
+
148
+ 7. Disclaimer of Warranty. Unless required by applicable law or
149
+ agreed to in writing, Licensor provides the Work (and each
150
+ Contributor provides its Contributions) on an "AS IS" BASIS,
151
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
152
+ implied, including, without limitation, any warranties or conditions
153
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
154
+ PARTICULAR PURPOSE. You are solely responsible for determining the
155
+ appropriateness of using or redistributing the Work and assume any
156
+ risks associated with Your exercise of permissions under this License.
157
+
158
+ 8. Limitation of Liability. In no event and under no legal theory,
159
+ whether in tort (including negligence), contract, or otherwise,
160
+ unless required by applicable law (such as deliberate and grossly
161
+ negligent acts) or agreed to in writing, shall any Contributor be
162
+ liable to You for damages, including any direct, indirect, special,
163
+ incidental, or consequential damages of any character arising as a
164
+ result of this License or out of the use or inability to use the
165
+ Work (including but not limited to damages for loss of goodwill,
166
+ work stoppage, computer failure or malfunction, or any and all
167
+ other commercial damages or losses), even if such Contributor
168
+ has been advised of the possibility of such damages.
169
+
170
+ 9. Accepting Warranty or Support. While redistributing the Work or
171
+ Derivative Works thereof, You may accept support, warranty, indemnity,
172
+ or other liability obligations and/or rights consistent with this
173
+ License. However, in accepting such obligations, You may act only
174
+ on Your own behalf and on Your sole responsibility, not on behalf
175
+ of any other Contributor, and only if You agree to indemnify,
176
+ defend, and hold each Contributor harmless for any liability
177
+ incurred by, or claims asserted against, such Contributor by reason
178
+ of your accepting any such warranty or support.
179
+
180
+ END OF TERMS AND CONDITIONS
181
+
182
+ APPENDIX: How to apply the Apache License to your work.
183
+
184
+ To apply the Apache License to your work, attach the following
185
+ boilerplate notice, with the fields enclosed by brackets "[]"
186
+ replaced with your own identifying information. (Don't include
187
+ the brackets!) The text should be enclosed in the appropriate
188
+ comment syntax for the file format. We also recommend that a
189
+ file or class name and description of purpose be included on the
190
+ same "printed page" as the copyright notice for easier
191
+ identification within third-party archives.
192
+
193
+ Copyright 2026 Good Timing, Inc.
194
+
195
+ Licensed under the Apache License, Version 2.0 (the "License");
196
+ you may not use this file except in compliance with the License.
197
+ You may obtain a copy of the License at
198
+
199
+ http://www.apache.org/licenses/LICENSE-2.0
200
+
201
+ Unless required by applicable law or agreed to in writing, software
202
+ distributed under the License is distributed on an "AS IS" BASIS,
203
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
204
+ implied. See the License for the specific language governing
205
+ permissions and limitations under the License.
206
+ License-File: LICENSE
207
+ Classifier: License :: OSI Approved :: Apache Software License
208
+ Classifier: Programming Language :: Python :: 3
209
+ Classifier: Programming Language :: Python :: 3.11
210
+ Classifier: Programming Language :: Python :: 3.12
211
+ Classifier: Programming Language :: Python :: 3.13
212
+ Classifier: Programming Language :: Python :: 3.14
213
+ Requires-Python: >=3.11
214
+ Provides-Extra: dev
215
+ Requires-Dist: pytest>=7.0; extra == 'dev'
216
+ Requires-Dist: ruff>=0.4; extra == 'dev'
217
+ Description-Content-Type: text/markdown
218
+
219
+ # baton-proxy
220
+
221
+ Subprocess-wrap MCP proxy. Wraps a stdio MCP server, injects an annotation tool into the handshake, and emits friction events to one or more sinks (stderr, a JSONL file, or a Baton Console).
222
+
223
+ Zero changes to the underlying MCP server. The proxy *is* the MCP server from Claude's perspective; the real server is its child process.
224
+
225
+ ```
226
+ ┌──────────┐ ┌───────────────┐ ┌────────────────────┐
227
+ │ Claude │ ◀──▶ │ baton-proxy │ ◀──▶ │ your MCP server │
228
+ └──────────┘ └───────┬───────┘ └────────────────────┘
229
+ │
230
+ │ async fan-out — pick any subset
231
+ ▼
232
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
233
+ │ stderr: │ │ file:// │ │ Baton Console │
234
+ │ JSONL stream │ │ JSONL file │ │ (HTTPS POST) │
235
+ └─────────────────┘ └─────────────────┘ └─────────────────┘
236
+ ```
237
+
238
+ ## Quick start
239
+
240
+ ```bash
241
+ pipx install baton-proxy # or: pip install baton-proxy
242
+ ```
243
+
244
+ `pipx` installs the CLI into its own isolated venv and puts `baton-proxy` on your PATH — so Claude's config can invoke it directly without env activation. Plain `pip install` works if you already manage your own Python env.
245
+
246
+ Replace your MCP server entry in Claude's config:
247
+
248
+ ```jsonc
249
+ // Before
250
+ { "command": "npx", "args": ["@vendor/mcp-server"] }
251
+
252
+ // After — zero-config: events go to stderr + /tmp/baton-proxy.jsonl
253
+ { "command": "baton-proxy", "args": ["--", "npx", "@vendor/mcp-server"] }
254
+ ```
255
+
256
+ That's the entire install. Restart Claude, drive the wrapped server, then either:
257
+
258
+ - Ask Claude **"show me the friction report for this session"** — the proxy injects a `baton_session_report` tool that returns a vendor-shareable markdown report directly in the conversation, or
259
+ - `cat /tmp/baton-proxy.jsonl` to see the raw friction events.
260
+
261
+ No env vars, no backend, no credentials. The report is a preview of the ticket shape a Baton-instrumented vendor sees in their Console.
262
+
263
+ To ship events to a Console instead (or in addition), add four env vars:
264
+
265
+ ```jsonc
266
+ {
267
+ "command": "baton-proxy",
268
+ "args": ["--", "npx", "@vendor/mcp-server"],
269
+ "env": {
270
+ "BATON_EVENT_SINK": "https://console.example.com",
271
+ "BATON_TENANT_ID": "your-tenant",
272
+ "BATON_API_KEY": "...",
273
+ "BATON_CONSENT_TOKEN": "..."
274
+ }
275
+ }
276
+ ```
277
+
278
+ The proxy adds two tools to the upstream server's tool list:
279
+ - `baton_annotate` — Claude calls it (unprompted) when it hits friction; emits an annotation event.
280
+ - `baton_session_report` — Claude calls it (when the customer asks for a report); returns a vendor-shareable markdown summary of the session's friction. **Only injected in local-sink installs** — vendors using an `http(s)://` sink (production mode) get a clean tool list; the vendor's Console renders tickets there instead.
281
+
282
+ And the proxy emits a friction event per real tool call.
283
+
284
+ ## Try it in one command: `scan`
285
+
286
+ Preview the friction an agent is likely to hit on a server you run — no permanent install, no change to your Claude config:
287
+
288
+ ```bash
289
+ uvx baton-proxy scan --config github
290
+ ```
291
+
292
+ `scan` targets a server you've **already configured in Claude** (by name), reusing that entry's saved credentials. It writes an ephemeral config, drives a headless agent (`claude -p`, billed to your own auth) through the wrapped server, and renders `./baton-report.md`. Everything runs locally — nothing leaves your machine, and you type no secrets. The report is labeled **preflight/inferred**: it previews likely friction, it's not real-user data (that's what the permanent wrap above captures).
293
+
294
+ Why `--config` (and not a raw server command)? A friction report only delivers its insight on a server you actually run — its real tools, its real auth, your real workflows. So scan resolves a configured entry rather than scanning a stranger's server. It reads `--config <name>` from `~/.claude.json` or `./.mcp.json`; point at a specific file with `--config-file`:
295
+
296
+ ```bash
297
+ uvx baton-proxy scan --config github --config-file ./.mcp.json
298
+ ```
299
+
300
+ Details:
301
+ - The resolved entry's credentials (its `env`, including `${VAR}` references) flow to the wrapped server untouched.
302
+ - An entry that's already `baton-proxy`-wrapped is unwrapped automatically, and its `BATON_*` vars are dropped so the scan session stays local rather than shipping to your real Console.
303
+ - Remote/OAuth (`http`/`sse`) entries aren't supported yet — scan wraps stdio servers.
304
+ - `--timeout` bounds the run (default 300s; a partial report renders on expiry). `--out` sets the report path.
305
+
306
+ ## What gets emitted
307
+
308
+ Per real tool call, three event types match the [Baton wire format](https://github.com/good-timing/baton/blob/main/docs/SPEC.md) (`tool_call_start` / `tool_call_end` / `tool_call_error`):
309
+
310
+ | Event | Payload |
311
+ |---|---|
312
+ | `tool_call_start` | `{tool_name, params}` |
313
+ | `tool_call_end` | `{tool_name, result, duration_ms}` |
314
+ | `tool_call_error` | `{tool_name, error_type, error_body, duration_ms}` |
315
+
316
+ Each event carries a session id (one per proxy process), monotonic sequence number, and the upstream MCP request's `_meta` block (for cycle correlation).
317
+
318
+ The injected `baton_annotate` tool itself is handled by the proxy; the upstream server never sees it.
319
+
320
+ ## Configuration
321
+
322
+ All knobs are environment variables. Every emission-related one has a default; the zero-config install (no env vars) writes events to stderr + `/tmp/baton-proxy.jsonl`.
323
+
324
+ | Variable | Default | Purpose |
325
+ |---|---|---|
326
+ | `BATON_EVENT_SINK` | `stderr:,file:///tmp/baton-proxy.jsonl` | Where events go. URL scheme picks the sink: `https://console.example.com` POSTs to `{url}/v0/events`, `file:///tmp/events.jsonl` appends a JSON line per event, `stderr:` writes JSONL to stderr. Comma-separated values fan out to all of them. |
327
+ | `BATON_TENANT_ID` | `local` | Tenant identifier. Placeholder; replace when shipping to a Console. |
328
+ | `BATON_CONSENT_TOKEN` | `local` | Per-process consent token. **Placeholder; you MUST replace this before pointing at an `http(s)://` sink** — the proxy refuses to start in that combination, so accidental remote leakage of placeholder-tagged events doesn't happen. |
329
+ | `BATON_API_KEY` | _(unset)_ | Bearer token. Required only when the sink scheme is `http(s)://`; `file://` and `stderr:` sinks ignore it. |
330
+ | `BATON_VENDOR_ID` | _(unset)_ | Labels the install for the operator (useful for multi-vendor customers grepping their JSONL). Does NOT prefix the injected tool name — that stays `baton_annotate` in v1. Vendors who need a white-labelled tool name will get an opt-in switch when they ask. |
331
+ | `BATON_PROXY_LOG_FILE`| _(unset)_ | Path to tee proxy logs to (default: stderr only). |
332
+
333
+ ### The three rungs
334
+
335
+ Pick the rung you need; the env-var deltas are the entire difference.
336
+
337
+ | Rung | Sink | env additions |
338
+ |---|---|---|
339
+ | **1. Default (install-and-play)** | stderr + `/tmp/baton-proxy.jsonl` | _(none)_ |
340
+ | **2. Custom local capture** | wherever you want | `BATON_EVENT_SINK=file:///path/to/your.jsonl` |
341
+ | **3. Ship to a Console** | hosted | `BATON_EVENT_SINK=https://console.example.com` + `BATON_API_KEY=...` + `BATON_TENANT_ID=your-tenant` + `BATON_CONSENT_TOKEN=real-token` |
342
+
343
+ ### See it locally
344
+
345
+ After installing (`{ "command": "baton-proxy", "args": ["--", "npx", "@vendor/mcp-server"] }` in your Claude config) and restarting Claude, drive a few tool calls and try either:
346
+
347
+ **Conversational** — ask Claude:
348
+ > Show me the friction report for this session.
349
+
350
+ Claude calls the injected `baton_session_report` tool; the proxy returns a markdown report (per-tool breakdown, errored calls with input/error detail, any annotations the model emitted) that Claude relays directly in the conversation.
351
+
352
+ **Raw** — inspect the JSONL stream:
353
+
354
+ ```sh
355
+ cat /tmp/baton-proxy.jsonl | jq -c '{type: .event_type, payload}'
356
+ ```
357
+
358
+ See `examples/live-claude-invocation/` for a guided walk-through that also covers the elicitation behaviour of the injected `baton_annotate` tool.
359
+
360
+ ### Sink misconfig fails loudly
361
+
362
+ The proxy refuses to start when:
363
+ - an `http(s)://` sink is configured but `BATON_API_KEY` is unset
364
+ - an `http(s)://` sink is configured but `BATON_CONSENT_TOKEN` is still the placeholder `"local"`
365
+ - the sink URL has an unsupported scheme
366
+
367
+ These are emitted as proxy startup errors so a misconfigured install never silently drops or silently mistags events.
368
+
369
+ ## Trust properties
370
+
371
+ - **Open source, Apache 2.0.** Auditable end-to-end.
372
+ - **Fail-open.** Console outage, network issue, or instrumentation bug never breaks the MCP pipe. Tested by `tests/test_emitter.py::test_stop_is_clean_when_console_dead` and `tests/test_injection.py`.
373
+ - **Outbound-only.** The proxy never accepts inbound connections. Events go to the configured sink (HTTP POST out for `https://` sinks, local file write for `file://` sinks); that's the only egress surface.
374
+ - **No deps.** Pure stdlib. No pydantic, no httpx, no third-party runtime requirements.
375
+ - **Emission off the hot path.** Event emission is enqueued onto a background thread; the proxy I/O pump does not wait for the POST. End-to-end overhead measurement pending.
376
+
377
+ **Trust model.** baton-proxy and the wrapped MCP server run in the same trust domain (same user, vendor's own MCP server). The proxy filters `BATON_*` from the upstream subprocess env as a least-privilege measure — the upstream has no need for Baton credentials, and accidental leakage paths (debug logging, crash-report env dumps, future plugins) shouldn't see them. This is not a cross-process trust boundary; don't use baton-proxy to instrument an MCP server you don't trust — that's not the threat model the proxy is designed for.
378
+
379
+ ## How it works
380
+
381
+ Two unidirectional pumps:
382
+
383
+ - **client → server**: forwards stdin lines to the child process. Intercepts `tools/call` for `baton_annotate` (proxy synthesises the response). For every other `tools/call`, enqueues a `tool_call_start` event and records the request id.
384
+ - **server → client**: forwards child stdout to the client. Modifies the `initialize` response to append annotation-tool instructions; modifies the `tools/list` response to append the `baton_annotate` tool. Correlates responses by id to emit `tool_call_end` / `tool_call_error`.
385
+
386
+ A third background thread drains an in-memory queue and delivers events one at a time to the configured sink (HTTP POST for `https://`, JSONL append for `file://`). Failed deliveries are logged and dropped — the proxy never retries on the hot path.
387
+
388
+ ## Development
389
+
390
+ ```bash
391
+ git clone https://github.com/good-timing/baton-proxy
392
+ cd baton-proxy
393
+ python3 -m venv .venv && source .venv/bin/activate
394
+ pip install -e ".[dev]"
395
+ pytest
396
+ ```
397
+
398
+ ## Related
399
+
400
+ - **[baton-sdk](https://github.com/good-timing/baton)** — the in-process alternative. Vendors who control their MCP server add `install_baton(mcp, ...)` instead of subprocess-wrapping. Same wire format, same sinks; tighter integration with one line of vendor code.
401
+ - **[Baton wire protocol](https://github.com/good-timing/baton/blob/main/docs/SPEC.md)** — the event envelope, signal taxonomy, and HTTPS contract that both `baton-proxy` and `baton-sdk` emit against.
402
+
403
+ ## Roadmap
404
+
405
+ - PII scrubbing for `params` and `result` payloads (currently passed verbatim).
406
+ - Static-linked single-binary distribution (PyInstaller, then likely a Go rewrite once distribution shape is set).
407
+ - Helm chart for hosted-HTTP MCP servers.
408
+ - Hosted-evaluation mode (per-request consent tokens).
409
+
410
+ ## License
411
+
412
+ Apache 2.0. See [LICENSE](LICENSE).
@@ -7,7 +7,7 @@ name = "baton-proxy"
7
7
  dynamic = ["version"]
8
8
  description = "Subprocess-wrap MCP proxy that injects an annotation tool and emits friction events."
9
9
  readme = "README.md"
10
- license = { text = "Apache-2.0" }
10
+ license = { file = "LICENSE" }
11
11
  requires-python = ">=3.11"
12
12
  authors = [{ name = "Good Timing, Inc." }]
13
13
  classifiers = [
@@ -0,0 +1,13 @@
1
+ """baton-proxy — subprocess-wrap MCP proxy.
2
+
3
+ Wraps a stdio MCP server, injects an annotation tool into the handshake,
4
+ and emits friction events to a baton-console.
5
+
6
+ See README.md for usage.
7
+ """
8
+
9
+ __version__ = "0.2.2"
10
+
11
+ # The product/version token, single-sourced here so the emitter's `sdk_version`
12
+ # field and the HTTP bridge's outbound `User-Agent` header can never drift.
13
+ USER_AGENT = f"baton-proxy/{__version__}"