baton-proxy 0.1.0__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.
- baton_proxy-0.1.0/.github/workflows/release.yml +56 -0
- baton_proxy-0.1.0/.github/workflows/test.yml +26 -0
- baton_proxy-0.1.0/.gitignore +12 -0
- baton_proxy-0.1.0/CHANGELOG.md +24 -0
- baton_proxy-0.1.0/LICENSE +200 -0
- baton_proxy-0.1.0/PKG-INFO +182 -0
- baton_proxy-0.1.0/README.md +163 -0
- baton_proxy-0.1.0/examples/live-claude-invocation/instructions.md +124 -0
- baton_proxy-0.1.0/examples/live-claude-invocation/result.md +62 -0
- baton_proxy-0.1.0/examples/live-claude-invocation/setup.sh +69 -0
- baton_proxy-0.1.0/examples/live-claude-invocation/unregister.sh +8 -0
- baton_proxy-0.1.0/pyproject.toml +44 -0
- baton_proxy-0.1.0/src/baton_proxy/__init__.py +9 -0
- baton_proxy-0.1.0/src/baton_proxy/__main__.py +8 -0
- baton_proxy-0.1.0/src/baton_proxy/config.py +100 -0
- baton_proxy-0.1.0/src/baton_proxy/emitter.py +306 -0
- baton_proxy-0.1.0/src/baton_proxy/proxy.py +554 -0
- baton_proxy-0.1.0/src/baton_proxy/report.py +215 -0
- baton_proxy-0.1.0/src/baton_proxy/sinks.py +219 -0
- baton_proxy-0.1.0/tests/__init__.py +0 -0
- baton_proxy-0.1.0/tests/fixture_server.py +101 -0
- baton_proxy-0.1.0/tests/test_config.py +95 -0
- baton_proxy-0.1.0/tests/test_emitter.py +322 -0
- baton_proxy-0.1.0/tests/test_injection.py +341 -0
- baton_proxy-0.1.0/tests/test_pending_eviction.py +70 -0
- baton_proxy-0.1.0/tests/test_proxy_env.py +61 -0
- baton_proxy-0.1.0/tests/test_report.py +205 -0
- baton_proxy-0.1.0/tests/test_sinks.py +206 -0
- baton_proxy-0.1.0/uv.lock +107 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: release-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: false
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
outputs:
|
|
16
|
+
version: ${{ steps.version.outputs.version }}
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.13"
|
|
22
|
+
- name: Install build tooling
|
|
23
|
+
run: pip install build twine
|
|
24
|
+
- name: Verify tag matches package version
|
|
25
|
+
id: version
|
|
26
|
+
run: |
|
|
27
|
+
TAG="${GITHUB_REF#refs/tags/v}"
|
|
28
|
+
PKG=$(python -c "import sys; sys.path.insert(0, 'src'); from baton_proxy import __version__; print(__version__)")
|
|
29
|
+
if [ "$TAG" != "$PKG" ]; then
|
|
30
|
+
echo "::error::Tag v$TAG does not match __version__=$PKG"
|
|
31
|
+
exit 1
|
|
32
|
+
fi
|
|
33
|
+
echo "version=$TAG" >> "$GITHUB_OUTPUT"
|
|
34
|
+
- name: Build sdist + wheel
|
|
35
|
+
run: python -m build
|
|
36
|
+
- name: Check distribution
|
|
37
|
+
run: twine check dist/*
|
|
38
|
+
- uses: actions/upload-artifact@v4
|
|
39
|
+
with:
|
|
40
|
+
name: dist
|
|
41
|
+
path: dist/
|
|
42
|
+
|
|
43
|
+
publish:
|
|
44
|
+
needs: build
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
environment:
|
|
47
|
+
name: pypi
|
|
48
|
+
url: https://pypi.org/project/baton-proxy/${{ needs.build.outputs.version }}/
|
|
49
|
+
permissions:
|
|
50
|
+
id-token: write # Trusted Publishing — no token secret needed
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/download-artifact@v4
|
|
53
|
+
with:
|
|
54
|
+
name: dist
|
|
55
|
+
path: dist/
|
|
56
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: test-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
python: ["3.11", "3.12", "3.13"]
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python }}
|
|
24
|
+
- run: pip install -e ".[dev]"
|
|
25
|
+
- run: ruff check .
|
|
26
|
+
- run: pytest
|
|
@@ -0,0 +1,24 @@
|
|
|
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.1.0] — 2026-06-12
|
|
11
|
+
|
|
12
|
+
Initial public release on PyPI.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Subprocess-wrap MCP proxy: wraps a stdio MCP server, intercepts the handshake, injects friction-capture tools into the upstream server's `tools/list`.
|
|
16
|
+
- `baton_annotate` tool: lets Claude emit a per-call annotation event when it hits friction (unprompted).
|
|
17
|
+
- `baton_session_report` tool: returns a vendor-shareable markdown report of the session's friction (errors, slow calls, annotations). Local-sink installs only.
|
|
18
|
+
- 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.
|
|
19
|
+
- 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`.
|
|
20
|
+
- 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`.
|
|
21
|
+
- Fail-open delivery: emission runs on a background thread; Console outage never blocks the MCP pipe.
|
|
22
|
+
|
|
23
|
+
[Unreleased]: https://github.com/good-timing/baton-proxy/compare/v0.1.0...HEAD
|
|
24
|
+
[0.1.0]: https://github.com/good-timing/baton-proxy/releases/tag/v0.1.0
|
|
@@ -0,0 +1,200 @@
|
|
|
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 describing the origin of the Work and
|
|
141
|
+
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 Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may accept support, warranty, indemnity,
|
|
167
|
+
or other liability obligations and/or rights consistent with this
|
|
168
|
+
License. However, in accepting such obligations, You may act only
|
|
169
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
170
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
171
|
+
defend, and hold each Contributor harmless for any liability
|
|
172
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
173
|
+
of your accepting any such warranty or support.
|
|
174
|
+
|
|
175
|
+
END OF TERMS AND CONDITIONS
|
|
176
|
+
|
|
177
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
178
|
+
|
|
179
|
+
To apply the Apache License to your work, attach the following
|
|
180
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
181
|
+
replaced with your own identifying information. (Don't include
|
|
182
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
183
|
+
comment syntax for the file format. We also recommend that a
|
|
184
|
+
file or class name and description of purpose be included on the
|
|
185
|
+
same "printed page" as the copyright notice for easier
|
|
186
|
+
identification within third-party archives.
|
|
187
|
+
|
|
188
|
+
Copyright 2026 Good Timing, Inc.
|
|
189
|
+
|
|
190
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
191
|
+
you may not use this file except in compliance with the License.
|
|
192
|
+
You may obtain a copy of the License at
|
|
193
|
+
|
|
194
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
195
|
+
|
|
196
|
+
Unless required by applicable law or agreed to in writing, software
|
|
197
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
198
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
199
|
+
implied. See the License for the specific language governing
|
|
200
|
+
permissions and limitations under the License.
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: baton-proxy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Subprocess-wrap MCP proxy that injects an annotation tool and emits friction events.
|
|
5
|
+
Author: Good Timing, Inc.
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# baton-proxy
|
|
21
|
+
|
|
22
|
+
Subprocess-wrap MCP proxy. Wraps a stdio MCP server, injects an annotation tool into the handshake, and emits friction events to a Baton Console.
|
|
23
|
+
|
|
24
|
+
Zero changes to the underlying MCP server. The proxy *is* the MCP server from Claude's perspective; the real server is its child process.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
┌──────────┐ ┌───────────────┐ ┌────────────────────┐
|
|
28
|
+
│ Claude │ ◀──▶ │ baton-proxy │ ◀──▶ │ your MCP server │
|
|
29
|
+
└──────────┘ └───────┬───────┘ └────────────────────┘
|
|
30
|
+
│ async POST
|
|
31
|
+
▼
|
|
32
|
+
┌──────────────┐
|
|
33
|
+
│ Baton Console│
|
|
34
|
+
└──────────────┘
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pipx install baton-proxy # or: pip install baton-proxy
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Replace your MCP server entry in Claude's config:
|
|
44
|
+
|
|
45
|
+
```jsonc
|
|
46
|
+
// Before
|
|
47
|
+
{ "command": "npx", "args": ["@vendor/mcp-server"] }
|
|
48
|
+
|
|
49
|
+
// After — zero-config: events go to stderr + /tmp/baton-proxy.jsonl
|
|
50
|
+
{ "command": "baton-proxy", "args": ["--", "npx", "@vendor/mcp-server"] }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
That's the entire install. Restart Claude, drive the wrapped server, then either:
|
|
54
|
+
|
|
55
|
+
- 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
|
|
56
|
+
- `cat /tmp/baton-proxy.jsonl` to see the raw friction events.
|
|
57
|
+
|
|
58
|
+
No env vars, no backend, no credentials. The report is a preview of the ticket shape a Baton-instrumented vendor sees in their Console.
|
|
59
|
+
|
|
60
|
+
To ship events to a Console instead (or in addition), add four env vars:
|
|
61
|
+
|
|
62
|
+
```jsonc
|
|
63
|
+
{
|
|
64
|
+
"command": "baton-proxy",
|
|
65
|
+
"args": ["--", "npx", "@vendor/mcp-server"],
|
|
66
|
+
"env": {
|
|
67
|
+
"BATON_EVENT_SINK": "https://console.example.com",
|
|
68
|
+
"BATON_TENANT_ID": "your-tenant",
|
|
69
|
+
"BATON_API_KEY": "...",
|
|
70
|
+
"BATON_CONSENT_TOKEN": "..."
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The proxy adds two tools to the upstream server's tool list:
|
|
76
|
+
- `baton_annotate` — Claude calls it (unprompted) when it hits friction; emits an annotation event.
|
|
77
|
+
- `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.
|
|
78
|
+
|
|
79
|
+
And the proxy emits a friction event per real tool call.
|
|
80
|
+
|
|
81
|
+
## What gets emitted
|
|
82
|
+
|
|
83
|
+
Per real tool call, three event types match the Baton wire format (`tool_call_start` / `tool_call_end` / `tool_call_error`):
|
|
84
|
+
|
|
85
|
+
| Event | Payload |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `tool_call_start` | `{tool_name, params}` |
|
|
88
|
+
| `tool_call_end` | `{tool_name, result, duration_ms}` |
|
|
89
|
+
| `tool_call_error` | `{tool_name, error_type, error_body, duration_ms}` |
|
|
90
|
+
|
|
91
|
+
Each event carries a session id (one per proxy process), monotonic sequence number, and the upstream MCP request's `_meta` block (for cycle correlation).
|
|
92
|
+
|
|
93
|
+
The injected `baton_annotate` tool itself is handled by the proxy; the upstream server never sees it.
|
|
94
|
+
|
|
95
|
+
## Configuration
|
|
96
|
+
|
|
97
|
+
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`.
|
|
98
|
+
|
|
99
|
+
| Variable | Default | Purpose |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| `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. |
|
|
102
|
+
| `BATON_TENANT_ID` | `local` | Tenant identifier. Placeholder; replace when shipping to a Console. |
|
|
103
|
+
| `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. |
|
|
104
|
+
| `BATON_API_KEY` | _(unset)_ | Bearer token. Required only when the sink scheme is `http(s)://`; `file://` and `stderr:` sinks ignore it. |
|
|
105
|
+
| `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. |
|
|
106
|
+
| `BATON_PROXY_LOG_FILE`| _(unset)_ | Path to tee proxy logs to (default: stderr only). |
|
|
107
|
+
|
|
108
|
+
### The three rungs
|
|
109
|
+
|
|
110
|
+
Pick the rung you need; the env-var deltas are the entire difference.
|
|
111
|
+
|
|
112
|
+
| Rung | Sink | env additions |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| **1. Default (install-and-play)** | stderr + `/tmp/baton-proxy.jsonl` | _(none)_ |
|
|
115
|
+
| **2. Custom local capture** | wherever you want | `BATON_EVENT_SINK=file:///path/to/your.jsonl` |
|
|
116
|
+
| **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` |
|
|
117
|
+
|
|
118
|
+
### See it locally
|
|
119
|
+
|
|
120
|
+
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:
|
|
121
|
+
|
|
122
|
+
**Conversational** — ask Claude:
|
|
123
|
+
> Show me the friction report for this session.
|
|
124
|
+
|
|
125
|
+
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.
|
|
126
|
+
|
|
127
|
+
**Raw** — inspect the JSONL stream:
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
cat /tmp/baton-proxy.jsonl | jq -c '{type: .event_type, payload}'
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
See `examples/live-claude-invocation/` for a guided walk-through that also covers the elicitation behaviour of the injected `baton_annotate` tool.
|
|
134
|
+
|
|
135
|
+
### Sink misconfig fails loudly
|
|
136
|
+
|
|
137
|
+
The proxy refuses to start when:
|
|
138
|
+
- an `http(s)://` sink is configured but `BATON_API_KEY` is unset
|
|
139
|
+
- an `http(s)://` sink is configured but `BATON_CONSENT_TOKEN` is still the placeholder `"local"`
|
|
140
|
+
- the sink URL has an unsupported scheme
|
|
141
|
+
|
|
142
|
+
These are emitted as proxy startup errors so a misconfigured install never silently drops or silently mistags events.
|
|
143
|
+
|
|
144
|
+
## Trust properties
|
|
145
|
+
|
|
146
|
+
- **Open source, Apache 2.0.** Auditable end-to-end.
|
|
147
|
+
- **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`.
|
|
148
|
+
- **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.
|
|
149
|
+
- **No deps.** Pure stdlib. No pydantic, no httpx, no third-party runtime requirements.
|
|
150
|
+
- **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.
|
|
151
|
+
|
|
152
|
+
**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.
|
|
153
|
+
|
|
154
|
+
## How it works
|
|
155
|
+
|
|
156
|
+
Two unidirectional pumps:
|
|
157
|
+
|
|
158
|
+
- **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.
|
|
159
|
+
- **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`.
|
|
160
|
+
|
|
161
|
+
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.
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
git clone https://github.com/good-timing/baton-proxy
|
|
167
|
+
cd baton-proxy
|
|
168
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
169
|
+
pip install -e ".[dev]"
|
|
170
|
+
pytest
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Roadmap
|
|
174
|
+
|
|
175
|
+
- PII scrubbing for `params` and `result` payloads (currently passed verbatim).
|
|
176
|
+
- Static-linked single-binary distribution (PyInstaller, then likely a Go rewrite once distribution shape is set).
|
|
177
|
+
- Helm chart for hosted-HTTP MCP servers.
|
|
178
|
+
- Hosted-evaluation mode (per-request consent tokens).
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
Apache 2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# baton-proxy
|
|
2
|
+
|
|
3
|
+
Subprocess-wrap MCP proxy. Wraps a stdio MCP server, injects an annotation tool into the handshake, and emits friction events to a Baton Console.
|
|
4
|
+
|
|
5
|
+
Zero changes to the underlying MCP server. The proxy *is* the MCP server from Claude's perspective; the real server is its child process.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌──────────┐ ┌───────────────┐ ┌────────────────────┐
|
|
9
|
+
│ Claude │ ◀──▶ │ baton-proxy │ ◀──▶ │ your MCP server │
|
|
10
|
+
└──────────┘ └───────┬───────┘ └────────────────────┘
|
|
11
|
+
│ async POST
|
|
12
|
+
▼
|
|
13
|
+
┌──────────────┐
|
|
14
|
+
│ Baton Console│
|
|
15
|
+
└──────────────┘
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pipx install baton-proxy # or: pip install baton-proxy
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Replace your MCP server entry in Claude's config:
|
|
25
|
+
|
|
26
|
+
```jsonc
|
|
27
|
+
// Before
|
|
28
|
+
{ "command": "npx", "args": ["@vendor/mcp-server"] }
|
|
29
|
+
|
|
30
|
+
// After — zero-config: events go to stderr + /tmp/baton-proxy.jsonl
|
|
31
|
+
{ "command": "baton-proxy", "args": ["--", "npx", "@vendor/mcp-server"] }
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
That's the entire install. Restart Claude, drive the wrapped server, then either:
|
|
35
|
+
|
|
36
|
+
- 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
|
|
37
|
+
- `cat /tmp/baton-proxy.jsonl` to see the raw friction events.
|
|
38
|
+
|
|
39
|
+
No env vars, no backend, no credentials. The report is a preview of the ticket shape a Baton-instrumented vendor sees in their Console.
|
|
40
|
+
|
|
41
|
+
To ship events to a Console instead (or in addition), add four env vars:
|
|
42
|
+
|
|
43
|
+
```jsonc
|
|
44
|
+
{
|
|
45
|
+
"command": "baton-proxy",
|
|
46
|
+
"args": ["--", "npx", "@vendor/mcp-server"],
|
|
47
|
+
"env": {
|
|
48
|
+
"BATON_EVENT_SINK": "https://console.example.com",
|
|
49
|
+
"BATON_TENANT_ID": "your-tenant",
|
|
50
|
+
"BATON_API_KEY": "...",
|
|
51
|
+
"BATON_CONSENT_TOKEN": "..."
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The proxy adds two tools to the upstream server's tool list:
|
|
57
|
+
- `baton_annotate` — Claude calls it (unprompted) when it hits friction; emits an annotation event.
|
|
58
|
+
- `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.
|
|
59
|
+
|
|
60
|
+
And the proxy emits a friction event per real tool call.
|
|
61
|
+
|
|
62
|
+
## What gets emitted
|
|
63
|
+
|
|
64
|
+
Per real tool call, three event types match the Baton wire format (`tool_call_start` / `tool_call_end` / `tool_call_error`):
|
|
65
|
+
|
|
66
|
+
| Event | Payload |
|
|
67
|
+
|---|---|
|
|
68
|
+
| `tool_call_start` | `{tool_name, params}` |
|
|
69
|
+
| `tool_call_end` | `{tool_name, result, duration_ms}` |
|
|
70
|
+
| `tool_call_error` | `{tool_name, error_type, error_body, duration_ms}` |
|
|
71
|
+
|
|
72
|
+
Each event carries a session id (one per proxy process), monotonic sequence number, and the upstream MCP request's `_meta` block (for cycle correlation).
|
|
73
|
+
|
|
74
|
+
The injected `baton_annotate` tool itself is handled by the proxy; the upstream server never sees it.
|
|
75
|
+
|
|
76
|
+
## Configuration
|
|
77
|
+
|
|
78
|
+
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`.
|
|
79
|
+
|
|
80
|
+
| Variable | Default | Purpose |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `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. |
|
|
83
|
+
| `BATON_TENANT_ID` | `local` | Tenant identifier. Placeholder; replace when shipping to a Console. |
|
|
84
|
+
| `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. |
|
|
85
|
+
| `BATON_API_KEY` | _(unset)_ | Bearer token. Required only when the sink scheme is `http(s)://`; `file://` and `stderr:` sinks ignore it. |
|
|
86
|
+
| `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. |
|
|
87
|
+
| `BATON_PROXY_LOG_FILE`| _(unset)_ | Path to tee proxy logs to (default: stderr only). |
|
|
88
|
+
|
|
89
|
+
### The three rungs
|
|
90
|
+
|
|
91
|
+
Pick the rung you need; the env-var deltas are the entire difference.
|
|
92
|
+
|
|
93
|
+
| Rung | Sink | env additions |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| **1. Default (install-and-play)** | stderr + `/tmp/baton-proxy.jsonl` | _(none)_ |
|
|
96
|
+
| **2. Custom local capture** | wherever you want | `BATON_EVENT_SINK=file:///path/to/your.jsonl` |
|
|
97
|
+
| **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` |
|
|
98
|
+
|
|
99
|
+
### See it locally
|
|
100
|
+
|
|
101
|
+
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:
|
|
102
|
+
|
|
103
|
+
**Conversational** — ask Claude:
|
|
104
|
+
> Show me the friction report for this session.
|
|
105
|
+
|
|
106
|
+
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.
|
|
107
|
+
|
|
108
|
+
**Raw** — inspect the JSONL stream:
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
cat /tmp/baton-proxy.jsonl | jq -c '{type: .event_type, payload}'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
See `examples/live-claude-invocation/` for a guided walk-through that also covers the elicitation behaviour of the injected `baton_annotate` tool.
|
|
115
|
+
|
|
116
|
+
### Sink misconfig fails loudly
|
|
117
|
+
|
|
118
|
+
The proxy refuses to start when:
|
|
119
|
+
- an `http(s)://` sink is configured but `BATON_API_KEY` is unset
|
|
120
|
+
- an `http(s)://` sink is configured but `BATON_CONSENT_TOKEN` is still the placeholder `"local"`
|
|
121
|
+
- the sink URL has an unsupported scheme
|
|
122
|
+
|
|
123
|
+
These are emitted as proxy startup errors so a misconfigured install never silently drops or silently mistags events.
|
|
124
|
+
|
|
125
|
+
## Trust properties
|
|
126
|
+
|
|
127
|
+
- **Open source, Apache 2.0.** Auditable end-to-end.
|
|
128
|
+
- **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`.
|
|
129
|
+
- **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.
|
|
130
|
+
- **No deps.** Pure stdlib. No pydantic, no httpx, no third-party runtime requirements.
|
|
131
|
+
- **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.
|
|
132
|
+
|
|
133
|
+
**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.
|
|
134
|
+
|
|
135
|
+
## How it works
|
|
136
|
+
|
|
137
|
+
Two unidirectional pumps:
|
|
138
|
+
|
|
139
|
+
- **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.
|
|
140
|
+
- **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`.
|
|
141
|
+
|
|
142
|
+
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.
|
|
143
|
+
|
|
144
|
+
## Development
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
git clone https://github.com/good-timing/baton-proxy
|
|
148
|
+
cd baton-proxy
|
|
149
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
150
|
+
pip install -e ".[dev]"
|
|
151
|
+
pytest
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Roadmap
|
|
155
|
+
|
|
156
|
+
- PII scrubbing for `params` and `result` payloads (currently passed verbatim).
|
|
157
|
+
- Static-linked single-binary distribution (PyInstaller, then likely a Go rewrite once distribution shape is set).
|
|
158
|
+
- Helm chart for hosted-HTTP MCP servers.
|
|
159
|
+
- Hosted-evaluation mode (per-request consent tokens).
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
Apache 2.0. See [LICENSE](LICENSE).
|