@viberqc/mcp-server 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +73 -0
- package/dist/client/api.js +135 -0
- package/dist/contracts/repository.js +1 -0
- package/dist/contracts/tools.js +212 -0
- package/dist/index.js +18 -0
- package/dist/repository/git-files.js +77 -0
- package/dist/repository/identity.js +72 -0
- package/dist/repository/inventory.js +91 -0
- package/dist/repository/viberqc-ignore.js +94 -0
- package/dist/security/content-policy.js +147 -0
- package/dist/security/path-policy.js +167 -0
- package/dist/security/redaction.js +63 -0
- package/dist/tools/register.js +100 -0
- package/dist/tools/repository-inspection.js +223 -0
- package/dist/tools/server.js +43 -0
- package/package.json +60 -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
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @viberqc/mcp-server
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) แบบอ่านอย่างเดียวสำหรับ ViberQC รุ่น P2
|
|
4
|
+
เชื่อมโปรแกรมเขียนโค้ดกับบัญชี Project Token สำรวจข้อมูล Repo ในเครื่อง
|
|
5
|
+
โหลด Scan Profile และเตรียม Scan Session โดยไม่ส่ง Source Code ออกจากเครื่อง
|
|
6
|
+
|
|
7
|
+
แพ็กเกจรุ่นนี้ยังไม่มีคำสั่งรันตัวตรวจ วางแผนซ่อม แก้ไฟล์ หรือยืนยันผลซ่อม
|
|
8
|
+
ความสามารถเหล่านั้นเป็นงาน P3 และ P4
|
|
9
|
+
|
|
10
|
+
รุ่น `0.1.0` เผยแพร่ในช่อง `next` สำหรับทดสอบการเชื่อมต่อ MCP ก่อน
|
|
11
|
+
ยังไม่ใช่รุ่น `latest` และยังไม่ยืนยันว่า ViberQC Production เปิด P2 API
|
|
12
|
+
|
|
13
|
+
## ข้อกำหนด
|
|
14
|
+
|
|
15
|
+
- Node.js `>=22.14.0`
|
|
16
|
+
- ช่องทาง MCP: `stdio`
|
|
17
|
+
- ViberQC API ใช้ HTTPS; HTTP ใช้ได้เฉพาะ `localhost` สำหรับการพัฒนา
|
|
18
|
+
- Project Token อ่านจาก `VIBERQC_PROJECT_TOKEN`
|
|
19
|
+
- API URL อ่านจาก `VIBERQC_API_URL` หรือใช้ `https://www.viberqc.com`
|
|
20
|
+
- Repo root สำรองอ่านจาก `VIBERQC_REPO_ROOT`
|
|
21
|
+
|
|
22
|
+
## สร้างและทดสอบในเครื่อง
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
cd packages/viberqc-mcp
|
|
26
|
+
npm ci
|
|
27
|
+
npm run build
|
|
28
|
+
npm test
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## ติดตั้งจาก npm
|
|
32
|
+
|
|
33
|
+
ล็อกรุ่นตรงตัวเพื่อให้ทุกเครื่องใช้ package เดียวกัน:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @viberqc/mcp-server@0.1.0
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## ตัวอย่างตั้งค่า
|
|
40
|
+
|
|
41
|
+
ตัวอย่างนี้ล็อกรุ่น `0.1.0` ห้ามใส่ค่า Token จริงลงไฟล์ตั้งค่า
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"mcpServers": {
|
|
46
|
+
"viberqc": {
|
|
47
|
+
"command": "npx",
|
|
48
|
+
"args": ["-y", "@viberqc/mcp-server@0.1.0"],
|
|
49
|
+
"env": {
|
|
50
|
+
"VIBERQC_API_URL": "https://www.viberqc.com",
|
|
51
|
+
"VIBERQC_PROJECT_TOKEN": "${VIBERQC_PROJECT_TOKEN}"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## เครื่องมือ P2
|
|
59
|
+
|
|
60
|
+
| Tool | หน้าที่ | ติดต่อ ViberQC |
|
|
61
|
+
|---|---|---:|
|
|
62
|
+
| `viberqc_status` | ตรวจรุ่น บัญชี แผน Project Repo และสิทธิ์ | ใช่ |
|
|
63
|
+
| `viberqc_list_profiles` | แสดง Profile และรายการที่ใช้ได้ | ใช่ |
|
|
64
|
+
| `viberqc_inspect_repo` | สำรวจ Git เครื่องมือ และจำนวนไฟล์ในเครื่อง | ไม่ |
|
|
65
|
+
| `viberqc_prepare_scan` | เตรียม Session โดยส่งเฉพาะข้อมูลสรุป | ใช่ |
|
|
66
|
+
| `viberqc_get_session` | อ่านสถานะและสรุป Session | ใช่ |
|
|
67
|
+
|
|
68
|
+
ข้อมูลที่ไม่ส่งออกจากเครื่อง: Source Code เต็ม, absolute path, Token,
|
|
69
|
+
secret value และเนื้อหา diff
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
เผยแพร่ภายใต้ [Apache License 2.0](./LICENSE)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { DEFAULT_VIBERQC_API_URL, MCP_PACKAGE_VERSION, getSessionOutputSchema, listProfilesOutputSchema, prepareScanOutputSchema, statusOutputSchema, } from '../contracts/tools.js';
|
|
3
|
+
import { assertExternalPayloadSafe } from '../security/redaction.js';
|
|
4
|
+
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
5
|
+
const REQUEST_TIMEOUT_MS = 15_000;
|
|
6
|
+
export class ViberQcApiError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
status;
|
|
9
|
+
constructor(code, message, status) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'ViberQcApiError';
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.status = status;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function normalizeBaseUrl(value) {
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = new URL(value);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new ViberQcApiError('API_CONFIG_INVALID', 'VIBERQC_API_URL must be a valid URL.');
|
|
23
|
+
}
|
|
24
|
+
const isLoopback = parsed.hostname === 'localhost' ||
|
|
25
|
+
parsed.hostname === '127.0.0.1' ||
|
|
26
|
+
parsed.hostname === '[::1]';
|
|
27
|
+
if (parsed.protocol !== 'https:' && !(parsed.protocol === 'http:' && isLoopback)) {
|
|
28
|
+
throw new ViberQcApiError('API_CONFIG_INVALID', 'VIBERQC_API_URL must use HTTPS or a loopback HTTP address.');
|
|
29
|
+
}
|
|
30
|
+
if (parsed.username || parsed.password || parsed.search || parsed.hash) {
|
|
31
|
+
throw new ViberQcApiError('API_CONFIG_INVALID', 'VIBERQC_API_URL cannot contain credentials, a query, or a fragment.');
|
|
32
|
+
}
|
|
33
|
+
return parsed.toString().replace(/\/$/, '');
|
|
34
|
+
}
|
|
35
|
+
function safeHttpMessage(status) {
|
|
36
|
+
if (status === 401) {
|
|
37
|
+
return 'The Project Token is missing, invalid, expired, or revoked.';
|
|
38
|
+
}
|
|
39
|
+
if (status === 403) {
|
|
40
|
+
return 'The Project Token does not have permission for this request.';
|
|
41
|
+
}
|
|
42
|
+
if (status === 429) {
|
|
43
|
+
return 'The ViberQC request limit has been reached.';
|
|
44
|
+
}
|
|
45
|
+
return 'The ViberQC API rejected the request.';
|
|
46
|
+
}
|
|
47
|
+
export class HttpViberQcApi {
|
|
48
|
+
baseUrl;
|
|
49
|
+
projectToken;
|
|
50
|
+
fetchFn;
|
|
51
|
+
timeoutMs;
|
|
52
|
+
constructor(options = {}) {
|
|
53
|
+
this.baseUrl = normalizeBaseUrl(options.baseUrl ?? process.env.VIBERQC_API_URL ?? DEFAULT_VIBERQC_API_URL);
|
|
54
|
+
this.projectToken =
|
|
55
|
+
options.projectToken ?? process.env.VIBERQC_PROJECT_TOKEN ?? '';
|
|
56
|
+
this.fetchFn = options.fetchFn ?? fetch;
|
|
57
|
+
this.timeoutMs = options.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
58
|
+
}
|
|
59
|
+
async status(repository) {
|
|
60
|
+
return this.request('POST', '/api/mcp/v1/token/introspect', statusOutputSchema, { repository });
|
|
61
|
+
}
|
|
62
|
+
async listProfiles(input) {
|
|
63
|
+
const search = new URLSearchParams();
|
|
64
|
+
for (const value of input.techStack) {
|
|
65
|
+
search.append('techStack', value);
|
|
66
|
+
}
|
|
67
|
+
const suffix = search.size > 0 ? `?${search.toString()}` : '';
|
|
68
|
+
return this.request('GET', `/api/mcp/v1/profiles${suffix}`, listProfilesOutputSchema);
|
|
69
|
+
}
|
|
70
|
+
async prepareScan(input) {
|
|
71
|
+
return this.request('POST', '/api/mcp/v1/sessions', prepareScanOutputSchema, input);
|
|
72
|
+
}
|
|
73
|
+
async getSession(sessionId) {
|
|
74
|
+
return this.request('GET', `/api/mcp/v1/sessions/${encodeURIComponent(sessionId)}`, getSessionOutputSchema);
|
|
75
|
+
}
|
|
76
|
+
async request(method, route, schema, body) {
|
|
77
|
+
if (!this.projectToken) {
|
|
78
|
+
throw new ViberQcApiError('TOKEN_MISSING', 'Set VIBERQC_PROJECT_TOKEN before using a network tool.');
|
|
79
|
+
}
|
|
80
|
+
if (this.projectToken.length > 4_096) {
|
|
81
|
+
throw new ViberQcApiError('API_CONFIG_INVALID', 'VIBERQC_PROJECT_TOKEN is invalid.');
|
|
82
|
+
}
|
|
83
|
+
if (body !== undefined) {
|
|
84
|
+
assertExternalPayloadSafe(body);
|
|
85
|
+
}
|
|
86
|
+
const controller = new AbortController();
|
|
87
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
88
|
+
let response;
|
|
89
|
+
try {
|
|
90
|
+
response = await this.fetchFn(`${this.baseUrl}${route}`, {
|
|
91
|
+
method,
|
|
92
|
+
headers: {
|
|
93
|
+
accept: 'application/json',
|
|
94
|
+
authorization: `Bearer ${this.projectToken}`,
|
|
95
|
+
'content-type': 'application/json',
|
|
96
|
+
'x-request-id': randomUUID(),
|
|
97
|
+
'x-viberqc-api-version': 'v1',
|
|
98
|
+
'x-viberqc-mcp-version': MCP_PACKAGE_VERSION,
|
|
99
|
+
},
|
|
100
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
101
|
+
signal: controller.signal,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
throw new ViberQcApiError('API_UNAVAILABLE', 'The ViberQC API could not be reached.');
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
clearTimeout(timeout);
|
|
109
|
+
}
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
throw new ViberQcApiError('API_UNAVAILABLE', safeHttpMessage(response.status), response.status);
|
|
112
|
+
}
|
|
113
|
+
const announcedLength = Number(response.headers.get('content-length') ?? '0');
|
|
114
|
+
if (announcedLength > MAX_RESPONSE_BYTES) {
|
|
115
|
+
throw new ViberQcApiError('API_RESPONSE_TOO_LARGE', 'The ViberQC API response exceeded the allowed size.');
|
|
116
|
+
}
|
|
117
|
+
const text = await response.text();
|
|
118
|
+
if (Buffer.byteLength(text, 'utf8') > MAX_RESPONSE_BYTES) {
|
|
119
|
+
throw new ViberQcApiError('API_RESPONSE_TOO_LARGE', 'The ViberQC API response exceeded the allowed size.');
|
|
120
|
+
}
|
|
121
|
+
let data;
|
|
122
|
+
try {
|
|
123
|
+
data = JSON.parse(text);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
throw new ViberQcApiError('API_RESPONSE_INVALID', 'The ViberQC API returned invalid data.');
|
|
127
|
+
}
|
|
128
|
+
assertExternalPayloadSafe(data);
|
|
129
|
+
const parsed = schema.safeParse(data);
|
|
130
|
+
if (!parsed.success) {
|
|
131
|
+
throw new ViberQcApiError('API_RESPONSE_INVALID', 'The ViberQC API returned data outside the agreed contract.');
|
|
132
|
+
}
|
|
133
|
+
return parsed.data;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_REPOSITORY_SCOPE = 'changed';
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const MCP_SERVER_NAME = 'viberqc';
|
|
3
|
+
export const MCP_PACKAGE_VERSION = '0.1.0';
|
|
4
|
+
export const MCP_API_VERSION = 'v1';
|
|
5
|
+
export const DEFAULT_VIBERQC_API_URL = 'https://www.viberqc.com';
|
|
6
|
+
export const P2_TOOL_NAMES = [
|
|
7
|
+
'viberqc_status',
|
|
8
|
+
'viberqc_list_profiles',
|
|
9
|
+
'viberqc_inspect_repo',
|
|
10
|
+
'viberqc_prepare_scan',
|
|
11
|
+
'viberqc_get_session',
|
|
12
|
+
];
|
|
13
|
+
const identifierSchema = z
|
|
14
|
+
.string()
|
|
15
|
+
.trim()
|
|
16
|
+
.min(1)
|
|
17
|
+
.max(128)
|
|
18
|
+
.regex(/^[A-Za-z0-9][A-Za-z0-9._:-]*$/);
|
|
19
|
+
const uuidSchema = z.string().uuid();
|
|
20
|
+
const itemIdSchema = z
|
|
21
|
+
.string()
|
|
22
|
+
.trim()
|
|
23
|
+
.min(3)
|
|
24
|
+
.max(96)
|
|
25
|
+
.regex(/^[A-Z0-9][A-Z0-9_-]*$/);
|
|
26
|
+
const itemIdsSchema = z.array(itemIdSchema).max(1_000);
|
|
27
|
+
const scopeSchema = z.enum(['changed', 'full']);
|
|
28
|
+
const shaSchema = z.string().regex(/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/i);
|
|
29
|
+
export const statusInputSchema = z.object({}).strict();
|
|
30
|
+
export const statusOutputSchema = z
|
|
31
|
+
.object({
|
|
32
|
+
mcpVersion: z.string().min(1).max(32),
|
|
33
|
+
apiVersion: z.literal(MCP_API_VERSION),
|
|
34
|
+
account: z
|
|
35
|
+
.object({
|
|
36
|
+
userId: uuidSchema,
|
|
37
|
+
teamId: uuidSchema,
|
|
38
|
+
})
|
|
39
|
+
.strict(),
|
|
40
|
+
project: z
|
|
41
|
+
.object({
|
|
42
|
+
projectId: uuidSchema,
|
|
43
|
+
repositoryId: uuidSchema,
|
|
44
|
+
})
|
|
45
|
+
.strict(),
|
|
46
|
+
plan: z
|
|
47
|
+
.object({
|
|
48
|
+
code: identifierSchema,
|
|
49
|
+
active: z.boolean(),
|
|
50
|
+
})
|
|
51
|
+
.strict(),
|
|
52
|
+
repo: z
|
|
53
|
+
.object({
|
|
54
|
+
matched: z.boolean(),
|
|
55
|
+
scope: scopeSchema,
|
|
56
|
+
})
|
|
57
|
+
.strict(),
|
|
58
|
+
permissions: z.array(identifierSchema).max(64),
|
|
59
|
+
})
|
|
60
|
+
.strict();
|
|
61
|
+
export const listProfilesInputSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
techStack: z.array(identifierSchema).max(64).default([]),
|
|
64
|
+
})
|
|
65
|
+
.strict();
|
|
66
|
+
const reasonSchema = z
|
|
67
|
+
.object({
|
|
68
|
+
itemId: itemIdSchema,
|
|
69
|
+
reason: z.string().trim().min(1).max(500),
|
|
70
|
+
})
|
|
71
|
+
.strict();
|
|
72
|
+
const manualItemSchema = z
|
|
73
|
+
.object({
|
|
74
|
+
itemId: itemIdSchema,
|
|
75
|
+
requiredEvidence: z.string().trim().min(1).max(500),
|
|
76
|
+
})
|
|
77
|
+
.strict();
|
|
78
|
+
export const scanProfileSchema = z
|
|
79
|
+
.object({
|
|
80
|
+
profileId: identifierSchema,
|
|
81
|
+
profileVersion: identifierSchema,
|
|
82
|
+
name: z.string().trim().min(1).max(160),
|
|
83
|
+
description: z.string().trim().max(1_000),
|
|
84
|
+
supportedItemIds: itemIdsSchema,
|
|
85
|
+
unsupportedItemIds: z.array(reasonSchema).max(1_000),
|
|
86
|
+
manualItemIds: z.array(manualItemSchema).max(1_000),
|
|
87
|
+
entitlement: z
|
|
88
|
+
.object({
|
|
89
|
+
allowed: z.boolean(),
|
|
90
|
+
reason: z.string().trim().min(1).max(500).optional(),
|
|
91
|
+
})
|
|
92
|
+
.strict(),
|
|
93
|
+
})
|
|
94
|
+
.strict();
|
|
95
|
+
export const listProfilesOutputSchema = z
|
|
96
|
+
.object({
|
|
97
|
+
profiles: z.array(scanProfileSchema).max(100),
|
|
98
|
+
})
|
|
99
|
+
.strict();
|
|
100
|
+
export const inspectRepoInputSchema = z
|
|
101
|
+
.object({
|
|
102
|
+
scope: scopeSchema.default('changed'),
|
|
103
|
+
})
|
|
104
|
+
.strict();
|
|
105
|
+
const dirtyStatusSchema = z
|
|
106
|
+
.object({
|
|
107
|
+
staged: z.number().int().nonnegative(),
|
|
108
|
+
unstaged: z.number().int().nonnegative(),
|
|
109
|
+
untracked: z.number().int().nonnegative(),
|
|
110
|
+
})
|
|
111
|
+
.strict();
|
|
112
|
+
export const inspectRepoOutputSchema = z
|
|
113
|
+
.object({
|
|
114
|
+
branch: z.string().trim().min(1).max(500),
|
|
115
|
+
commitSha: shaSchema,
|
|
116
|
+
dirtyStatus: dirtyStatusSchema,
|
|
117
|
+
techStack: z
|
|
118
|
+
.object({
|
|
119
|
+
languages: z.array(identifierSchema).max(64),
|
|
120
|
+
frameworks: z.array(identifierSchema).max(64),
|
|
121
|
+
packageManagers: z.array(identifierSchema).max(16),
|
|
122
|
+
testCommands: z.array(z.string().trim().min(1).max(300)).max(32),
|
|
123
|
+
})
|
|
124
|
+
.strict(),
|
|
125
|
+
scope: scopeSchema,
|
|
126
|
+
fileCount: z.number().int().nonnegative(),
|
|
127
|
+
skippedCount: z.number().int().nonnegative(),
|
|
128
|
+
skipReasons: z.record(z.string(), z.number().int().nonnegative()),
|
|
129
|
+
repoFingerprint: z.string().regex(/^[a-f0-9]{64}$/),
|
|
130
|
+
})
|
|
131
|
+
.strict();
|
|
132
|
+
export const prepareScanInputSchema = z
|
|
133
|
+
.object({
|
|
134
|
+
profileId: identifierSchema,
|
|
135
|
+
scope: scopeSchema.default('changed'),
|
|
136
|
+
requestedItemIds: itemIdsSchema.min(1),
|
|
137
|
+
})
|
|
138
|
+
.strict();
|
|
139
|
+
export const prepareScanOutputSchema = z
|
|
140
|
+
.object({
|
|
141
|
+
sessionId: uuidSchema,
|
|
142
|
+
profileId: identifierSchema,
|
|
143
|
+
profileVersion: identifierSchema,
|
|
144
|
+
requestedItemIds: itemIdsSchema,
|
|
145
|
+
acceptedItemIds: itemIdsSchema,
|
|
146
|
+
unsupportedItemIds: itemIdsSchema,
|
|
147
|
+
manualItemIds: itemIdsSchema,
|
|
148
|
+
repo: z
|
|
149
|
+
.object({
|
|
150
|
+
repositoryId: uuidSchema,
|
|
151
|
+
branch: z.string().trim().min(1).max(500),
|
|
152
|
+
commitSha: shaSchema,
|
|
153
|
+
scope: scopeSchema,
|
|
154
|
+
})
|
|
155
|
+
.strict(),
|
|
156
|
+
sourceUpload: z.literal(false),
|
|
157
|
+
})
|
|
158
|
+
.strict();
|
|
159
|
+
export const getSessionInputSchema = z
|
|
160
|
+
.object({
|
|
161
|
+
sessionId: uuidSchema,
|
|
162
|
+
})
|
|
163
|
+
.strict();
|
|
164
|
+
const evidenceSummarySchema = z
|
|
165
|
+
.object({
|
|
166
|
+
consideredFiles: z.number().int().nonnegative(),
|
|
167
|
+
skippedFiles: z.number().int().nonnegative(),
|
|
168
|
+
rejectedFiles: z.number().int().nonnegative(),
|
|
169
|
+
evidenceTypes: z.array(identifierSchema).max(64),
|
|
170
|
+
redactedTypes: z.array(identifierSchema).max(64),
|
|
171
|
+
})
|
|
172
|
+
.strict();
|
|
173
|
+
export const getSessionOutputSchema = z
|
|
174
|
+
.object({
|
|
175
|
+
sessionId: uuidSchema,
|
|
176
|
+
projectId: uuidSchema,
|
|
177
|
+
repositoryId: uuidSchema,
|
|
178
|
+
profileId: identifierSchema,
|
|
179
|
+
profileVersion: identifierSchema,
|
|
180
|
+
repo: z
|
|
181
|
+
.object({
|
|
182
|
+
branch: z.string().trim().min(1).max(500),
|
|
183
|
+
commitSha: shaSchema,
|
|
184
|
+
diffSha: shaSchema.optional(),
|
|
185
|
+
scope: scopeSchema,
|
|
186
|
+
})
|
|
187
|
+
.strict(),
|
|
188
|
+
requestedItemIds: itemIdsSchema,
|
|
189
|
+
acceptedItemIds: itemIdsSchema,
|
|
190
|
+
unsupportedItemIds: itemIdsSchema,
|
|
191
|
+
manualItemIds: itemIdsSchema,
|
|
192
|
+
status: z.enum([
|
|
193
|
+
'prepared',
|
|
194
|
+
'queued',
|
|
195
|
+
'running',
|
|
196
|
+
'completed',
|
|
197
|
+
'failed',
|
|
198
|
+
'cancelled',
|
|
199
|
+
]),
|
|
200
|
+
evidenceSummary: evidenceSummarySchema,
|
|
201
|
+
reportId: uuidSchema.optional(),
|
|
202
|
+
sourceUpload: z.literal(false),
|
|
203
|
+
})
|
|
204
|
+
.strict();
|
|
205
|
+
export const repositoryContextSchema = z
|
|
206
|
+
.object({
|
|
207
|
+
repositoryFingerprint: z.string().regex(/^[a-f0-9]{64}$/),
|
|
208
|
+
branch: z.string().trim().min(1).max(500),
|
|
209
|
+
commitSha: shaSchema,
|
|
210
|
+
scope: scopeSchema,
|
|
211
|
+
})
|
|
212
|
+
.strict();
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { redactSensitiveText } from './security/redaction.js';
|
|
4
|
+
import { createViberQcServer } from './tools/server.js';
|
|
5
|
+
function writeSafeLog(message) {
|
|
6
|
+
process.stderr.write(`[viberqc] ${redactSensitiveText(message)}\n`);
|
|
7
|
+
}
|
|
8
|
+
async function main() {
|
|
9
|
+
const server = createViberQcServer();
|
|
10
|
+
const transport = new StdioServerTransport();
|
|
11
|
+
await server.connect(transport);
|
|
12
|
+
writeSafeLog('MCP stdio server started.');
|
|
13
|
+
}
|
|
14
|
+
main().catch((error) => {
|
|
15
|
+
const message = error instanceof Error ? error.message : 'The MCP server could not start.';
|
|
16
|
+
writeSafeLog(message);
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
});
|