@andpipes/mcp-adapter 0.0.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 +201 -0
- package/dist/index.cjs +352 -0
- package/dist/index.d.cts +184 -0
- package/dist/index.d.ts +184 -0
- package/dist/index.js +294 -0
- package/package.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Do not include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 EEG Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ANDPIPE_CALL_ENVELOPE_ARGUMENT: () => ANDPIPE_CALL_ENVELOPE_ARGUMENT,
|
|
24
|
+
ANDPIPE_CONFIRMATION_INPUT_PATH: () => ANDPIPE_CONFIRMATION_INPUT_PATH,
|
|
25
|
+
ANDPIPE_CONFIRMATION_META_KEY: () => ANDPIPE_CONFIRMATION_META_KEY,
|
|
26
|
+
AP_JSON_RPC_AUTH: () => AP_JSON_RPC_AUTH,
|
|
27
|
+
AP_JSON_RPC_DOMAIN: () => AP_JSON_RPC_DOMAIN,
|
|
28
|
+
AP_JSON_RPC_POLICY: () => AP_JSON_RPC_POLICY,
|
|
29
|
+
AP_JSON_RPC_SERVER: () => AP_JSON_RPC_SERVER,
|
|
30
|
+
GEMINI_COMPATIBILITY_PROFILES: () => GEMINI_COMPATIBILITY_PROFILES,
|
|
31
|
+
GEMINI_ENTERPRISE_CLIENT_MARKER: () => GEMINI_ENTERPRISE_CLIENT_MARKER,
|
|
32
|
+
GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI: () => GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI,
|
|
33
|
+
GEMINI_EXTENSION_GITHUB_TOPIC: () => GEMINI_EXTENSION_GITHUB_TOPIC,
|
|
34
|
+
GEMINI_EXTENSION_MANIFEST: () => GEMINI_EXTENSION_MANIFEST,
|
|
35
|
+
GEMINI_MCP_SERVER_NAME: () => GEMINI_MCP_SERVER_NAME,
|
|
36
|
+
GEMINI_SURFACES: () => GEMINI_SURFACES,
|
|
37
|
+
JSON_RPC_INTERNAL_ERROR: () => JSON_RPC_INTERNAL_ERROR,
|
|
38
|
+
JSON_RPC_INVALID_PARAMS: () => JSON_RPC_INVALID_PARAMS,
|
|
39
|
+
JSON_RPC_INVALID_REQUEST: () => JSON_RPC_INVALID_REQUEST,
|
|
40
|
+
JSON_RPC_METHOD_NOT_FOUND: () => JSON_RPC_METHOD_NOT_FOUND,
|
|
41
|
+
JSON_RPC_PARSE_ERROR: () => JSON_RPC_PARSE_ERROR,
|
|
42
|
+
JsonRpcParseError: () => JsonRpcParseError,
|
|
43
|
+
MCP_PROTOCOL_VERSION: () => MCP_PROTOCOL_VERSION,
|
|
44
|
+
McpProtocolError: () => McpProtocolError,
|
|
45
|
+
apCodeToJsonRpc: () => apCodeToJsonRpc,
|
|
46
|
+
geminiCompatibilityProfile: () => geminiCompatibilityProfile,
|
|
47
|
+
isJsonRpcNotification: () => isJsonRpcNotification,
|
|
48
|
+
jsonRpcError: () => jsonRpcError,
|
|
49
|
+
jsonRpcResult: () => jsonRpcResult,
|
|
50
|
+
packageName: () => packageName,
|
|
51
|
+
parseCallToolParams: () => parseCallToolParams,
|
|
52
|
+
parseJsonRpcRequest: () => parseJsonRpcRequest,
|
|
53
|
+
splitAndpipeCallArguments: () => splitAndpipeCallArguments,
|
|
54
|
+
withAndpipeConfirmationInputSchema: () => withAndpipeConfirmationInputSchema
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(index_exports);
|
|
57
|
+
|
|
58
|
+
// src/jsonrpc.ts
|
|
59
|
+
var JSON_RPC_PARSE_ERROR = -32700;
|
|
60
|
+
var JSON_RPC_INVALID_REQUEST = -32600;
|
|
61
|
+
var JSON_RPC_METHOD_NOT_FOUND = -32601;
|
|
62
|
+
var JSON_RPC_INVALID_PARAMS = -32602;
|
|
63
|
+
var JSON_RPC_INTERNAL_ERROR = -32603;
|
|
64
|
+
var JsonRpcParseError = class extends Error {
|
|
65
|
+
code;
|
|
66
|
+
/** 可能なら元 request の id を保持し、エラー応答に載せる。 */
|
|
67
|
+
rpcId;
|
|
68
|
+
constructor(code, message, rpcId = null) {
|
|
69
|
+
super(message);
|
|
70
|
+
this.name = "JsonRpcParseError";
|
|
71
|
+
this.code = code;
|
|
72
|
+
this.rpcId = rpcId;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function isJsonRpcId(value) {
|
|
76
|
+
return value === null || typeof value === "string" || typeof value === "number";
|
|
77
|
+
}
|
|
78
|
+
function parseJsonRpcRequest(raw) {
|
|
79
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
80
|
+
throw new JsonRpcParseError(JSON_RPC_INVALID_REQUEST, "request must be a JSON object");
|
|
81
|
+
}
|
|
82
|
+
const obj = raw;
|
|
83
|
+
const id = isJsonRpcId(obj.id) ? obj.id : null;
|
|
84
|
+
if (obj.jsonrpc !== "2.0") {
|
|
85
|
+
throw new JsonRpcParseError(JSON_RPC_INVALID_REQUEST, 'jsonrpc must be "2.0"', id);
|
|
86
|
+
}
|
|
87
|
+
if (typeof obj.method !== "string" || obj.method.length === 0) {
|
|
88
|
+
throw new JsonRpcParseError(JSON_RPC_INVALID_REQUEST, "method must be a non-empty string", id);
|
|
89
|
+
}
|
|
90
|
+
if (!isJsonRpcId(obj.id)) {
|
|
91
|
+
throw new JsonRpcParseError(JSON_RPC_INVALID_REQUEST, "id must be string | number | null");
|
|
92
|
+
}
|
|
93
|
+
return { jsonrpc: "2.0", id: obj.id, method: obj.method, params: obj.params };
|
|
94
|
+
}
|
|
95
|
+
function isJsonRpcNotification(raw) {
|
|
96
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
const obj = raw;
|
|
100
|
+
return obj.jsonrpc === "2.0" && typeof obj.method === "string" && obj.id === void 0;
|
|
101
|
+
}
|
|
102
|
+
function jsonRpcResult(id, result) {
|
|
103
|
+
return { jsonrpc: "2.0", id, result };
|
|
104
|
+
}
|
|
105
|
+
function jsonRpcError(id, code, message, data) {
|
|
106
|
+
const error = data === void 0 ? { code, message } : { code, message, data };
|
|
107
|
+
return { jsonrpc: "2.0", id, error };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/errors.ts
|
|
111
|
+
var AP_JSON_RPC_AUTH = -32001;
|
|
112
|
+
var AP_JSON_RPC_POLICY = -32002;
|
|
113
|
+
var AP_JSON_RPC_SERVER = -32003;
|
|
114
|
+
var AP_JSON_RPC_DOMAIN = -32004;
|
|
115
|
+
var JSON_RPC_BY_AP_CODE = {
|
|
116
|
+
AP_AUTH_REQUIRED: AP_JSON_RPC_AUTH,
|
|
117
|
+
AP_INVALID_TOKEN: AP_JSON_RPC_AUTH,
|
|
118
|
+
AP_INVALID_AUDIENCE: AP_JSON_RPC_AUTH,
|
|
119
|
+
AP_INVALID_RESOURCE: AP_JSON_RPC_AUTH,
|
|
120
|
+
AP_INVALID_SCOPE: AP_JSON_RPC_AUTH,
|
|
121
|
+
AP_POLICY_DENIED: AP_JSON_RPC_POLICY,
|
|
122
|
+
AP_PLAN_LIMIT_EXCEEDED: AP_JSON_RPC_POLICY,
|
|
123
|
+
AP_CONFIRMATION_REQUIRED: AP_JSON_RPC_POLICY,
|
|
124
|
+
AP_CONFIRMATION_EXPIRED: AP_JSON_RPC_POLICY,
|
|
125
|
+
AP_CONFIRMATION_REJECTED: AP_JSON_RPC_POLICY,
|
|
126
|
+
AP_CONFLICT: AP_JSON_RPC_POLICY,
|
|
127
|
+
AP_IDEMPOTENCY_KEY_CONFLICT: AP_JSON_RPC_POLICY,
|
|
128
|
+
AP_INVALID_STATE_TRANSITION: AP_JSON_RPC_POLICY,
|
|
129
|
+
AP_CONFIG_DRAFT_REQUIRED: AP_JSON_RPC_POLICY,
|
|
130
|
+
AP_NOT_FOUND: JSON_RPC_METHOD_NOT_FOUND,
|
|
131
|
+
AP_TOOL_NOT_FOUND: JSON_RPC_METHOD_NOT_FOUND,
|
|
132
|
+
AP_TOOL_VERSION_NOT_FOUND: JSON_RPC_METHOD_NOT_FOUND,
|
|
133
|
+
AP_INPUT_INVALID: JSON_RPC_INVALID_PARAMS,
|
|
134
|
+
AP_IDEMPOTENCY_KEY_REQUIRED: JSON_RPC_INVALID_PARAMS,
|
|
135
|
+
AP_SECRET_VALUE_NOT_ALLOWED: JSON_RPC_INVALID_PARAMS,
|
|
136
|
+
AP_RATE_LIMITED: AP_JSON_RPC_SERVER,
|
|
137
|
+
AP_UPSTREAM_AUTH_FAILED: AP_JSON_RPC_SERVER,
|
|
138
|
+
AP_UPSTREAM_TIMEOUT: AP_JSON_RPC_SERVER,
|
|
139
|
+
AP_UPSTREAM_ERROR: AP_JSON_RPC_SERVER,
|
|
140
|
+
AP_REDACTION_FAILED: AP_JSON_RPC_SERVER,
|
|
141
|
+
AP_WIDGET_RENDER_FAILED: AP_JSON_RPC_SERVER,
|
|
142
|
+
AP_OUTPUT_INVALID: JSON_RPC_INTERNAL_ERROR,
|
|
143
|
+
AP_DOMAIN_NOT_VERIFIED: AP_JSON_RPC_DOMAIN
|
|
144
|
+
};
|
|
145
|
+
function apCodeToJsonRpc(apCode, message) {
|
|
146
|
+
const code = JSON_RPC_BY_AP_CODE[apCode] ?? JSON_RPC_INTERNAL_ERROR;
|
|
147
|
+
return { code, message: message ?? apCode, data: { apCode } };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/gemini.ts
|
|
151
|
+
var GEMINI_MCP_SERVER_NAME = "andpipe";
|
|
152
|
+
var GEMINI_ENTERPRISE_CLIENT_MARKER = "gemini_enterprise";
|
|
153
|
+
var GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI = "https://vertexaisearch.cloud.google.com/oauth-redirect";
|
|
154
|
+
var GEMINI_EXTENSION_GITHUB_TOPIC = "gemini-cli-extension";
|
|
155
|
+
var GEMINI_EXTENSION_MANIFEST = "gemini-extension.json";
|
|
156
|
+
var GEMINI_SURFACES = ["gemini_cli", "gemini_api", "gemini_enterprise"];
|
|
157
|
+
var GEMINI_COMPATIBILITY_PROFILES = {
|
|
158
|
+
gemini_cli: {
|
|
159
|
+
surface: "gemini_cli",
|
|
160
|
+
transport: "streamable_http",
|
|
161
|
+
serverName: GEMINI_MCP_SERVER_NAME,
|
|
162
|
+
oauthMode: "oauth_discovery_or_static",
|
|
163
|
+
policyIdentity: "unverified",
|
|
164
|
+
confirmation: "andpipe_signed_human_evidence",
|
|
165
|
+
resultContract: "mcp_content_with_text_fallback_and_structured_content",
|
|
166
|
+
maxEnabledActions: null,
|
|
167
|
+
lifecycle: "supported",
|
|
168
|
+
publicationSurface: "extension_gallery_auto_index"
|
|
169
|
+
},
|
|
170
|
+
gemini_api: {
|
|
171
|
+
surface: "gemini_api",
|
|
172
|
+
transport: "streamable_http",
|
|
173
|
+
serverName: GEMINI_MCP_SERVER_NAME,
|
|
174
|
+
oauthMode: "caller_supplied_header",
|
|
175
|
+
policyIdentity: "unverified",
|
|
176
|
+
confirmation: "andpipe_signed_human_evidence",
|
|
177
|
+
resultContract: "mcp_content_with_text_fallback_and_structured_content",
|
|
178
|
+
maxEnabledActions: null,
|
|
179
|
+
lifecycle: "supported",
|
|
180
|
+
publicationSurface: "direct_remote_mcp_configuration"
|
|
181
|
+
},
|
|
182
|
+
gemini_enterprise: {
|
|
183
|
+
surface: "gemini_enterprise",
|
|
184
|
+
transport: "streamable_http",
|
|
185
|
+
serverName: GEMINI_MCP_SERVER_NAME,
|
|
186
|
+
oauthMode: "confidential_client",
|
|
187
|
+
policyIdentity: "registered_confidential_client",
|
|
188
|
+
confirmation: "andpipe_signed_human_evidence",
|
|
189
|
+
resultContract: "mcp_content_with_text_fallback_and_structured_content",
|
|
190
|
+
maxEnabledActions: 100,
|
|
191
|
+
lifecycle: "preview",
|
|
192
|
+
publicationSurface: "tenant_admin_data_store"
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function geminiCompatibilityProfile(surface) {
|
|
196
|
+
return GEMINI_COMPATIBILITY_PROFILES[surface];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/tools.ts
|
|
200
|
+
var MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
201
|
+
var ANDPIPE_CALL_ENVELOPE_ARGUMENT = "_andpipe";
|
|
202
|
+
var ANDPIPE_CONFIRMATION_META_KEY = "andpipe.dev/confirmation";
|
|
203
|
+
var ANDPIPE_CONFIRMATION_INPUT_PATH = "_andpipe.confirmation";
|
|
204
|
+
var CONFIRMATION_INPUT_SCHEMA = {
|
|
205
|
+
type: "object",
|
|
206
|
+
description: "Reserved andpipe control envelope. It is removed before business input validation and upstream execution.",
|
|
207
|
+
additionalProperties: false,
|
|
208
|
+
required: ["confirmation"],
|
|
209
|
+
properties: {
|
|
210
|
+
confirmation: {
|
|
211
|
+
oneOf: [
|
|
212
|
+
{
|
|
213
|
+
type: "object",
|
|
214
|
+
additionalProperties: false,
|
|
215
|
+
required: ["confirmationId", "signature"],
|
|
216
|
+
properties: {
|
|
217
|
+
confirmationId: { type: "string", format: "uuid" },
|
|
218
|
+
signature: { type: "string", pattern: "^[a-f0-9]{64}$" }
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
type: "object",
|
|
223
|
+
additionalProperties: false,
|
|
224
|
+
required: ["confirmationId", "decision"],
|
|
225
|
+
properties: {
|
|
226
|
+
confirmationId: { type: "string", format: "uuid" },
|
|
227
|
+
decision: { const: "rejected" }
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
function record(value) {
|
|
235
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
236
|
+
}
|
|
237
|
+
function exactKeys(value, expected) {
|
|
238
|
+
const actual = Object.keys(value).sort();
|
|
239
|
+
const canonical = [...expected].sort();
|
|
240
|
+
return actual.length === canonical.length && actual.every((key, index) => key === canonical[index]);
|
|
241
|
+
}
|
|
242
|
+
function parseConfirmationArgument(raw) {
|
|
243
|
+
const value = record(raw);
|
|
244
|
+
if (!value) return null;
|
|
245
|
+
if (exactKeys(value, ["confirmationId", "signature"]) && typeof value.confirmationId === "string" && typeof value.signature === "string") {
|
|
246
|
+
return { confirmationId: value.confirmationId, signature: value.signature };
|
|
247
|
+
}
|
|
248
|
+
if (exactKeys(value, ["confirmationId", "decision"]) && typeof value.confirmationId === "string" && value.decision === "rejected") {
|
|
249
|
+
return { confirmationId: value.confirmationId, decision: "rejected" };
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
function splitAndpipeCallArguments(input) {
|
|
254
|
+
if (!(ANDPIPE_CALL_ENVELOPE_ARGUMENT in input)) {
|
|
255
|
+
return { arguments: { ...input }, confirmation: null };
|
|
256
|
+
}
|
|
257
|
+
const envelope = record(input[ANDPIPE_CALL_ENVELOPE_ARGUMENT]);
|
|
258
|
+
if (!envelope || !exactKeys(envelope, ["confirmation"])) {
|
|
259
|
+
throw new McpProtocolError(
|
|
260
|
+
JSON_RPC_INVALID_PARAMS,
|
|
261
|
+
"params.arguments._andpipe must contain only a valid confirmation"
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const confirmation = parseConfirmationArgument(envelope.confirmation);
|
|
265
|
+
if (!confirmation) {
|
|
266
|
+
throw new McpProtocolError(
|
|
267
|
+
JSON_RPC_INVALID_PARAMS,
|
|
268
|
+
"params.arguments._andpipe.confirmation is invalid"
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
const { [ANDPIPE_CALL_ENVELOPE_ARGUMENT]: _reserved, ...businessArguments } = input;
|
|
272
|
+
return { arguments: businessArguments, confirmation };
|
|
273
|
+
}
|
|
274
|
+
function withAndpipeConfirmationInputSchema(inputSchema) {
|
|
275
|
+
const properties = record(inputSchema.properties) ?? {};
|
|
276
|
+
return {
|
|
277
|
+
...inputSchema,
|
|
278
|
+
type: inputSchema.type ?? "object",
|
|
279
|
+
properties: {
|
|
280
|
+
...properties,
|
|
281
|
+
[ANDPIPE_CALL_ENVELOPE_ARGUMENT]: CONFIRMATION_INPUT_SCHEMA
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
var McpProtocolError = class extends Error {
|
|
286
|
+
code;
|
|
287
|
+
constructor(code, message) {
|
|
288
|
+
super(message);
|
|
289
|
+
this.name = "McpProtocolError";
|
|
290
|
+
this.code = code;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
function parseCallToolParams(params) {
|
|
294
|
+
if (typeof params !== "object" || params === null || Array.isArray(params)) {
|
|
295
|
+
throw new McpProtocolError(JSON_RPC_INVALID_PARAMS, "params must be an object");
|
|
296
|
+
}
|
|
297
|
+
const obj = params;
|
|
298
|
+
if (typeof obj.name !== "string" || obj.name.length === 0) {
|
|
299
|
+
throw new McpProtocolError(JSON_RPC_INVALID_PARAMS, "params.name must be a non-empty string");
|
|
300
|
+
}
|
|
301
|
+
const args = obj.arguments;
|
|
302
|
+
if (args !== void 0 && (typeof args !== "object" || args === null || Array.isArray(args))) {
|
|
303
|
+
throw new McpProtocolError(JSON_RPC_INVALID_PARAMS, "params.arguments must be an object");
|
|
304
|
+
}
|
|
305
|
+
const parsed = {
|
|
306
|
+
name: obj.name,
|
|
307
|
+
arguments: args ?? {}
|
|
308
|
+
};
|
|
309
|
+
const meta = obj._meta;
|
|
310
|
+
if (typeof meta === "object" && meta !== null && !Array.isArray(meta)) {
|
|
311
|
+
parsed._meta = meta;
|
|
312
|
+
}
|
|
313
|
+
return parsed;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/index.ts
|
|
317
|
+
var packageName = "@andpipes/mcp-adapter";
|
|
318
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
319
|
+
0 && (module.exports = {
|
|
320
|
+
ANDPIPE_CALL_ENVELOPE_ARGUMENT,
|
|
321
|
+
ANDPIPE_CONFIRMATION_INPUT_PATH,
|
|
322
|
+
ANDPIPE_CONFIRMATION_META_KEY,
|
|
323
|
+
AP_JSON_RPC_AUTH,
|
|
324
|
+
AP_JSON_RPC_DOMAIN,
|
|
325
|
+
AP_JSON_RPC_POLICY,
|
|
326
|
+
AP_JSON_RPC_SERVER,
|
|
327
|
+
GEMINI_COMPATIBILITY_PROFILES,
|
|
328
|
+
GEMINI_ENTERPRISE_CLIENT_MARKER,
|
|
329
|
+
GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI,
|
|
330
|
+
GEMINI_EXTENSION_GITHUB_TOPIC,
|
|
331
|
+
GEMINI_EXTENSION_MANIFEST,
|
|
332
|
+
GEMINI_MCP_SERVER_NAME,
|
|
333
|
+
GEMINI_SURFACES,
|
|
334
|
+
JSON_RPC_INTERNAL_ERROR,
|
|
335
|
+
JSON_RPC_INVALID_PARAMS,
|
|
336
|
+
JSON_RPC_INVALID_REQUEST,
|
|
337
|
+
JSON_RPC_METHOD_NOT_FOUND,
|
|
338
|
+
JSON_RPC_PARSE_ERROR,
|
|
339
|
+
JsonRpcParseError,
|
|
340
|
+
MCP_PROTOCOL_VERSION,
|
|
341
|
+
McpProtocolError,
|
|
342
|
+
apCodeToJsonRpc,
|
|
343
|
+
geminiCompatibilityProfile,
|
|
344
|
+
isJsonRpcNotification,
|
|
345
|
+
jsonRpcError,
|
|
346
|
+
jsonRpcResult,
|
|
347
|
+
packageName,
|
|
348
|
+
parseCallToolParams,
|
|
349
|
+
parseJsonRpcRequest,
|
|
350
|
+
splitAndpipeCallArguments,
|
|
351
|
+
withAndpipeConfirmationInputSchema
|
|
352
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/** andpipe server error 帯 (-32000〜-32099) の仮割当 (SoT 14.1, 確定要)。 */
|
|
2
|
+
declare const AP_JSON_RPC_AUTH = -32001;
|
|
3
|
+
declare const AP_JSON_RPC_POLICY = -32002;
|
|
4
|
+
declare const AP_JSON_RPC_SERVER = -32003;
|
|
5
|
+
declare const AP_JSON_RPC_DOMAIN = -32004;
|
|
6
|
+
interface McpErrorShape {
|
|
7
|
+
code: number;
|
|
8
|
+
message: string;
|
|
9
|
+
data: {
|
|
10
|
+
apCode: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** AP コードを JSON-RPC error 形 (code + data.apCode) に写像する。 */
|
|
14
|
+
declare function apCodeToJsonRpc(apCode: string, message?: string): McpErrorShape;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Gemini host family の production compatibility contract (#457 / ADR-457)。
|
|
18
|
+
* provider の UI や token を模倣せず、andpipe が生成・検証できる静的な境界だけを表す。
|
|
19
|
+
*/
|
|
20
|
+
declare const GEMINI_MCP_SERVER_NAME: "andpipe";
|
|
21
|
+
declare const GEMINI_ENTERPRISE_CLIENT_MARKER: "gemini_enterprise";
|
|
22
|
+
declare const GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI: "https://vertexaisearch.cloud.google.com/oauth-redirect";
|
|
23
|
+
declare const GEMINI_EXTENSION_GITHUB_TOPIC: "gemini-cli-extension";
|
|
24
|
+
declare const GEMINI_EXTENSION_MANIFEST: "gemini-extension.json";
|
|
25
|
+
declare const GEMINI_SURFACES: readonly ["gemini_cli", "gemini_api", "gemini_enterprise"];
|
|
26
|
+
type GeminiSurface = (typeof GEMINI_SURFACES)[number];
|
|
27
|
+
interface GeminiCompatibilityProfile {
|
|
28
|
+
readonly surface: GeminiSurface;
|
|
29
|
+
readonly transport: "streamable_http";
|
|
30
|
+
readonly serverName: typeof GEMINI_MCP_SERVER_NAME;
|
|
31
|
+
readonly oauthMode: "oauth_discovery_or_static" | "caller_supplied_header" | "confidential_client";
|
|
32
|
+
readonly policyIdentity: "unverified" | "registered_confidential_client";
|
|
33
|
+
readonly confirmation: "andpipe_signed_human_evidence";
|
|
34
|
+
readonly resultContract: "mcp_content_with_text_fallback_and_structured_content";
|
|
35
|
+
readonly maxEnabledActions: number | null;
|
|
36
|
+
readonly lifecycle: "supported" | "preview";
|
|
37
|
+
readonly publicationSurface: "extension_gallery_auto_index" | "direct_remote_mcp_configuration" | "tenant_admin_data_store";
|
|
38
|
+
}
|
|
39
|
+
declare const GEMINI_COMPATIBILITY_PROFILES: Readonly<Record<GeminiSurface, GeminiCompatibilityProfile>>;
|
|
40
|
+
declare function geminiCompatibilityProfile(surface: GeminiSurface): GeminiCompatibilityProfile;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* JSON-RPC 2.0 エンベロープ (MCP は JSON-RPC 2.0 over Streamable HTTP)。
|
|
44
|
+
*
|
|
45
|
+
* ドメイン非依存の純粋層。db / policy / Tool Contract を一切 import しない。SoT 13 / 14.1。
|
|
46
|
+
*/
|
|
47
|
+
/** JSON-RPC 2.0 §5.1 の予約エラーコード。 */
|
|
48
|
+
declare const JSON_RPC_PARSE_ERROR = -32700;
|
|
49
|
+
declare const JSON_RPC_INVALID_REQUEST = -32600;
|
|
50
|
+
declare const JSON_RPC_METHOD_NOT_FOUND = -32601;
|
|
51
|
+
declare const JSON_RPC_INVALID_PARAMS = -32602;
|
|
52
|
+
declare const JSON_RPC_INTERNAL_ERROR = -32603;
|
|
53
|
+
type JsonRpcId = string | number | null;
|
|
54
|
+
interface JsonRpcRequest {
|
|
55
|
+
jsonrpc: "2.0";
|
|
56
|
+
id: JsonRpcId;
|
|
57
|
+
method: string;
|
|
58
|
+
params?: unknown;
|
|
59
|
+
}
|
|
60
|
+
interface JsonRpcSuccess<T> {
|
|
61
|
+
jsonrpc: "2.0";
|
|
62
|
+
id: JsonRpcId;
|
|
63
|
+
result: T;
|
|
64
|
+
}
|
|
65
|
+
interface JsonRpcErrorObject {
|
|
66
|
+
code: number;
|
|
67
|
+
message: string;
|
|
68
|
+
data?: unknown;
|
|
69
|
+
}
|
|
70
|
+
interface JsonRpcError {
|
|
71
|
+
jsonrpc: "2.0";
|
|
72
|
+
id: JsonRpcId;
|
|
73
|
+
error: JsonRpcErrorObject;
|
|
74
|
+
}
|
|
75
|
+
type JsonRpcResponse<T> = JsonRpcSuccess<T> | JsonRpcError;
|
|
76
|
+
/** request の形が JSON-RPC 2.0 でない場合の parse 失敗。code は -32700 / -32600。 */
|
|
77
|
+
declare class JsonRpcParseError extends Error {
|
|
78
|
+
readonly code: number;
|
|
79
|
+
/** 可能なら元 request の id を保持し、エラー応答に載せる。 */
|
|
80
|
+
readonly rpcId: JsonRpcId;
|
|
81
|
+
constructor(code: number, message: string, rpcId?: JsonRpcId);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* unknown を JsonRpcRequest として検証する。
|
|
85
|
+
* @throws JsonRpcParseError 形が不正な場合 (可能なら id を保持)。
|
|
86
|
+
*/
|
|
87
|
+
declare function parseJsonRpcRequest(raw: unknown): JsonRpcRequest;
|
|
88
|
+
/**
|
|
89
|
+
* JSON-RPC notification (id を持たない request) か判定する。notification には応答を返さない。
|
|
90
|
+
* MCP の `notifications/initialized` 等の検出に使う。
|
|
91
|
+
*/
|
|
92
|
+
declare function isJsonRpcNotification(raw: unknown): boolean;
|
|
93
|
+
declare function jsonRpcResult<T>(id: JsonRpcId, result: T): JsonRpcSuccess<T>;
|
|
94
|
+
declare function jsonRpcError(id: JsonRpcId, code: number, message: string, data?: unknown): JsonRpcError;
|
|
95
|
+
|
|
96
|
+
/** MCP tool annotations (`@andpipes/tool-contract` の同名型と構造互換)。 */
|
|
97
|
+
interface McpToolAnnotations {
|
|
98
|
+
title?: string;
|
|
99
|
+
readOnlyHint?: boolean;
|
|
100
|
+
destructiveHint?: boolean;
|
|
101
|
+
idempotentHint?: boolean;
|
|
102
|
+
openWorldHint?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* MCP tool descriptor の wire 形。
|
|
106
|
+
* `@andpipes/tool-contract` の `toMcpDescriptor` 出力と構造互換 (mcp-adapter は依存を持たないため
|
|
107
|
+
* 型を自前定義し、gateway 側で構造的に受け渡す)。
|
|
108
|
+
*/
|
|
109
|
+
interface McpToolDescriptor {
|
|
110
|
+
name: string;
|
|
111
|
+
title?: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
inputSchema: Record<string, unknown>;
|
|
114
|
+
outputSchema?: Record<string, unknown>;
|
|
115
|
+
annotations?: McpToolAnnotations;
|
|
116
|
+
_meta?: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
interface ListToolsResult {
|
|
119
|
+
tools: McpToolDescriptor[];
|
|
120
|
+
}
|
|
121
|
+
/** MCP がネゴシエートする protocol version の既定値 (foundation。client 要求があれば echo する)。 */
|
|
122
|
+
declare const MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
123
|
+
/** MCP `initialize` の result 形 (lifecycle ハンドシェイク)。 */
|
|
124
|
+
interface InitializeResult {
|
|
125
|
+
protocolVersion: string;
|
|
126
|
+
capabilities: Record<string, unknown>;
|
|
127
|
+
serverInfo: {
|
|
128
|
+
name: string;
|
|
129
|
+
version: string;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** tools/call の content block。Phase 1 は text のみ (Widget は structuredContent + textFallback)。 */
|
|
133
|
+
interface McpTextContent {
|
|
134
|
+
type: "text";
|
|
135
|
+
text: string;
|
|
136
|
+
}
|
|
137
|
+
interface CallToolParams {
|
|
138
|
+
name: string;
|
|
139
|
+
arguments: Record<string, unknown>;
|
|
140
|
+
_meta?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
interface CallToolResult {
|
|
143
|
+
content: McpTextContent[];
|
|
144
|
+
structuredContent?: unknown;
|
|
145
|
+
isError?: boolean;
|
|
146
|
+
_meta?: Record<string, unknown>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* `_meta` を構築できない MCP host が signed human confirmation を再送するための予約済み入力 envelope。
|
|
150
|
+
* Gateway は Tool Contract の入力検証より前にこの field を分離し、connector / audit summary へ渡さない。
|
|
151
|
+
*/
|
|
152
|
+
declare const ANDPIPE_CALL_ENVELOPE_ARGUMENT: "_andpipe";
|
|
153
|
+
declare const ANDPIPE_CONFIRMATION_META_KEY: "andpipe.dev/confirmation";
|
|
154
|
+
declare const ANDPIPE_CONFIRMATION_INPUT_PATH: "_andpipe.confirmation";
|
|
155
|
+
interface AndpipeConfirmationEvidence {
|
|
156
|
+
confirmationId: string;
|
|
157
|
+
signature?: string;
|
|
158
|
+
decision?: "rejected";
|
|
159
|
+
}
|
|
160
|
+
interface SplitAndpipeCallArgumentsResult {
|
|
161
|
+
arguments: Record<string, unknown>;
|
|
162
|
+
confirmation: AndpipeConfirmationEvidence | null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Gemini 等が tool arguments として返す `_andpipe.confirmation` を business arguments から分離する。
|
|
166
|
+
* 予約 field が存在するのに exact shape でない場合は、無視せず JSON-RPC invalid params へ倒す。
|
|
167
|
+
*/
|
|
168
|
+
declare function splitAndpipeCallArguments(input: Record<string, unknown>): SplitAndpipeCallArgumentsResult;
|
|
169
|
+
/** Tool descriptor に optional control envelope を加える。元 schema は変更しない。 */
|
|
170
|
+
declare function withAndpipeConfirmationInputSchema(inputSchema: Record<string, unknown>): Record<string, unknown>;
|
|
171
|
+
/** tools/call の params が不正な場合。code は -32602 (invalid params)。 */
|
|
172
|
+
declare class McpProtocolError extends Error {
|
|
173
|
+
readonly code: number;
|
|
174
|
+
constructor(code: number, message: string);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* tools/call の params を検証する。`name` 必須、`arguments` は object (省略時 `{}`)。
|
|
178
|
+
* @throws McpProtocolError 形が不正な場合。
|
|
179
|
+
*/
|
|
180
|
+
declare function parseCallToolParams(params: unknown): CallToolParams;
|
|
181
|
+
|
|
182
|
+
declare const packageName: "@andpipes/mcp-adapter";
|
|
183
|
+
|
|
184
|
+
export { ANDPIPE_CALL_ENVELOPE_ARGUMENT, ANDPIPE_CONFIRMATION_INPUT_PATH, ANDPIPE_CONFIRMATION_META_KEY, AP_JSON_RPC_AUTH, AP_JSON_RPC_DOMAIN, AP_JSON_RPC_POLICY, AP_JSON_RPC_SERVER, type AndpipeConfirmationEvidence, type CallToolParams, type CallToolResult, GEMINI_COMPATIBILITY_PROFILES, GEMINI_ENTERPRISE_CLIENT_MARKER, GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI, GEMINI_EXTENSION_GITHUB_TOPIC, GEMINI_EXTENSION_MANIFEST, GEMINI_MCP_SERVER_NAME, GEMINI_SURFACES, type GeminiCompatibilityProfile, type GeminiSurface, type InitializeResult, JSON_RPC_INTERNAL_ERROR, JSON_RPC_INVALID_PARAMS, JSON_RPC_INVALID_REQUEST, JSON_RPC_METHOD_NOT_FOUND, JSON_RPC_PARSE_ERROR, type JsonRpcError, type JsonRpcErrorObject, type JsonRpcId, JsonRpcParseError, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccess, type ListToolsResult, MCP_PROTOCOL_VERSION, type McpErrorShape, McpProtocolError, type McpTextContent, type McpToolAnnotations, type McpToolDescriptor, type SplitAndpipeCallArgumentsResult, apCodeToJsonRpc, geminiCompatibilityProfile, isJsonRpcNotification, jsonRpcError, jsonRpcResult, packageName, parseCallToolParams, parseJsonRpcRequest, splitAndpipeCallArguments, withAndpipeConfirmationInputSchema };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/** andpipe server error 帯 (-32000〜-32099) の仮割当 (SoT 14.1, 確定要)。 */
|
|
2
|
+
declare const AP_JSON_RPC_AUTH = -32001;
|
|
3
|
+
declare const AP_JSON_RPC_POLICY = -32002;
|
|
4
|
+
declare const AP_JSON_RPC_SERVER = -32003;
|
|
5
|
+
declare const AP_JSON_RPC_DOMAIN = -32004;
|
|
6
|
+
interface McpErrorShape {
|
|
7
|
+
code: number;
|
|
8
|
+
message: string;
|
|
9
|
+
data: {
|
|
10
|
+
apCode: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** AP コードを JSON-RPC error 形 (code + data.apCode) に写像する。 */
|
|
14
|
+
declare function apCodeToJsonRpc(apCode: string, message?: string): McpErrorShape;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Gemini host family の production compatibility contract (#457 / ADR-457)。
|
|
18
|
+
* provider の UI や token を模倣せず、andpipe が生成・検証できる静的な境界だけを表す。
|
|
19
|
+
*/
|
|
20
|
+
declare const GEMINI_MCP_SERVER_NAME: "andpipe";
|
|
21
|
+
declare const GEMINI_ENTERPRISE_CLIENT_MARKER: "gemini_enterprise";
|
|
22
|
+
declare const GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI: "https://vertexaisearch.cloud.google.com/oauth-redirect";
|
|
23
|
+
declare const GEMINI_EXTENSION_GITHUB_TOPIC: "gemini-cli-extension";
|
|
24
|
+
declare const GEMINI_EXTENSION_MANIFEST: "gemini-extension.json";
|
|
25
|
+
declare const GEMINI_SURFACES: readonly ["gemini_cli", "gemini_api", "gemini_enterprise"];
|
|
26
|
+
type GeminiSurface = (typeof GEMINI_SURFACES)[number];
|
|
27
|
+
interface GeminiCompatibilityProfile {
|
|
28
|
+
readonly surface: GeminiSurface;
|
|
29
|
+
readonly transport: "streamable_http";
|
|
30
|
+
readonly serverName: typeof GEMINI_MCP_SERVER_NAME;
|
|
31
|
+
readonly oauthMode: "oauth_discovery_or_static" | "caller_supplied_header" | "confidential_client";
|
|
32
|
+
readonly policyIdentity: "unverified" | "registered_confidential_client";
|
|
33
|
+
readonly confirmation: "andpipe_signed_human_evidence";
|
|
34
|
+
readonly resultContract: "mcp_content_with_text_fallback_and_structured_content";
|
|
35
|
+
readonly maxEnabledActions: number | null;
|
|
36
|
+
readonly lifecycle: "supported" | "preview";
|
|
37
|
+
readonly publicationSurface: "extension_gallery_auto_index" | "direct_remote_mcp_configuration" | "tenant_admin_data_store";
|
|
38
|
+
}
|
|
39
|
+
declare const GEMINI_COMPATIBILITY_PROFILES: Readonly<Record<GeminiSurface, GeminiCompatibilityProfile>>;
|
|
40
|
+
declare function geminiCompatibilityProfile(surface: GeminiSurface): GeminiCompatibilityProfile;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* JSON-RPC 2.0 エンベロープ (MCP は JSON-RPC 2.0 over Streamable HTTP)。
|
|
44
|
+
*
|
|
45
|
+
* ドメイン非依存の純粋層。db / policy / Tool Contract を一切 import しない。SoT 13 / 14.1。
|
|
46
|
+
*/
|
|
47
|
+
/** JSON-RPC 2.0 §5.1 の予約エラーコード。 */
|
|
48
|
+
declare const JSON_RPC_PARSE_ERROR = -32700;
|
|
49
|
+
declare const JSON_RPC_INVALID_REQUEST = -32600;
|
|
50
|
+
declare const JSON_RPC_METHOD_NOT_FOUND = -32601;
|
|
51
|
+
declare const JSON_RPC_INVALID_PARAMS = -32602;
|
|
52
|
+
declare const JSON_RPC_INTERNAL_ERROR = -32603;
|
|
53
|
+
type JsonRpcId = string | number | null;
|
|
54
|
+
interface JsonRpcRequest {
|
|
55
|
+
jsonrpc: "2.0";
|
|
56
|
+
id: JsonRpcId;
|
|
57
|
+
method: string;
|
|
58
|
+
params?: unknown;
|
|
59
|
+
}
|
|
60
|
+
interface JsonRpcSuccess<T> {
|
|
61
|
+
jsonrpc: "2.0";
|
|
62
|
+
id: JsonRpcId;
|
|
63
|
+
result: T;
|
|
64
|
+
}
|
|
65
|
+
interface JsonRpcErrorObject {
|
|
66
|
+
code: number;
|
|
67
|
+
message: string;
|
|
68
|
+
data?: unknown;
|
|
69
|
+
}
|
|
70
|
+
interface JsonRpcError {
|
|
71
|
+
jsonrpc: "2.0";
|
|
72
|
+
id: JsonRpcId;
|
|
73
|
+
error: JsonRpcErrorObject;
|
|
74
|
+
}
|
|
75
|
+
type JsonRpcResponse<T> = JsonRpcSuccess<T> | JsonRpcError;
|
|
76
|
+
/** request の形が JSON-RPC 2.0 でない場合の parse 失敗。code は -32700 / -32600。 */
|
|
77
|
+
declare class JsonRpcParseError extends Error {
|
|
78
|
+
readonly code: number;
|
|
79
|
+
/** 可能なら元 request の id を保持し、エラー応答に載せる。 */
|
|
80
|
+
readonly rpcId: JsonRpcId;
|
|
81
|
+
constructor(code: number, message: string, rpcId?: JsonRpcId);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* unknown を JsonRpcRequest として検証する。
|
|
85
|
+
* @throws JsonRpcParseError 形が不正な場合 (可能なら id を保持)。
|
|
86
|
+
*/
|
|
87
|
+
declare function parseJsonRpcRequest(raw: unknown): JsonRpcRequest;
|
|
88
|
+
/**
|
|
89
|
+
* JSON-RPC notification (id を持たない request) か判定する。notification には応答を返さない。
|
|
90
|
+
* MCP の `notifications/initialized` 等の検出に使う。
|
|
91
|
+
*/
|
|
92
|
+
declare function isJsonRpcNotification(raw: unknown): boolean;
|
|
93
|
+
declare function jsonRpcResult<T>(id: JsonRpcId, result: T): JsonRpcSuccess<T>;
|
|
94
|
+
declare function jsonRpcError(id: JsonRpcId, code: number, message: string, data?: unknown): JsonRpcError;
|
|
95
|
+
|
|
96
|
+
/** MCP tool annotations (`@andpipes/tool-contract` の同名型と構造互換)。 */
|
|
97
|
+
interface McpToolAnnotations {
|
|
98
|
+
title?: string;
|
|
99
|
+
readOnlyHint?: boolean;
|
|
100
|
+
destructiveHint?: boolean;
|
|
101
|
+
idempotentHint?: boolean;
|
|
102
|
+
openWorldHint?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* MCP tool descriptor の wire 形。
|
|
106
|
+
* `@andpipes/tool-contract` の `toMcpDescriptor` 出力と構造互換 (mcp-adapter は依存を持たないため
|
|
107
|
+
* 型を自前定義し、gateway 側で構造的に受け渡す)。
|
|
108
|
+
*/
|
|
109
|
+
interface McpToolDescriptor {
|
|
110
|
+
name: string;
|
|
111
|
+
title?: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
inputSchema: Record<string, unknown>;
|
|
114
|
+
outputSchema?: Record<string, unknown>;
|
|
115
|
+
annotations?: McpToolAnnotations;
|
|
116
|
+
_meta?: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
interface ListToolsResult {
|
|
119
|
+
tools: McpToolDescriptor[];
|
|
120
|
+
}
|
|
121
|
+
/** MCP がネゴシエートする protocol version の既定値 (foundation。client 要求があれば echo する)。 */
|
|
122
|
+
declare const MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
123
|
+
/** MCP `initialize` の result 形 (lifecycle ハンドシェイク)。 */
|
|
124
|
+
interface InitializeResult {
|
|
125
|
+
protocolVersion: string;
|
|
126
|
+
capabilities: Record<string, unknown>;
|
|
127
|
+
serverInfo: {
|
|
128
|
+
name: string;
|
|
129
|
+
version: string;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** tools/call の content block。Phase 1 は text のみ (Widget は structuredContent + textFallback)。 */
|
|
133
|
+
interface McpTextContent {
|
|
134
|
+
type: "text";
|
|
135
|
+
text: string;
|
|
136
|
+
}
|
|
137
|
+
interface CallToolParams {
|
|
138
|
+
name: string;
|
|
139
|
+
arguments: Record<string, unknown>;
|
|
140
|
+
_meta?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
interface CallToolResult {
|
|
143
|
+
content: McpTextContent[];
|
|
144
|
+
structuredContent?: unknown;
|
|
145
|
+
isError?: boolean;
|
|
146
|
+
_meta?: Record<string, unknown>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* `_meta` を構築できない MCP host が signed human confirmation を再送するための予約済み入力 envelope。
|
|
150
|
+
* Gateway は Tool Contract の入力検証より前にこの field を分離し、connector / audit summary へ渡さない。
|
|
151
|
+
*/
|
|
152
|
+
declare const ANDPIPE_CALL_ENVELOPE_ARGUMENT: "_andpipe";
|
|
153
|
+
declare const ANDPIPE_CONFIRMATION_META_KEY: "andpipe.dev/confirmation";
|
|
154
|
+
declare const ANDPIPE_CONFIRMATION_INPUT_PATH: "_andpipe.confirmation";
|
|
155
|
+
interface AndpipeConfirmationEvidence {
|
|
156
|
+
confirmationId: string;
|
|
157
|
+
signature?: string;
|
|
158
|
+
decision?: "rejected";
|
|
159
|
+
}
|
|
160
|
+
interface SplitAndpipeCallArgumentsResult {
|
|
161
|
+
arguments: Record<string, unknown>;
|
|
162
|
+
confirmation: AndpipeConfirmationEvidence | null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Gemini 等が tool arguments として返す `_andpipe.confirmation` を business arguments から分離する。
|
|
166
|
+
* 予約 field が存在するのに exact shape でない場合は、無視せず JSON-RPC invalid params へ倒す。
|
|
167
|
+
*/
|
|
168
|
+
declare function splitAndpipeCallArguments(input: Record<string, unknown>): SplitAndpipeCallArgumentsResult;
|
|
169
|
+
/** Tool descriptor に optional control envelope を加える。元 schema は変更しない。 */
|
|
170
|
+
declare function withAndpipeConfirmationInputSchema(inputSchema: Record<string, unknown>): Record<string, unknown>;
|
|
171
|
+
/** tools/call の params が不正な場合。code は -32602 (invalid params)。 */
|
|
172
|
+
declare class McpProtocolError extends Error {
|
|
173
|
+
readonly code: number;
|
|
174
|
+
constructor(code: number, message: string);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* tools/call の params を検証する。`name` 必須、`arguments` は object (省略時 `{}`)。
|
|
178
|
+
* @throws McpProtocolError 形が不正な場合。
|
|
179
|
+
*/
|
|
180
|
+
declare function parseCallToolParams(params: unknown): CallToolParams;
|
|
181
|
+
|
|
182
|
+
declare const packageName: "@andpipes/mcp-adapter";
|
|
183
|
+
|
|
184
|
+
export { ANDPIPE_CALL_ENVELOPE_ARGUMENT, ANDPIPE_CONFIRMATION_INPUT_PATH, ANDPIPE_CONFIRMATION_META_KEY, AP_JSON_RPC_AUTH, AP_JSON_RPC_DOMAIN, AP_JSON_RPC_POLICY, AP_JSON_RPC_SERVER, type AndpipeConfirmationEvidence, type CallToolParams, type CallToolResult, GEMINI_COMPATIBILITY_PROFILES, GEMINI_ENTERPRISE_CLIENT_MARKER, GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI, GEMINI_EXTENSION_GITHUB_TOPIC, GEMINI_EXTENSION_MANIFEST, GEMINI_MCP_SERVER_NAME, GEMINI_SURFACES, type GeminiCompatibilityProfile, type GeminiSurface, type InitializeResult, JSON_RPC_INTERNAL_ERROR, JSON_RPC_INVALID_PARAMS, JSON_RPC_INVALID_REQUEST, JSON_RPC_METHOD_NOT_FOUND, JSON_RPC_PARSE_ERROR, type JsonRpcError, type JsonRpcErrorObject, type JsonRpcId, JsonRpcParseError, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccess, type ListToolsResult, MCP_PROTOCOL_VERSION, type McpErrorShape, McpProtocolError, type McpTextContent, type McpToolAnnotations, type McpToolDescriptor, type SplitAndpipeCallArgumentsResult, apCodeToJsonRpc, geminiCompatibilityProfile, isJsonRpcNotification, jsonRpcError, jsonRpcResult, packageName, parseCallToolParams, parseJsonRpcRequest, splitAndpipeCallArguments, withAndpipeConfirmationInputSchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// src/jsonrpc.ts
|
|
2
|
+
var JSON_RPC_PARSE_ERROR = -32700;
|
|
3
|
+
var JSON_RPC_INVALID_REQUEST = -32600;
|
|
4
|
+
var JSON_RPC_METHOD_NOT_FOUND = -32601;
|
|
5
|
+
var JSON_RPC_INVALID_PARAMS = -32602;
|
|
6
|
+
var JSON_RPC_INTERNAL_ERROR = -32603;
|
|
7
|
+
var JsonRpcParseError = class extends Error {
|
|
8
|
+
code;
|
|
9
|
+
/** 可能なら元 request の id を保持し、エラー応答に載せる。 */
|
|
10
|
+
rpcId;
|
|
11
|
+
constructor(code, message, rpcId = null) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "JsonRpcParseError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.rpcId = rpcId;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function isJsonRpcId(value) {
|
|
19
|
+
return value === null || typeof value === "string" || typeof value === "number";
|
|
20
|
+
}
|
|
21
|
+
function parseJsonRpcRequest(raw) {
|
|
22
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
23
|
+
throw new JsonRpcParseError(JSON_RPC_INVALID_REQUEST, "request must be a JSON object");
|
|
24
|
+
}
|
|
25
|
+
const obj = raw;
|
|
26
|
+
const id = isJsonRpcId(obj.id) ? obj.id : null;
|
|
27
|
+
if (obj.jsonrpc !== "2.0") {
|
|
28
|
+
throw new JsonRpcParseError(JSON_RPC_INVALID_REQUEST, 'jsonrpc must be "2.0"', id);
|
|
29
|
+
}
|
|
30
|
+
if (typeof obj.method !== "string" || obj.method.length === 0) {
|
|
31
|
+
throw new JsonRpcParseError(JSON_RPC_INVALID_REQUEST, "method must be a non-empty string", id);
|
|
32
|
+
}
|
|
33
|
+
if (!isJsonRpcId(obj.id)) {
|
|
34
|
+
throw new JsonRpcParseError(JSON_RPC_INVALID_REQUEST, "id must be string | number | null");
|
|
35
|
+
}
|
|
36
|
+
return { jsonrpc: "2.0", id: obj.id, method: obj.method, params: obj.params };
|
|
37
|
+
}
|
|
38
|
+
function isJsonRpcNotification(raw) {
|
|
39
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const obj = raw;
|
|
43
|
+
return obj.jsonrpc === "2.0" && typeof obj.method === "string" && obj.id === void 0;
|
|
44
|
+
}
|
|
45
|
+
function jsonRpcResult(id, result) {
|
|
46
|
+
return { jsonrpc: "2.0", id, result };
|
|
47
|
+
}
|
|
48
|
+
function jsonRpcError(id, code, message, data) {
|
|
49
|
+
const error = data === void 0 ? { code, message } : { code, message, data };
|
|
50
|
+
return { jsonrpc: "2.0", id, error };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/errors.ts
|
|
54
|
+
var AP_JSON_RPC_AUTH = -32001;
|
|
55
|
+
var AP_JSON_RPC_POLICY = -32002;
|
|
56
|
+
var AP_JSON_RPC_SERVER = -32003;
|
|
57
|
+
var AP_JSON_RPC_DOMAIN = -32004;
|
|
58
|
+
var JSON_RPC_BY_AP_CODE = {
|
|
59
|
+
AP_AUTH_REQUIRED: AP_JSON_RPC_AUTH,
|
|
60
|
+
AP_INVALID_TOKEN: AP_JSON_RPC_AUTH,
|
|
61
|
+
AP_INVALID_AUDIENCE: AP_JSON_RPC_AUTH,
|
|
62
|
+
AP_INVALID_RESOURCE: AP_JSON_RPC_AUTH,
|
|
63
|
+
AP_INVALID_SCOPE: AP_JSON_RPC_AUTH,
|
|
64
|
+
AP_POLICY_DENIED: AP_JSON_RPC_POLICY,
|
|
65
|
+
AP_PLAN_LIMIT_EXCEEDED: AP_JSON_RPC_POLICY,
|
|
66
|
+
AP_CONFIRMATION_REQUIRED: AP_JSON_RPC_POLICY,
|
|
67
|
+
AP_CONFIRMATION_EXPIRED: AP_JSON_RPC_POLICY,
|
|
68
|
+
AP_CONFIRMATION_REJECTED: AP_JSON_RPC_POLICY,
|
|
69
|
+
AP_CONFLICT: AP_JSON_RPC_POLICY,
|
|
70
|
+
AP_IDEMPOTENCY_KEY_CONFLICT: AP_JSON_RPC_POLICY,
|
|
71
|
+
AP_INVALID_STATE_TRANSITION: AP_JSON_RPC_POLICY,
|
|
72
|
+
AP_CONFIG_DRAFT_REQUIRED: AP_JSON_RPC_POLICY,
|
|
73
|
+
AP_NOT_FOUND: JSON_RPC_METHOD_NOT_FOUND,
|
|
74
|
+
AP_TOOL_NOT_FOUND: JSON_RPC_METHOD_NOT_FOUND,
|
|
75
|
+
AP_TOOL_VERSION_NOT_FOUND: JSON_RPC_METHOD_NOT_FOUND,
|
|
76
|
+
AP_INPUT_INVALID: JSON_RPC_INVALID_PARAMS,
|
|
77
|
+
AP_IDEMPOTENCY_KEY_REQUIRED: JSON_RPC_INVALID_PARAMS,
|
|
78
|
+
AP_SECRET_VALUE_NOT_ALLOWED: JSON_RPC_INVALID_PARAMS,
|
|
79
|
+
AP_RATE_LIMITED: AP_JSON_RPC_SERVER,
|
|
80
|
+
AP_UPSTREAM_AUTH_FAILED: AP_JSON_RPC_SERVER,
|
|
81
|
+
AP_UPSTREAM_TIMEOUT: AP_JSON_RPC_SERVER,
|
|
82
|
+
AP_UPSTREAM_ERROR: AP_JSON_RPC_SERVER,
|
|
83
|
+
AP_REDACTION_FAILED: AP_JSON_RPC_SERVER,
|
|
84
|
+
AP_WIDGET_RENDER_FAILED: AP_JSON_RPC_SERVER,
|
|
85
|
+
AP_OUTPUT_INVALID: JSON_RPC_INTERNAL_ERROR,
|
|
86
|
+
AP_DOMAIN_NOT_VERIFIED: AP_JSON_RPC_DOMAIN
|
|
87
|
+
};
|
|
88
|
+
function apCodeToJsonRpc(apCode, message) {
|
|
89
|
+
const code = JSON_RPC_BY_AP_CODE[apCode] ?? JSON_RPC_INTERNAL_ERROR;
|
|
90
|
+
return { code, message: message ?? apCode, data: { apCode } };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/gemini.ts
|
|
94
|
+
var GEMINI_MCP_SERVER_NAME = "andpipe";
|
|
95
|
+
var GEMINI_ENTERPRISE_CLIENT_MARKER = "gemini_enterprise";
|
|
96
|
+
var GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI = "https://vertexaisearch.cloud.google.com/oauth-redirect";
|
|
97
|
+
var GEMINI_EXTENSION_GITHUB_TOPIC = "gemini-cli-extension";
|
|
98
|
+
var GEMINI_EXTENSION_MANIFEST = "gemini-extension.json";
|
|
99
|
+
var GEMINI_SURFACES = ["gemini_cli", "gemini_api", "gemini_enterprise"];
|
|
100
|
+
var GEMINI_COMPATIBILITY_PROFILES = {
|
|
101
|
+
gemini_cli: {
|
|
102
|
+
surface: "gemini_cli",
|
|
103
|
+
transport: "streamable_http",
|
|
104
|
+
serverName: GEMINI_MCP_SERVER_NAME,
|
|
105
|
+
oauthMode: "oauth_discovery_or_static",
|
|
106
|
+
policyIdentity: "unverified",
|
|
107
|
+
confirmation: "andpipe_signed_human_evidence",
|
|
108
|
+
resultContract: "mcp_content_with_text_fallback_and_structured_content",
|
|
109
|
+
maxEnabledActions: null,
|
|
110
|
+
lifecycle: "supported",
|
|
111
|
+
publicationSurface: "extension_gallery_auto_index"
|
|
112
|
+
},
|
|
113
|
+
gemini_api: {
|
|
114
|
+
surface: "gemini_api",
|
|
115
|
+
transport: "streamable_http",
|
|
116
|
+
serverName: GEMINI_MCP_SERVER_NAME,
|
|
117
|
+
oauthMode: "caller_supplied_header",
|
|
118
|
+
policyIdentity: "unverified",
|
|
119
|
+
confirmation: "andpipe_signed_human_evidence",
|
|
120
|
+
resultContract: "mcp_content_with_text_fallback_and_structured_content",
|
|
121
|
+
maxEnabledActions: null,
|
|
122
|
+
lifecycle: "supported",
|
|
123
|
+
publicationSurface: "direct_remote_mcp_configuration"
|
|
124
|
+
},
|
|
125
|
+
gemini_enterprise: {
|
|
126
|
+
surface: "gemini_enterprise",
|
|
127
|
+
transport: "streamable_http",
|
|
128
|
+
serverName: GEMINI_MCP_SERVER_NAME,
|
|
129
|
+
oauthMode: "confidential_client",
|
|
130
|
+
policyIdentity: "registered_confidential_client",
|
|
131
|
+
confirmation: "andpipe_signed_human_evidence",
|
|
132
|
+
resultContract: "mcp_content_with_text_fallback_and_structured_content",
|
|
133
|
+
maxEnabledActions: 100,
|
|
134
|
+
lifecycle: "preview",
|
|
135
|
+
publicationSurface: "tenant_admin_data_store"
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
function geminiCompatibilityProfile(surface) {
|
|
139
|
+
return GEMINI_COMPATIBILITY_PROFILES[surface];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/tools.ts
|
|
143
|
+
var MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
144
|
+
var ANDPIPE_CALL_ENVELOPE_ARGUMENT = "_andpipe";
|
|
145
|
+
var ANDPIPE_CONFIRMATION_META_KEY = "andpipe.dev/confirmation";
|
|
146
|
+
var ANDPIPE_CONFIRMATION_INPUT_PATH = "_andpipe.confirmation";
|
|
147
|
+
var CONFIRMATION_INPUT_SCHEMA = {
|
|
148
|
+
type: "object",
|
|
149
|
+
description: "Reserved andpipe control envelope. It is removed before business input validation and upstream execution.",
|
|
150
|
+
additionalProperties: false,
|
|
151
|
+
required: ["confirmation"],
|
|
152
|
+
properties: {
|
|
153
|
+
confirmation: {
|
|
154
|
+
oneOf: [
|
|
155
|
+
{
|
|
156
|
+
type: "object",
|
|
157
|
+
additionalProperties: false,
|
|
158
|
+
required: ["confirmationId", "signature"],
|
|
159
|
+
properties: {
|
|
160
|
+
confirmationId: { type: "string", format: "uuid" },
|
|
161
|
+
signature: { type: "string", pattern: "^[a-f0-9]{64}$" }
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
type: "object",
|
|
166
|
+
additionalProperties: false,
|
|
167
|
+
required: ["confirmationId", "decision"],
|
|
168
|
+
properties: {
|
|
169
|
+
confirmationId: { type: "string", format: "uuid" },
|
|
170
|
+
decision: { const: "rejected" }
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
function record(value) {
|
|
178
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
179
|
+
}
|
|
180
|
+
function exactKeys(value, expected) {
|
|
181
|
+
const actual = Object.keys(value).sort();
|
|
182
|
+
const canonical = [...expected].sort();
|
|
183
|
+
return actual.length === canonical.length && actual.every((key, index) => key === canonical[index]);
|
|
184
|
+
}
|
|
185
|
+
function parseConfirmationArgument(raw) {
|
|
186
|
+
const value = record(raw);
|
|
187
|
+
if (!value) return null;
|
|
188
|
+
if (exactKeys(value, ["confirmationId", "signature"]) && typeof value.confirmationId === "string" && typeof value.signature === "string") {
|
|
189
|
+
return { confirmationId: value.confirmationId, signature: value.signature };
|
|
190
|
+
}
|
|
191
|
+
if (exactKeys(value, ["confirmationId", "decision"]) && typeof value.confirmationId === "string" && value.decision === "rejected") {
|
|
192
|
+
return { confirmationId: value.confirmationId, decision: "rejected" };
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
function splitAndpipeCallArguments(input) {
|
|
197
|
+
if (!(ANDPIPE_CALL_ENVELOPE_ARGUMENT in input)) {
|
|
198
|
+
return { arguments: { ...input }, confirmation: null };
|
|
199
|
+
}
|
|
200
|
+
const envelope = record(input[ANDPIPE_CALL_ENVELOPE_ARGUMENT]);
|
|
201
|
+
if (!envelope || !exactKeys(envelope, ["confirmation"])) {
|
|
202
|
+
throw new McpProtocolError(
|
|
203
|
+
JSON_RPC_INVALID_PARAMS,
|
|
204
|
+
"params.arguments._andpipe must contain only a valid confirmation"
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
const confirmation = parseConfirmationArgument(envelope.confirmation);
|
|
208
|
+
if (!confirmation) {
|
|
209
|
+
throw new McpProtocolError(
|
|
210
|
+
JSON_RPC_INVALID_PARAMS,
|
|
211
|
+
"params.arguments._andpipe.confirmation is invalid"
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
const { [ANDPIPE_CALL_ENVELOPE_ARGUMENT]: _reserved, ...businessArguments } = input;
|
|
215
|
+
return { arguments: businessArguments, confirmation };
|
|
216
|
+
}
|
|
217
|
+
function withAndpipeConfirmationInputSchema(inputSchema) {
|
|
218
|
+
const properties = record(inputSchema.properties) ?? {};
|
|
219
|
+
return {
|
|
220
|
+
...inputSchema,
|
|
221
|
+
type: inputSchema.type ?? "object",
|
|
222
|
+
properties: {
|
|
223
|
+
...properties,
|
|
224
|
+
[ANDPIPE_CALL_ENVELOPE_ARGUMENT]: CONFIRMATION_INPUT_SCHEMA
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
var McpProtocolError = class extends Error {
|
|
229
|
+
code;
|
|
230
|
+
constructor(code, message) {
|
|
231
|
+
super(message);
|
|
232
|
+
this.name = "McpProtocolError";
|
|
233
|
+
this.code = code;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
function parseCallToolParams(params) {
|
|
237
|
+
if (typeof params !== "object" || params === null || Array.isArray(params)) {
|
|
238
|
+
throw new McpProtocolError(JSON_RPC_INVALID_PARAMS, "params must be an object");
|
|
239
|
+
}
|
|
240
|
+
const obj = params;
|
|
241
|
+
if (typeof obj.name !== "string" || obj.name.length === 0) {
|
|
242
|
+
throw new McpProtocolError(JSON_RPC_INVALID_PARAMS, "params.name must be a non-empty string");
|
|
243
|
+
}
|
|
244
|
+
const args = obj.arguments;
|
|
245
|
+
if (args !== void 0 && (typeof args !== "object" || args === null || Array.isArray(args))) {
|
|
246
|
+
throw new McpProtocolError(JSON_RPC_INVALID_PARAMS, "params.arguments must be an object");
|
|
247
|
+
}
|
|
248
|
+
const parsed = {
|
|
249
|
+
name: obj.name,
|
|
250
|
+
arguments: args ?? {}
|
|
251
|
+
};
|
|
252
|
+
const meta = obj._meta;
|
|
253
|
+
if (typeof meta === "object" && meta !== null && !Array.isArray(meta)) {
|
|
254
|
+
parsed._meta = meta;
|
|
255
|
+
}
|
|
256
|
+
return parsed;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/index.ts
|
|
260
|
+
var packageName = "@andpipes/mcp-adapter";
|
|
261
|
+
export {
|
|
262
|
+
ANDPIPE_CALL_ENVELOPE_ARGUMENT,
|
|
263
|
+
ANDPIPE_CONFIRMATION_INPUT_PATH,
|
|
264
|
+
ANDPIPE_CONFIRMATION_META_KEY,
|
|
265
|
+
AP_JSON_RPC_AUTH,
|
|
266
|
+
AP_JSON_RPC_DOMAIN,
|
|
267
|
+
AP_JSON_RPC_POLICY,
|
|
268
|
+
AP_JSON_RPC_SERVER,
|
|
269
|
+
GEMINI_COMPATIBILITY_PROFILES,
|
|
270
|
+
GEMINI_ENTERPRISE_CLIENT_MARKER,
|
|
271
|
+
GEMINI_ENTERPRISE_OAUTH_REDIRECT_URI,
|
|
272
|
+
GEMINI_EXTENSION_GITHUB_TOPIC,
|
|
273
|
+
GEMINI_EXTENSION_MANIFEST,
|
|
274
|
+
GEMINI_MCP_SERVER_NAME,
|
|
275
|
+
GEMINI_SURFACES,
|
|
276
|
+
JSON_RPC_INTERNAL_ERROR,
|
|
277
|
+
JSON_RPC_INVALID_PARAMS,
|
|
278
|
+
JSON_RPC_INVALID_REQUEST,
|
|
279
|
+
JSON_RPC_METHOD_NOT_FOUND,
|
|
280
|
+
JSON_RPC_PARSE_ERROR,
|
|
281
|
+
JsonRpcParseError,
|
|
282
|
+
MCP_PROTOCOL_VERSION,
|
|
283
|
+
McpProtocolError,
|
|
284
|
+
apCodeToJsonRpc,
|
|
285
|
+
geminiCompatibilityProfile,
|
|
286
|
+
isJsonRpcNotification,
|
|
287
|
+
jsonRpcError,
|
|
288
|
+
jsonRpcResult,
|
|
289
|
+
packageName,
|
|
290
|
+
parseCallToolParams,
|
|
291
|
+
parseJsonRpcRequest,
|
|
292
|
+
splitAndpipeCallArguments,
|
|
293
|
+
withAndpipeConfirmationInputSchema
|
|
294
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@andpipes/mcp-adapter",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"lint": "biome check .",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"test": "vitest run --passWithNoTests",
|
|
24
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean"
|
|
25
|
+
}
|
|
26
|
+
}
|