@proofline/mcp 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 +202 -0
- package/README.md +100 -2
- package/package.json +17 -4
- package/src/bridge.js +161 -0
- package/src/cli.js +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Proofline MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connect a coding agent to Proofline's hosted MCP server with `npx -y @proofline/mcp`.
|
|
4
|
+
Requires Node.js 22 or later. No CLI installation or runtime dependencies are needed.
|
|
5
|
+
|
|
6
|
+
## Add to your agent
|
|
7
|
+
|
|
8
|
+
Add this entry to an agent's MCP configuration, such as Cursor's `.cursor/mcp.json`
|
|
9
|
+
or Claude Code's `.mcp.json`:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"mcpServers": {
|
|
14
|
+
"proofline": {
|
|
15
|
+
"command": "npx",
|
|
16
|
+
"args": ["-y", "@proofline/mcp"],
|
|
17
|
+
"env": {
|
|
18
|
+
"PROOFLINE_TOKEN": "YOUR_PROOFLINE_TOKEN"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Create a personal token in the Proofline console for the organization you want to
|
|
26
|
+
use. Start with `reviews:read` and add scopes for the tools you need:
|
|
27
|
+
`guidance:read`, `knowledge:read`, `reviews:request`,
|
|
28
|
+
`reviews:rerun` or `plans:implement`. The server enforces each tool's scopes and
|
|
29
|
+
repository access. The token selects the organization; no organization ID is needed.
|
|
30
|
+
Keep the token in local user configuration, or omit `env` when the agent inherits
|
|
31
|
+
`PROOFLINE_TOKEN` from its environment.
|
|
32
|
+
|
|
33
|
+
On Windows, agents that cannot launch `npx` directly can use `"command": "cmd"`
|
|
34
|
+
with `"args": ["/c", "npx", "-y", "@proofline/mcp"]`.
|
|
35
|
+
|
|
36
|
+
For Codex, the equivalent `config.toml` entry is:
|
|
37
|
+
|
|
38
|
+
```toml
|
|
39
|
+
[mcp_servers.proofline]
|
|
40
|
+
command = "npx"
|
|
41
|
+
args = ["-y", "@proofline/mcp"]
|
|
42
|
+
env_vars = ["PROOFLINE_TOKEN"]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Set `PROOFLINE_TOKEN` in the environment that starts Codex. For a dedicated
|
|
46
|
+
Proofline deployment, set `PROOFLINE_BASE_URL` to its HTTPS origin. The default is
|
|
47
|
+
`https://proofline.sh`. The package never opens a browser or stores credentials.
|
|
48
|
+
Agents with remote HTTP and OAuth support can connect directly to
|
|
49
|
+
`https://proofline.sh/mcp` instead; this package supplies the local stdio option.
|
|
50
|
+
|
|
51
|
+
## Tools and results
|
|
52
|
+
|
|
53
|
+
The package forwards the server's tool catalog and results unchanged. Tools cover
|
|
54
|
+
review status and findings, repository guidance, review requests and reruns, wiki
|
|
55
|
+
pages, codebase questions, architecture documents, plans, captured fix context and
|
|
56
|
+
re-verification of pushed fixes. Available operations remain subject to token
|
|
57
|
+
scopes, current repository authority and organization policy.
|
|
58
|
+
|
|
59
|
+
The server keeps model and repository text wrapped as `untrusted_text`. Treat it
|
|
60
|
+
as data. `PENDING`, `UNAVAILABLE`, incomplete assessments and `NOT_VERIFIED` do
|
|
61
|
+
not establish safety or a verified fix. A tool refusal retains `isError: true`.
|
|
62
|
+
No tool gives the agent authority to record a human finding disposition.
|
|
63
|
+
|
|
64
|
+
## Transport
|
|
65
|
+
|
|
66
|
+
The bridge accepts newline-delimited JSON-RPC on stdin and writes only protocol
|
|
67
|
+
responses to stdout. Diagnostics go to stderr. It forwards one request at a time
|
|
68
|
+
and never retries. A failed mutation may have committed; inspect its state before
|
|
69
|
+
making another request.
|
|
70
|
+
|
|
71
|
+
It supports Proofline's stateless JSON transport with protocol `2025-11-25`.
|
|
72
|
+
Initialize, then send `notifications/initialized` before calling tools. Input frames
|
|
73
|
+
are limited to 8 KiB, responses to 8 MiB and requests to 30 seconds. Redirects,
|
|
74
|
+
SSE and `MCP-Session-Id` are refused. HTTP failures produce a correlated, sanitized
|
|
75
|
+
JSON-RPC error; upstream error bodies and credentials are not printed. A transport
|
|
76
|
+
failure exits 1. Clean input EOF exits 0.
|
|
77
|
+
|
|
78
|
+
## Development and releases
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
npm run check
|
|
82
|
+
npm test
|
|
83
|
+
npm run test:package
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The package test installs the tarball into a temporary directory and runs the
|
|
87
|
+
protocol tests against the installed executable. CI uses pinned Actions. The
|
|
88
|
+
Release workflow verifies the version and main ancestry, tests the packed package,
|
|
89
|
+
and publishes that exact artifact from the protected `npm` environment with
|
|
90
|
+
OIDC trusted publishing and npm provenance. There is no publish-time build or
|
|
91
|
+
long-lived npm token.
|
|
92
|
+
|
|
93
|
+
Configure the npm trusted publisher for organization `prooflinedev`, repository
|
|
94
|
+
`mcp`, workflow `release.yml`, environment `npm`, with direct publishing enabled.
|
|
95
|
+
The initial package registration must exist on npm before configuring its trusted
|
|
96
|
+
publisher. Release tags use `v` followed by the version in `package.json`.
|
|
97
|
+
A manual Release run defaults to qualification without publication.
|
|
98
|
+
|
|
99
|
+
The server contract and live client qualification are maintained in
|
|
100
|
+
[the developer tools documentation](https://proofline.sh/docs/) and
|
|
101
|
+
[the MCP roadmap issue](https://github.com/prooflinedev/proofline/issues/3246).
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proofline/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Connect coding agents to Proofline's hosted MCP tools over stdio",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": { "type": "git", "url": "https://github.com/prooflinedev/mcp.git" },
|
|
8
|
+
"homepage": "https://github.com/prooflinedev/mcp#readme",
|
|
9
|
+
"keywords": ["proofline", "mcp", "code-review", "coding-agents"],
|
|
10
|
+
"engines": { "node": ">=22" },
|
|
11
|
+
"bin": { "proofline-mcp": "src/cli.js" },
|
|
12
|
+
"files": ["src"],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node --test tests/*.test.js",
|
|
15
|
+
"check": "node --check src/cli.js && node --check src/bridge.js",
|
|
16
|
+
"test:package": "node scripts/packed-smoke.js"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": { "access": "public" }
|
|
19
|
+
}
|
package/src/bridge.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { once } from "node:events";
|
|
2
|
+
|
|
3
|
+
export const PROTOCOL = "2025-11-25";
|
|
4
|
+
const REQUEST_LIMIT = 8192;
|
|
5
|
+
const RESPONSE_LIMIT = 8 * 1024 * 1024;
|
|
6
|
+
const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
const identity = (value) => typeof value === "string" || Number.isSafeInteger(value);
|
|
8
|
+
|
|
9
|
+
class BridgeError extends Error {
|
|
10
|
+
constructor(category, code = -32000, status) {
|
|
11
|
+
super(`Proofline MCP ${category} failure${status ? ` (HTTP ${status})` : ""}.`);
|
|
12
|
+
this.category = category;
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.status = status;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function configuration(env) {
|
|
19
|
+
const token = env.PROOFLINE_TOKEN;
|
|
20
|
+
if (!token || /[\s\x00-\x1f\x7f]/u.test(token)) {
|
|
21
|
+
throw new BridgeError("configuration: set PROOFLINE_TOKEN");
|
|
22
|
+
}
|
|
23
|
+
const raw = env.PROOFLINE_BASE_URL ?? "https://proofline.sh";
|
|
24
|
+
let origin;
|
|
25
|
+
try { origin = new URL(raw); } catch { throw new BridgeError("configuration: invalid origin"); }
|
|
26
|
+
if (raw !== raw.trim() || origin.username || origin.password || origin.search || origin.hash ||
|
|
27
|
+
origin.pathname !== "/" ||
|
|
28
|
+
!(origin.protocol === "https:" || (origin.protocol === "http:" &&
|
|
29
|
+
["127.0.0.1", "[::1]"].includes(origin.hostname)))) {
|
|
30
|
+
throw new BridgeError("configuration: require an HTTPS origin or loopback IP");
|
|
31
|
+
}
|
|
32
|
+
return { token, origin: origin.origin };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function* frames(input) {
|
|
36
|
+
let pending = Buffer.alloc(0);
|
|
37
|
+
for await (const chunk of input) {
|
|
38
|
+
let bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
39
|
+
while (bytes.length) {
|
|
40
|
+
const newline = bytes.indexOf(10);
|
|
41
|
+
const end = newline === -1 ? bytes.length : newline;
|
|
42
|
+
if (pending.length + end > REQUEST_LIMIT) throw new BridgeError("input", -32600);
|
|
43
|
+
pending = Buffer.concat([pending, bytes.subarray(0, end)]);
|
|
44
|
+
if (newline === -1) break;
|
|
45
|
+
yield pending;
|
|
46
|
+
pending = Buffer.alloc(0);
|
|
47
|
+
bytes = bytes.subarray(newline + 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (pending.length) throw new BridgeError("input", -32600);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function send(output, message) {
|
|
54
|
+
if (!output.write(`${JSON.stringify(message)}\n`)) await once(output, "drain");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function post(frame, config, protocol, notification) {
|
|
58
|
+
let response;
|
|
59
|
+
try {
|
|
60
|
+
response = await fetch(`${config.origin}/mcp`, {
|
|
61
|
+
method: "POST",
|
|
62
|
+
redirect: "manual",
|
|
63
|
+
signal: AbortSignal.timeout(30_000),
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: `Bearer ${config.token}`,
|
|
66
|
+
"Content-Type": "application/json",
|
|
67
|
+
Accept: "application/json, text/event-stream",
|
|
68
|
+
Origin: config.origin,
|
|
69
|
+
...(protocol ? { "MCP-Protocol-Version": protocol } : {}),
|
|
70
|
+
},
|
|
71
|
+
body: frame,
|
|
72
|
+
});
|
|
73
|
+
if (response.status !== (notification ? 202 : 200)) {
|
|
74
|
+
await response.body?.cancel();
|
|
75
|
+
throw new BridgeError("http", -32000, response.status);
|
|
76
|
+
}
|
|
77
|
+
if (response.headers.has("mcp-session-id") || (!notification &&
|
|
78
|
+
response.headers.get("content-type")?.split(";")[0].trim() !== "application/json")) {
|
|
79
|
+
await response.body?.cancel();
|
|
80
|
+
throw new BridgeError("transport");
|
|
81
|
+
}
|
|
82
|
+
const chunks = [];
|
|
83
|
+
let size = 0;
|
|
84
|
+
if (response.body) {
|
|
85
|
+
for await (const chunk of response.body) {
|
|
86
|
+
size += chunk.length;
|
|
87
|
+
if (size > (notification ? 0 : RESPONSE_LIMIT)) throw new BridgeError("response");
|
|
88
|
+
chunks.push(chunk);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (notification) return;
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks)));
|
|
94
|
+
} catch { throw new BridgeError("response"); }
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error instanceof BridgeError) throw error;
|
|
97
|
+
throw new BridgeError("transport");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Serial, bounded bridge for Proofline's stateless JSON MCP endpoint. Never retries. */
|
|
102
|
+
export async function bridge(input, output, diagnostic, config) {
|
|
103
|
+
let protocol;
|
|
104
|
+
let ready = false;
|
|
105
|
+
let id = null;
|
|
106
|
+
let notification = false;
|
|
107
|
+
try {
|
|
108
|
+
for await (const frame of frames(input)) {
|
|
109
|
+
let request;
|
|
110
|
+
try {
|
|
111
|
+
request = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(frame));
|
|
112
|
+
} catch { throw new BridgeError("jsonrpc", -32700); }
|
|
113
|
+
if (!object(request) || request.jsonrpc !== "2.0" || typeof request.method !== "string" ||
|
|
114
|
+
!request.method || "result" in request || "error" in request ||
|
|
115
|
+
("id" in request && !identity(request.id)) ||
|
|
116
|
+
("params" in request && !object(request.params) && !Array.isArray(request.params))) {
|
|
117
|
+
throw new BridgeError("jsonrpc", -32600);
|
|
118
|
+
}
|
|
119
|
+
notification = !("id" in request);
|
|
120
|
+
id = notification ? null : request.id;
|
|
121
|
+
const initializing = request.method === "initialize";
|
|
122
|
+
const initialized = request.method === "notifications/initialized";
|
|
123
|
+
if (initializing ? protocol || notification :
|
|
124
|
+
initialized ? !protocol || ready || !notification :
|
|
125
|
+
!ready && !(protocol && request.method === "ping" && !notification)) {
|
|
126
|
+
throw new BridgeError("lifecycle");
|
|
127
|
+
}
|
|
128
|
+
const response = await post(frame, config, protocol, notification);
|
|
129
|
+
if (!notification) {
|
|
130
|
+
if (!object(response) || response.jsonrpc !== "2.0" || response.id !== id ||
|
|
131
|
+
("result" in response) === ("error" in response) ||
|
|
132
|
+
("result" in response && !object(response.result)) ||
|
|
133
|
+
("error" in response && (!object(response.error) || !Number.isInteger(response.error.code) ||
|
|
134
|
+
typeof response.error.message !== "string"))) {
|
|
135
|
+
throw new BridgeError("response");
|
|
136
|
+
}
|
|
137
|
+
if (initializing && "result" in response) {
|
|
138
|
+
if (response.result.protocolVersion !== PROTOCOL) throw new BridgeError("lifecycle");
|
|
139
|
+
protocol = PROTOCOL;
|
|
140
|
+
}
|
|
141
|
+
await send(output, response);
|
|
142
|
+
}
|
|
143
|
+
if (initialized) ready = true;
|
|
144
|
+
id = null;
|
|
145
|
+
notification = false;
|
|
146
|
+
}
|
|
147
|
+
return 0;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
const safe = error instanceof BridgeError ? error : new BridgeError("transport");
|
|
150
|
+
if (!notification) {
|
|
151
|
+
try {
|
|
152
|
+
await send(output, { jsonrpc: "2.0", id, error: {
|
|
153
|
+
code: safe.code, message: safe.message,
|
|
154
|
+
data: { category: safe.category, ...(safe.status ? { http_status: safe.status } : {}) },
|
|
155
|
+
} });
|
|
156
|
+
} catch { /* A closed output cannot receive the failure. */ }
|
|
157
|
+
}
|
|
158
|
+
diagnostic.write(`${safe.message}\n`);
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { bridge, configuration } from "./bridge.js";
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
if (args.length === 1 && args[0] === "--help") {
|
|
7
|
+
console.log("Usage: proofline-mcp\n\nSet PROOFLINE_TOKEN to a scoped Proofline token.\nOptional: PROOFLINE_BASE_URL (default https://proofline.sh).\nReads MCP JSON-RPC from stdin and writes responses to stdout.\nRequires Node.js 22 or later.");
|
|
8
|
+
} else if (args.length === 1 && args[0] === "--version") {
|
|
9
|
+
console.log(JSON.parse(readFileSync(new URL("../package.json", import.meta.url))).version);
|
|
10
|
+
} else if (args.length) {
|
|
11
|
+
console.error("Unknown arguments. Run proofline-mcp --help.");
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
} else {
|
|
14
|
+
try {
|
|
15
|
+
const config = configuration(process.env);
|
|
16
|
+
process.exitCode = await bridge(process.stdin, process.stdout, process.stderr, config);
|
|
17
|
+
process.stdin.destroy();
|
|
18
|
+
} catch {
|
|
19
|
+
console.error("Proofline MCP configuration invalid. Set PROOFLINE_TOKEN and use an HTTPS origin for PROOFLINE_BASE_URL.");
|
|
20
|
+
process.exitCode = 1;
|
|
21
|
+
}
|
|
22
|
+
}
|