@mcp-z/oauth 1.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 +21 -0
- package/README.md +71 -0
- package/dist/cjs/account-utils.d.cts +107 -0
- package/dist/cjs/account-utils.d.ts +107 -0
- package/dist/cjs/account-utils.js +481 -0
- package/dist/cjs/account-utils.js.map +1 -0
- package/dist/cjs/index.d.cts +19 -0
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.js +149 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/jwt-auth.d.cts +53 -0
- package/dist/cjs/jwt-auth.d.ts +53 -0
- package/dist/cjs/jwt-auth.js +417 -0
- package/dist/cjs/jwt-auth.js.map +1 -0
- package/dist/cjs/key-utils.d.cts +131 -0
- package/dist/cjs/key-utils.d.ts +131 -0
- package/dist/cjs/key-utils.js +421 -0
- package/dist/cjs/key-utils.js.map +1 -0
- package/dist/cjs/lib/account-server/index.d.cts +45 -0
- package/dist/cjs/lib/account-server/index.d.ts +45 -0
- package/dist/cjs/lib/account-server/index.js +67 -0
- package/dist/cjs/lib/account-server/index.js.map +1 -0
- package/dist/cjs/lib/account-server/loopback.d.cts +22 -0
- package/dist/cjs/lib/account-server/loopback.d.ts +22 -0
- package/dist/cjs/lib/account-server/loopback.js +778 -0
- package/dist/cjs/lib/account-server/loopback.js.map +1 -0
- package/dist/cjs/lib/account-server/me.d.cts +23 -0
- package/dist/cjs/lib/account-server/me.d.ts +23 -0
- package/dist/cjs/lib/account-server/me.js +412 -0
- package/dist/cjs/lib/account-server/me.js.map +1 -0
- package/dist/cjs/lib/account-server/shared-utils.d.cts +6 -0
- package/dist/cjs/lib/account-server/shared-utils.d.ts +6 -0
- package/dist/cjs/lib/account-server/shared-utils.js +235 -0
- package/dist/cjs/lib/account-server/shared-utils.js.map +1 -0
- package/dist/cjs/lib/account-server/stateless.d.cts +20 -0
- package/dist/cjs/lib/account-server/stateless.d.ts +20 -0
- package/dist/cjs/lib/account-server/stateless.js +32 -0
- package/dist/cjs/lib/account-server/stateless.js.map +1 -0
- package/dist/cjs/lib/account-server/types.d.cts +32 -0
- package/dist/cjs/lib/account-server/types.d.ts +32 -0
- package/dist/cjs/lib/account-server/types.js +7 -0
- package/dist/cjs/lib/account-server/types.js.map +1 -0
- package/dist/cjs/lib/dcr-types.d.cts +126 -0
- package/dist/cjs/lib/dcr-types.d.ts +126 -0
- package/dist/cjs/lib/dcr-types.js +12 -0
- package/dist/cjs/lib/dcr-types.js.map +1 -0
- package/dist/cjs/lib/rfc-metadata-types.d.cts +46 -0
- package/dist/cjs/lib/rfc-metadata-types.d.ts +46 -0
- package/dist/cjs/lib/rfc-metadata-types.js +8 -0
- package/dist/cjs/lib/rfc-metadata-types.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pkce.d.cts +36 -0
- package/dist/cjs/pkce.d.ts +36 -0
- package/dist/cjs/pkce.js +25 -0
- package/dist/cjs/pkce.js.map +1 -0
- package/dist/cjs/sanitizer.d.cts +37 -0
- package/dist/cjs/sanitizer.d.ts +37 -0
- package/dist/cjs/sanitizer.js +407 -0
- package/dist/cjs/sanitizer.js.map +1 -0
- package/dist/cjs/schemas/index.d.cts +36 -0
- package/dist/cjs/schemas/index.d.ts +36 -0
- package/dist/cjs/schemas/index.js +28 -0
- package/dist/cjs/schemas/index.js.map +1 -0
- package/dist/cjs/session-auth.d.cts +79 -0
- package/dist/cjs/session-auth.d.ts +79 -0
- package/dist/cjs/session-auth.js +354 -0
- package/dist/cjs/session-auth.js.map +1 -0
- package/dist/cjs/templates.d.cts +18 -0
- package/dist/cjs/templates.d.ts +18 -0
- package/dist/cjs/templates.js +38 -0
- package/dist/cjs/templates.js.map +1 -0
- package/dist/cjs/types.d.cts +343 -0
- package/dist/cjs/types.d.ts +343 -0
- package/dist/cjs/types.js +210 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/account-utils.d.ts +107 -0
- package/dist/esm/account-utils.js +179 -0
- package/dist/esm/account-utils.js.map +1 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/jwt-auth.d.ts +53 -0
- package/dist/esm/jwt-auth.js +164 -0
- package/dist/esm/jwt-auth.js.map +1 -0
- package/dist/esm/key-utils.d.ts +131 -0
- package/dist/esm/key-utils.js +143 -0
- package/dist/esm/key-utils.js.map +1 -0
- package/dist/esm/lib/account-server/index.d.ts +45 -0
- package/dist/esm/lib/account-server/index.js +41 -0
- package/dist/esm/lib/account-server/index.js.map +1 -0
- package/dist/esm/lib/account-server/loopback.d.ts +22 -0
- package/dist/esm/lib/account-server/loopback.js +372 -0
- package/dist/esm/lib/account-server/loopback.js.map +1 -0
- package/dist/esm/lib/account-server/me.d.ts +23 -0
- package/dist/esm/lib/account-server/me.js +170 -0
- package/dist/esm/lib/account-server/me.js.map +1 -0
- package/dist/esm/lib/account-server/shared-utils.d.ts +6 -0
- package/dist/esm/lib/account-server/shared-utils.js +24 -0
- package/dist/esm/lib/account-server/shared-utils.js.map +1 -0
- package/dist/esm/lib/account-server/stateless.d.ts +20 -0
- package/dist/esm/lib/account-server/stateless.js +25 -0
- package/dist/esm/lib/account-server/stateless.js.map +1 -0
- package/dist/esm/lib/account-server/types.d.ts +32 -0
- package/dist/esm/lib/account-server/types.js +6 -0
- package/dist/esm/lib/account-server/types.js.map +1 -0
- package/dist/esm/lib/dcr-types.d.ts +126 -0
- package/dist/esm/lib/dcr-types.js +13 -0
- package/dist/esm/lib/dcr-types.js.map +1 -0
- package/dist/esm/lib/rfc-metadata-types.d.ts +46 -0
- package/dist/esm/lib/rfc-metadata-types.js +7 -0
- package/dist/esm/lib/rfc-metadata-types.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/pkce.d.ts +36 -0
- package/dist/esm/pkce.js +33 -0
- package/dist/esm/pkce.js.map +1 -0
- package/dist/esm/sanitizer.d.ts +37 -0
- package/dist/esm/sanitizer.js +256 -0
- package/dist/esm/sanitizer.js.map +1 -0
- package/dist/esm/schemas/index.d.ts +36 -0
- package/dist/esm/schemas/index.js +19 -0
- package/dist/esm/schemas/index.js.map +1 -0
- package/dist/esm/session-auth.d.ts +79 -0
- package/dist/esm/session-auth.js +141 -0
- package/dist/esm/session-auth.js.map +1 -0
- package/dist/esm/templates.d.ts +18 -0
- package/dist/esm/templates.js +132 -0
- package/dist/esm/templates.js.map +1 -0
- package/dist/esm/types.d.ts +343 -0
- package/dist/esm/types.js +34 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback OAuth account management tools.
|
|
3
|
+
*
|
|
4
|
+
* Provides account management for LoopbackOAuthProvider (server-managed multi-account).
|
|
5
|
+
* Users can add multiple accounts, switch between them, and manage identities.
|
|
6
|
+
*
|
|
7
|
+
* Tools:
|
|
8
|
+
* - account-me: Show current user identity (email, alias, session expiry)
|
|
9
|
+
* - account-switch: Use account (add if needed, switch if already linked)
|
|
10
|
+
* - account-remove: Remove account and delete tokens
|
|
11
|
+
* - account-list: Show all linked accounts (returns empty array if none)
|
|
12
|
+
*/ "use strict";
|
|
13
|
+
Object.defineProperty(exports, "__esModule", {
|
|
14
|
+
value: true
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "createLoopback", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function() {
|
|
19
|
+
return createLoopback;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
var _types = require("@modelcontextprotocol/sdk/types.js");
|
|
23
|
+
var _zod = require("zod");
|
|
24
|
+
var _accountutilsts = require("../../account-utils.js");
|
|
25
|
+
var _mets = require("./me.js");
|
|
26
|
+
var _sharedutilsts = require("./shared-utils.js");
|
|
27
|
+
function _array_like_to_array(arr, len) {
|
|
28
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
29
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
30
|
+
return arr2;
|
|
31
|
+
}
|
|
32
|
+
function _array_without_holes(arr) {
|
|
33
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
34
|
+
}
|
|
35
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
36
|
+
try {
|
|
37
|
+
var info = gen[key](arg);
|
|
38
|
+
var value = info.value;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
reject(error);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (info.done) {
|
|
44
|
+
resolve(value);
|
|
45
|
+
} else {
|
|
46
|
+
Promise.resolve(value).then(_next, _throw);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function _async_to_generator(fn) {
|
|
50
|
+
return function() {
|
|
51
|
+
var self = this, args = arguments;
|
|
52
|
+
return new Promise(function(resolve, reject) {
|
|
53
|
+
var gen = fn.apply(self, args);
|
|
54
|
+
function _next(value) {
|
|
55
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
56
|
+
}
|
|
57
|
+
function _throw(err) {
|
|
58
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
59
|
+
}
|
|
60
|
+
_next(undefined);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function _define_property(obj, key, value) {
|
|
65
|
+
if (key in obj) {
|
|
66
|
+
Object.defineProperty(obj, key, {
|
|
67
|
+
value: value,
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
obj[key] = value;
|
|
74
|
+
}
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
function _instanceof(left, right) {
|
|
78
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
79
|
+
return !!right[Symbol.hasInstance](left);
|
|
80
|
+
} else {
|
|
81
|
+
return left instanceof right;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function _iterable_to_array(iter) {
|
|
85
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
86
|
+
}
|
|
87
|
+
function _non_iterable_spread() {
|
|
88
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
89
|
+
}
|
|
90
|
+
function _object_spread(target) {
|
|
91
|
+
for(var i = 1; i < arguments.length; i++){
|
|
92
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
93
|
+
var ownKeys = Object.keys(source);
|
|
94
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
95
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
96
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
ownKeys.forEach(function(key) {
|
|
100
|
+
_define_property(target, key, source[key]);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return target;
|
|
104
|
+
}
|
|
105
|
+
function ownKeys(object, enumerableOnly) {
|
|
106
|
+
var keys = Object.keys(object);
|
|
107
|
+
if (Object.getOwnPropertySymbols) {
|
|
108
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
109
|
+
if (enumerableOnly) {
|
|
110
|
+
symbols = symbols.filter(function(sym) {
|
|
111
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
keys.push.apply(keys, symbols);
|
|
115
|
+
}
|
|
116
|
+
return keys;
|
|
117
|
+
}
|
|
118
|
+
function _object_spread_props(target, source) {
|
|
119
|
+
source = source != null ? source : {};
|
|
120
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
121
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
122
|
+
} else {
|
|
123
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
124
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return target;
|
|
128
|
+
}
|
|
129
|
+
function _to_consumable_array(arr) {
|
|
130
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
131
|
+
}
|
|
132
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
133
|
+
if (!o) return;
|
|
134
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
135
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
136
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
137
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
138
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
139
|
+
}
|
|
140
|
+
function _ts_generator(thisArg, body) {
|
|
141
|
+
var f, y, t, _ = {
|
|
142
|
+
label: 0,
|
|
143
|
+
sent: function() {
|
|
144
|
+
if (t[0] & 1) throw t[1];
|
|
145
|
+
return t[1];
|
|
146
|
+
},
|
|
147
|
+
trys: [],
|
|
148
|
+
ops: []
|
|
149
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
150
|
+
return d(g, "next", {
|
|
151
|
+
value: verb(0)
|
|
152
|
+
}), d(g, "throw", {
|
|
153
|
+
value: verb(1)
|
|
154
|
+
}), d(g, "return", {
|
|
155
|
+
value: verb(2)
|
|
156
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
157
|
+
value: function() {
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
}), g;
|
|
161
|
+
function verb(n) {
|
|
162
|
+
return function(v) {
|
|
163
|
+
return step([
|
|
164
|
+
n,
|
|
165
|
+
v
|
|
166
|
+
]);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function step(op) {
|
|
170
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
171
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
172
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
173
|
+
if (y = 0, t) op = [
|
|
174
|
+
op[0] & 2,
|
|
175
|
+
t.value
|
|
176
|
+
];
|
|
177
|
+
switch(op[0]){
|
|
178
|
+
case 0:
|
|
179
|
+
case 1:
|
|
180
|
+
t = op;
|
|
181
|
+
break;
|
|
182
|
+
case 4:
|
|
183
|
+
_.label++;
|
|
184
|
+
return {
|
|
185
|
+
value: op[1],
|
|
186
|
+
done: false
|
|
187
|
+
};
|
|
188
|
+
case 5:
|
|
189
|
+
_.label++;
|
|
190
|
+
y = op[1];
|
|
191
|
+
op = [
|
|
192
|
+
0
|
|
193
|
+
];
|
|
194
|
+
continue;
|
|
195
|
+
case 7:
|
|
196
|
+
op = _.ops.pop();
|
|
197
|
+
_.trys.pop();
|
|
198
|
+
continue;
|
|
199
|
+
default:
|
|
200
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
201
|
+
_ = 0;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
205
|
+
_.label = op[1];
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
209
|
+
_.label = t[1];
|
|
210
|
+
t = op;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
if (t && _.label < t[2]) {
|
|
214
|
+
_.label = t[2];
|
|
215
|
+
_.ops.push(op);
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
if (t[2]) _.ops.pop();
|
|
219
|
+
_.trys.pop();
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
op = body.call(thisArg, _);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
op = [
|
|
225
|
+
6,
|
|
226
|
+
e
|
|
227
|
+
];
|
|
228
|
+
y = 0;
|
|
229
|
+
} finally{
|
|
230
|
+
f = t = 0;
|
|
231
|
+
}
|
|
232
|
+
if (op[0] & 5) throw op[1];
|
|
233
|
+
return {
|
|
234
|
+
value: op[0] ? op[1] : void 0,
|
|
235
|
+
done: true
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function createLoopback(config) {
|
|
240
|
+
var service = config.service, store = config.store, logger = config.logger, auth = config.auth;
|
|
241
|
+
// Create account-me tool
|
|
242
|
+
var meTools = (0, _mets.createAccountMe)({
|
|
243
|
+
service: service,
|
|
244
|
+
store: store,
|
|
245
|
+
logger: logger,
|
|
246
|
+
mode: 'loopback'
|
|
247
|
+
});
|
|
248
|
+
var tools = _to_consumable_array(meTools.tools).concat([
|
|
249
|
+
// account-switch
|
|
250
|
+
{
|
|
251
|
+
name: 'account-switch',
|
|
252
|
+
config: {
|
|
253
|
+
description: "Use ".concat(service, " account (smart mode). If email/alias provided and already linked, switches to it without triggering OAuth. If not linked or no email provided, triggers OAuth browser flow to add account. Returns account email, whether it was newly added, and total account count."),
|
|
254
|
+
inputSchema: {
|
|
255
|
+
email: _zod.z.string().optional().describe('Email address to link (if already linked, switches without OAuth)'),
|
|
256
|
+
alias: _zod.z.string().optional().describe('Optional alias for easy identification')
|
|
257
|
+
},
|
|
258
|
+
outputSchema: {
|
|
259
|
+
result: _zod.z.discriminatedUnion('type', [
|
|
260
|
+
_zod.z.object({
|
|
261
|
+
type: _zod.z.literal('success'),
|
|
262
|
+
email: _zod.z.string(),
|
|
263
|
+
isNew: _zod.z.boolean(),
|
|
264
|
+
totalAccounts: _zod.z.number(),
|
|
265
|
+
message: _zod.z.string()
|
|
266
|
+
})
|
|
267
|
+
])
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
handler: function(args) {
|
|
271
|
+
return _async_to_generator(function() {
|
|
272
|
+
var params, _ref, existingAccounts, email, isNew, accountId, _ref1, existingInfo, accountInfo, result, existingInfo1, accountInfo1, totalAccounts, result1, error, message;
|
|
273
|
+
return _ts_generator(this, function(_state) {
|
|
274
|
+
switch(_state.label){
|
|
275
|
+
case 0:
|
|
276
|
+
params = args;
|
|
277
|
+
_state.label = 1;
|
|
278
|
+
case 1:
|
|
279
|
+
_state.trys.push([
|
|
280
|
+
1,
|
|
281
|
+
16,
|
|
282
|
+
,
|
|
283
|
+
17
|
|
284
|
+
]);
|
|
285
|
+
logger.info("Starting account switch for ".concat(service), {
|
|
286
|
+
email: params.email,
|
|
287
|
+
alias: params.alias
|
|
288
|
+
});
|
|
289
|
+
return [
|
|
290
|
+
4,
|
|
291
|
+
(0, _accountutilsts.getLinkedAccounts)(store, {
|
|
292
|
+
service: service
|
|
293
|
+
})
|
|
294
|
+
];
|
|
295
|
+
case 2:
|
|
296
|
+
existingAccounts = _state.sent();
|
|
297
|
+
if (!params.email) return [
|
|
298
|
+
3,
|
|
299
|
+
8
|
|
300
|
+
];
|
|
301
|
+
return [
|
|
302
|
+
4,
|
|
303
|
+
(0, _sharedutilsts.findAccountByEmailOrAlias)(store, service, params.email)
|
|
304
|
+
];
|
|
305
|
+
case 3:
|
|
306
|
+
accountId = _state.sent();
|
|
307
|
+
if (!accountId) return [
|
|
308
|
+
3,
|
|
309
|
+
8
|
|
310
|
+
];
|
|
311
|
+
// Account already linked - just switch to it
|
|
312
|
+
email = accountId;
|
|
313
|
+
isNew = false;
|
|
314
|
+
logger.info("Account already linked: ".concat(email, ", switching without OAuth"));
|
|
315
|
+
// Set as active account
|
|
316
|
+
return [
|
|
317
|
+
4,
|
|
318
|
+
(0, _accountutilsts.setActiveAccount)(store, {
|
|
319
|
+
service: service,
|
|
320
|
+
accountId: email
|
|
321
|
+
})
|
|
322
|
+
];
|
|
323
|
+
case 4:
|
|
324
|
+
_state.sent();
|
|
325
|
+
if (!params.alias) return [
|
|
326
|
+
3,
|
|
327
|
+
7
|
|
328
|
+
];
|
|
329
|
+
return [
|
|
330
|
+
4,
|
|
331
|
+
(0, _accountutilsts.getAccountInfo)(store, {
|
|
332
|
+
accountId: email,
|
|
333
|
+
service: service
|
|
334
|
+
})
|
|
335
|
+
];
|
|
336
|
+
case 5:
|
|
337
|
+
existingInfo = _state.sent();
|
|
338
|
+
accountInfo = {
|
|
339
|
+
email: email,
|
|
340
|
+
alias: params.alias,
|
|
341
|
+
addedAt: (_ref1 = existingInfo === null || existingInfo === void 0 ? void 0 : existingInfo.addedAt) !== null && _ref1 !== void 0 ? _ref1 : new Date().toISOString()
|
|
342
|
+
};
|
|
343
|
+
return [
|
|
344
|
+
4,
|
|
345
|
+
(0, _accountutilsts.setAccountInfo)(store, {
|
|
346
|
+
accountId: email,
|
|
347
|
+
service: service
|
|
348
|
+
}, accountInfo)
|
|
349
|
+
];
|
|
350
|
+
case 6:
|
|
351
|
+
_state.sent();
|
|
352
|
+
_state.label = 7;
|
|
353
|
+
case 7:
|
|
354
|
+
result = {
|
|
355
|
+
type: 'success',
|
|
356
|
+
email: email,
|
|
357
|
+
isNew: false,
|
|
358
|
+
totalAccounts: existingAccounts.length,
|
|
359
|
+
message: "Account already linked: ".concat(email, ". Set as active account (no OAuth needed).")
|
|
360
|
+
};
|
|
361
|
+
return [
|
|
362
|
+
2,
|
|
363
|
+
{
|
|
364
|
+
content: [
|
|
365
|
+
{
|
|
366
|
+
type: 'text',
|
|
367
|
+
text: JSON.stringify(result, null, 2)
|
|
368
|
+
}
|
|
369
|
+
],
|
|
370
|
+
structuredContent: {
|
|
371
|
+
result: result
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
];
|
|
375
|
+
case 8:
|
|
376
|
+
// Not linked or no email provided - trigger OAuth flow for new account
|
|
377
|
+
// Check if provider supports interactive authentication
|
|
378
|
+
if (!auth.authenticateNewAccount) {
|
|
379
|
+
throw new Error('Account switching requires interactive authentication. ' + 'The current auth provider does not support authenticateNewAccount().');
|
|
380
|
+
}
|
|
381
|
+
return [
|
|
382
|
+
4,
|
|
383
|
+
auth.authenticateNewAccount()
|
|
384
|
+
];
|
|
385
|
+
case 9:
|
|
386
|
+
// Trigger new authentication with account selection
|
|
387
|
+
email = _state.sent();
|
|
388
|
+
// Check if account already exists (in case OAuth returned different email than requested)
|
|
389
|
+
isNew = !existingAccounts.includes(email);
|
|
390
|
+
if (!isNew) return [
|
|
391
|
+
3,
|
|
392
|
+
11
|
|
393
|
+
];
|
|
394
|
+
// Add new account
|
|
395
|
+
return [
|
|
396
|
+
4,
|
|
397
|
+
(0, _accountutilsts.addAccount)(store, {
|
|
398
|
+
service: service,
|
|
399
|
+
accountId: email
|
|
400
|
+
})
|
|
401
|
+
];
|
|
402
|
+
case 10:
|
|
403
|
+
_state.sent();
|
|
404
|
+
logger.info("Added new ".concat(service, " account"), {
|
|
405
|
+
email: email
|
|
406
|
+
});
|
|
407
|
+
return [
|
|
408
|
+
3,
|
|
409
|
+
12
|
|
410
|
+
];
|
|
411
|
+
case 11:
|
|
412
|
+
logger.info("Account already linked: ".concat(email));
|
|
413
|
+
_state.label = 12;
|
|
414
|
+
case 12:
|
|
415
|
+
return [
|
|
416
|
+
4,
|
|
417
|
+
(0, _accountutilsts.getAccountInfo)(store, {
|
|
418
|
+
accountId: email,
|
|
419
|
+
service: service
|
|
420
|
+
})
|
|
421
|
+
];
|
|
422
|
+
case 13:
|
|
423
|
+
existingInfo1 = _state.sent();
|
|
424
|
+
accountInfo1 = _object_spread_props(_object_spread({
|
|
425
|
+
email: email
|
|
426
|
+
}, params.alias ? {
|
|
427
|
+
alias: params.alias
|
|
428
|
+
} : {}), {
|
|
429
|
+
addedAt: isNew ? new Date().toISOString() : (_ref = existingInfo1 === null || existingInfo1 === void 0 ? void 0 : existingInfo1.addedAt) !== null && _ref !== void 0 ? _ref : new Date().toISOString()
|
|
430
|
+
});
|
|
431
|
+
return [
|
|
432
|
+
4,
|
|
433
|
+
(0, _accountutilsts.setAccountInfo)(store, {
|
|
434
|
+
accountId: email,
|
|
435
|
+
service: service
|
|
436
|
+
}, accountInfo1)
|
|
437
|
+
];
|
|
438
|
+
case 14:
|
|
439
|
+
_state.sent();
|
|
440
|
+
// Set as active account
|
|
441
|
+
return [
|
|
442
|
+
4,
|
|
443
|
+
(0, _accountutilsts.setActiveAccount)(store, {
|
|
444
|
+
service: service,
|
|
445
|
+
accountId: email
|
|
446
|
+
})
|
|
447
|
+
];
|
|
448
|
+
case 15:
|
|
449
|
+
_state.sent();
|
|
450
|
+
totalAccounts = isNew ? existingAccounts.length + 1 : existingAccounts.length;
|
|
451
|
+
result1 = {
|
|
452
|
+
type: 'success',
|
|
453
|
+
email: email,
|
|
454
|
+
isNew: isNew,
|
|
455
|
+
totalAccounts: totalAccounts,
|
|
456
|
+
message: isNew ? "Successfully added ".concat(service, " account: ").concat(email, " (").concat(totalAccounts, " total)") : "Account already linked: ".concat(email, ". Set as active account.")
|
|
457
|
+
};
|
|
458
|
+
return [
|
|
459
|
+
2,
|
|
460
|
+
{
|
|
461
|
+
content: [
|
|
462
|
+
{
|
|
463
|
+
type: 'text',
|
|
464
|
+
text: JSON.stringify(result1, null, 2)
|
|
465
|
+
}
|
|
466
|
+
],
|
|
467
|
+
structuredContent: {
|
|
468
|
+
result: result1
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
];
|
|
472
|
+
case 16:
|
|
473
|
+
error = _state.sent();
|
|
474
|
+
message = _instanceof(error, Error) ? error.message : String(error);
|
|
475
|
+
throw new _types.McpError(_types.ErrorCode.InternalError, "Error switching ".concat(service, " account: ").concat(message), {
|
|
476
|
+
stack: _instanceof(error, Error) ? error.stack : undefined
|
|
477
|
+
});
|
|
478
|
+
case 17:
|
|
479
|
+
return [
|
|
480
|
+
2
|
|
481
|
+
];
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
})();
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
// account-remove
|
|
488
|
+
{
|
|
489
|
+
name: 'account-remove',
|
|
490
|
+
config: {
|
|
491
|
+
description: "Remove ".concat(service, " account and delete stored tokens permanently. If removing the active account, the first remaining account becomes active. Requires email or alias parameter."),
|
|
492
|
+
inputSchema: {
|
|
493
|
+
accountId: _zod.z.string().min(1).describe('Email address or alias of account to remove')
|
|
494
|
+
},
|
|
495
|
+
outputSchema: {
|
|
496
|
+
result: _zod.z.discriminatedUnion('type', [
|
|
497
|
+
_zod.z.object({
|
|
498
|
+
type: _zod.z.literal('success'),
|
|
499
|
+
service: _zod.z.string(),
|
|
500
|
+
removed: _zod.z.string(),
|
|
501
|
+
remainingAccounts: _zod.z.number(),
|
|
502
|
+
newActiveAccount: _zod.z.string().optional(),
|
|
503
|
+
message: _zod.z.string()
|
|
504
|
+
})
|
|
505
|
+
])
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
handler: function(args) {
|
|
509
|
+
return _async_to_generator(function() {
|
|
510
|
+
var params, linkedAccounts, accountId, activeAccount, removingActive, remainingAccounts, newActiveAccount, firstRemaining, result, error, message;
|
|
511
|
+
return _ts_generator(this, function(_state) {
|
|
512
|
+
switch(_state.label){
|
|
513
|
+
case 0:
|
|
514
|
+
params = args;
|
|
515
|
+
_state.label = 1;
|
|
516
|
+
case 1:
|
|
517
|
+
_state.trys.push([
|
|
518
|
+
1,
|
|
519
|
+
8,
|
|
520
|
+
,
|
|
521
|
+
9
|
|
522
|
+
]);
|
|
523
|
+
return [
|
|
524
|
+
4,
|
|
525
|
+
(0, _accountutilsts.getLinkedAccounts)(store, {
|
|
526
|
+
service: service
|
|
527
|
+
})
|
|
528
|
+
];
|
|
529
|
+
case 2:
|
|
530
|
+
linkedAccounts = _state.sent();
|
|
531
|
+
if (linkedAccounts.length === 0) {
|
|
532
|
+
throw new Error("No ".concat(service, " accounts to remove"));
|
|
533
|
+
}
|
|
534
|
+
return [
|
|
535
|
+
4,
|
|
536
|
+
(0, _sharedutilsts.findAccountByEmailOrAlias)(store, service, params.accountId)
|
|
537
|
+
];
|
|
538
|
+
case 3:
|
|
539
|
+
accountId = _state.sent();
|
|
540
|
+
if (!accountId) {
|
|
541
|
+
throw new Error("Account not found: ".concat(params.accountId));
|
|
542
|
+
}
|
|
543
|
+
return [
|
|
544
|
+
4,
|
|
545
|
+
(0, _accountutilsts.getActiveAccount)(store, {
|
|
546
|
+
service: service
|
|
547
|
+
})
|
|
548
|
+
];
|
|
549
|
+
case 4:
|
|
550
|
+
activeAccount = _state.sent();
|
|
551
|
+
removingActive = activeAccount === accountId;
|
|
552
|
+
// Remove the account
|
|
553
|
+
return [
|
|
554
|
+
4,
|
|
555
|
+
(0, _accountutilsts.removeAccount)(store, {
|
|
556
|
+
service: service,
|
|
557
|
+
accountId: accountId
|
|
558
|
+
})
|
|
559
|
+
];
|
|
560
|
+
case 5:
|
|
561
|
+
_state.sent();
|
|
562
|
+
remainingAccounts = linkedAccounts.filter(function(id) {
|
|
563
|
+
return id !== accountId;
|
|
564
|
+
});
|
|
565
|
+
if (!(removingActive && remainingAccounts.length > 0)) return [
|
|
566
|
+
3,
|
|
567
|
+
7
|
|
568
|
+
];
|
|
569
|
+
firstRemaining = remainingAccounts[0];
|
|
570
|
+
if (!firstRemaining) return [
|
|
571
|
+
3,
|
|
572
|
+
7
|
|
573
|
+
];
|
|
574
|
+
newActiveAccount = firstRemaining;
|
|
575
|
+
return [
|
|
576
|
+
4,
|
|
577
|
+
(0, _accountutilsts.setActiveAccount)(store, {
|
|
578
|
+
service: service,
|
|
579
|
+
accountId: newActiveAccount
|
|
580
|
+
})
|
|
581
|
+
];
|
|
582
|
+
case 6:
|
|
583
|
+
_state.sent();
|
|
584
|
+
_state.label = 7;
|
|
585
|
+
case 7:
|
|
586
|
+
logger.info("Successfully removed ".concat(service, " account"), {
|
|
587
|
+
accountId: accountId,
|
|
588
|
+
remainingAccounts: remainingAccounts.length
|
|
589
|
+
});
|
|
590
|
+
result = _object_spread_props(_object_spread({
|
|
591
|
+
type: 'success',
|
|
592
|
+
service: service,
|
|
593
|
+
removed: accountId,
|
|
594
|
+
remainingAccounts: remainingAccounts.length
|
|
595
|
+
}, newActiveAccount && {
|
|
596
|
+
newActiveAccount: newActiveAccount
|
|
597
|
+
}), {
|
|
598
|
+
message: "Removed ".concat(service, " account: ").concat(accountId).concat(newActiveAccount ? ". Active account is now: ".concat(newActiveAccount) : '')
|
|
599
|
+
});
|
|
600
|
+
return [
|
|
601
|
+
2,
|
|
602
|
+
{
|
|
603
|
+
content: [
|
|
604
|
+
{
|
|
605
|
+
type: 'text',
|
|
606
|
+
text: JSON.stringify(result, null, 2)
|
|
607
|
+
}
|
|
608
|
+
],
|
|
609
|
+
structuredContent: {
|
|
610
|
+
result: result
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
];
|
|
614
|
+
case 8:
|
|
615
|
+
error = _state.sent();
|
|
616
|
+
message = _instanceof(error, Error) ? error.message : String(error);
|
|
617
|
+
throw new _types.McpError(_types.ErrorCode.InternalError, "Error removing ".concat(service, " account: ").concat(message), {
|
|
618
|
+
stack: _instanceof(error, Error) ? error.stack : undefined
|
|
619
|
+
});
|
|
620
|
+
case 9:
|
|
621
|
+
return [
|
|
622
|
+
2
|
|
623
|
+
];
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
})();
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
// account-list
|
|
630
|
+
{
|
|
631
|
+
name: 'account-list',
|
|
632
|
+
config: {
|
|
633
|
+
description: "List all linked ".concat(service, " accounts with their aliases and active status."),
|
|
634
|
+
inputSchema: {},
|
|
635
|
+
outputSchema: {
|
|
636
|
+
result: _zod.z.discriminatedUnion('type', [
|
|
637
|
+
_zod.z.object({
|
|
638
|
+
type: _zod.z.literal('success'),
|
|
639
|
+
service: _zod.z.string(),
|
|
640
|
+
accounts: _zod.z.array(_zod.z.object({
|
|
641
|
+
email: _zod.z.string(),
|
|
642
|
+
alias: _zod.z.string().optional(),
|
|
643
|
+
isActive: _zod.z.boolean()
|
|
644
|
+
})),
|
|
645
|
+
totalAccounts: _zod.z.number(),
|
|
646
|
+
message: _zod.z.string()
|
|
647
|
+
})
|
|
648
|
+
])
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
handler: function() {
|
|
652
|
+
return _async_to_generator(function() {
|
|
653
|
+
var linkedAccounts, result, activeAccountId, accounts, result1, error, message;
|
|
654
|
+
return _ts_generator(this, function(_state) {
|
|
655
|
+
switch(_state.label){
|
|
656
|
+
case 0:
|
|
657
|
+
_state.trys.push([
|
|
658
|
+
0,
|
|
659
|
+
4,
|
|
660
|
+
,
|
|
661
|
+
5
|
|
662
|
+
]);
|
|
663
|
+
return [
|
|
664
|
+
4,
|
|
665
|
+
(0, _accountutilsts.getLinkedAccounts)(store, {
|
|
666
|
+
service: service
|
|
667
|
+
})
|
|
668
|
+
];
|
|
669
|
+
case 1:
|
|
670
|
+
linkedAccounts = _state.sent();
|
|
671
|
+
// Return empty array gracefully (no error when no accounts)
|
|
672
|
+
if (linkedAccounts.length === 0) {
|
|
673
|
+
result = {
|
|
674
|
+
type: 'success',
|
|
675
|
+
service: service,
|
|
676
|
+
accounts: [],
|
|
677
|
+
totalAccounts: 0,
|
|
678
|
+
message: "No ".concat(service, " accounts linked. Use account-switch to add an account.")
|
|
679
|
+
};
|
|
680
|
+
return [
|
|
681
|
+
2,
|
|
682
|
+
{
|
|
683
|
+
content: [
|
|
684
|
+
{
|
|
685
|
+
type: 'text',
|
|
686
|
+
text: JSON.stringify(result, null, 2)
|
|
687
|
+
}
|
|
688
|
+
],
|
|
689
|
+
structuredContent: {
|
|
690
|
+
result: result
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
];
|
|
694
|
+
}
|
|
695
|
+
return [
|
|
696
|
+
4,
|
|
697
|
+
(0, _accountutilsts.getActiveAccount)(store, {
|
|
698
|
+
service: service
|
|
699
|
+
})
|
|
700
|
+
];
|
|
701
|
+
case 2:
|
|
702
|
+
activeAccountId = _state.sent();
|
|
703
|
+
return [
|
|
704
|
+
4,
|
|
705
|
+
Promise.all(linkedAccounts.map(function(email) {
|
|
706
|
+
return _async_to_generator(function() {
|
|
707
|
+
var accountInfo;
|
|
708
|
+
return _ts_generator(this, function(_state) {
|
|
709
|
+
switch(_state.label){
|
|
710
|
+
case 0:
|
|
711
|
+
return [
|
|
712
|
+
4,
|
|
713
|
+
(0, _accountutilsts.getAccountInfo)(store, {
|
|
714
|
+
accountId: email,
|
|
715
|
+
service: service
|
|
716
|
+
})
|
|
717
|
+
];
|
|
718
|
+
case 1:
|
|
719
|
+
accountInfo = _state.sent();
|
|
720
|
+
return [
|
|
721
|
+
2,
|
|
722
|
+
{
|
|
723
|
+
email: email,
|
|
724
|
+
alias: accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.alias,
|
|
725
|
+
isActive: email === activeAccountId
|
|
726
|
+
}
|
|
727
|
+
];
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
})();
|
|
731
|
+
}))
|
|
732
|
+
];
|
|
733
|
+
case 3:
|
|
734
|
+
accounts = _state.sent();
|
|
735
|
+
result1 = {
|
|
736
|
+
type: 'success',
|
|
737
|
+
service: service,
|
|
738
|
+
accounts: accounts,
|
|
739
|
+
totalAccounts: linkedAccounts.length,
|
|
740
|
+
message: "Found ".concat(linkedAccounts.length, " ").concat(service, " account(s)")
|
|
741
|
+
};
|
|
742
|
+
return [
|
|
743
|
+
2,
|
|
744
|
+
{
|
|
745
|
+
content: [
|
|
746
|
+
{
|
|
747
|
+
type: 'text',
|
|
748
|
+
text: JSON.stringify(result1, null, 2)
|
|
749
|
+
}
|
|
750
|
+
],
|
|
751
|
+
structuredContent: {
|
|
752
|
+
result: result1
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
];
|
|
756
|
+
case 4:
|
|
757
|
+
error = _state.sent();
|
|
758
|
+
message = _instanceof(error, Error) ? error.message : String(error);
|
|
759
|
+
throw new _types.McpError(_types.ErrorCode.InternalError, "Error listing ".concat(service, " accounts: ").concat(message), {
|
|
760
|
+
stack: _instanceof(error, Error) ? error.stack : undefined
|
|
761
|
+
});
|
|
762
|
+
case 5:
|
|
763
|
+
return [
|
|
764
|
+
2
|
|
765
|
+
];
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
})();
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
]);
|
|
772
|
+
var prompts = [];
|
|
773
|
+
return {
|
|
774
|
+
tools: tools,
|
|
775
|
+
prompts: prompts
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|