@mcp-z/client 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/AGENTS.md +159 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/cjs/auth/capability-discovery.d.cts +25 -0
- package/dist/cjs/auth/capability-discovery.d.ts +25 -0
- package/dist/cjs/auth/capability-discovery.js +280 -0
- package/dist/cjs/auth/capability-discovery.js.map +1 -0
- package/dist/cjs/auth/index.d.cts +9 -0
- package/dist/cjs/auth/index.d.ts +9 -0
- package/dist/cjs/auth/index.js +28 -0
- package/dist/cjs/auth/index.js.map +1 -0
- package/dist/cjs/auth/interactive-oauth-flow.d.cts +58 -0
- package/dist/cjs/auth/interactive-oauth-flow.d.ts +58 -0
- package/dist/cjs/auth/interactive-oauth-flow.js +537 -0
- package/dist/cjs/auth/interactive-oauth-flow.js.map +1 -0
- package/dist/cjs/auth/oauth-callback-listener.d.cts +56 -0
- package/dist/cjs/auth/oauth-callback-listener.d.ts +56 -0
- package/dist/cjs/auth/oauth-callback-listener.js +333 -0
- package/dist/cjs/auth/oauth-callback-listener.js.map +1 -0
- package/dist/cjs/auth/pkce.d.cts +17 -0
- package/dist/cjs/auth/pkce.d.ts +17 -0
- package/dist/cjs/auth/pkce.js +192 -0
- package/dist/cjs/auth/pkce.js.map +1 -0
- package/dist/cjs/auth/rfc9728-discovery.d.cts +34 -0
- package/dist/cjs/auth/rfc9728-discovery.d.ts +34 -0
- package/dist/cjs/auth/rfc9728-discovery.js +436 -0
- package/dist/cjs/auth/rfc9728-discovery.js.map +1 -0
- package/dist/cjs/auth/types.d.cts +137 -0
- package/dist/cjs/auth/types.d.ts +137 -0
- package/dist/cjs/auth/types.js +9 -0
- package/dist/cjs/auth/types.js.map +1 -0
- package/dist/cjs/client-helpers.d.cts +55 -0
- package/dist/cjs/client-helpers.d.ts +55 -0
- package/dist/cjs/client-helpers.js +128 -0
- package/dist/cjs/client-helpers.js.map +1 -0
- package/dist/cjs/config/server-loader.d.cts +27 -0
- package/dist/cjs/config/server-loader.d.ts +27 -0
- package/dist/cjs/config/server-loader.js +111 -0
- package/dist/cjs/config/server-loader.js.map +1 -0
- package/dist/cjs/config/validate-config.d.cts +15 -0
- package/dist/cjs/config/validate-config.d.ts +15 -0
- package/dist/cjs/config/validate-config.js +128 -0
- package/dist/cjs/config/validate-config.js.map +1 -0
- package/dist/cjs/connection/connect-client.d.cts +59 -0
- package/dist/cjs/connection/connect-client.d.ts +59 -0
- package/dist/cjs/connection/connect-client.js +536 -0
- package/dist/cjs/connection/connect-client.js.map +1 -0
- package/dist/cjs/connection/existing-process-transport.d.cts +40 -0
- package/dist/cjs/connection/existing-process-transport.d.ts +40 -0
- package/dist/cjs/connection/existing-process-transport.js +274 -0
- package/dist/cjs/connection/existing-process-transport.js.map +1 -0
- package/dist/cjs/connection/types.d.cts +61 -0
- package/dist/cjs/connection/types.d.ts +61 -0
- package/dist/cjs/connection/types.js +53 -0
- package/dist/cjs/connection/types.js.map +1 -0
- package/dist/cjs/connection/wait-for-http-ready.d.cts +15 -0
- package/dist/cjs/connection/wait-for-http-ready.d.ts +15 -0
- package/dist/cjs/connection/wait-for-http-ready.js +232 -0
- package/dist/cjs/connection/wait-for-http-ready.js.map +1 -0
- package/dist/cjs/dcr/dcr-authenticator.d.cts +73 -0
- package/dist/cjs/dcr/dcr-authenticator.d.ts +73 -0
- package/dist/cjs/dcr/dcr-authenticator.js +655 -0
- package/dist/cjs/dcr/dcr-authenticator.js.map +1 -0
- package/dist/cjs/dcr/dynamic-client-registrar.d.cts +28 -0
- package/dist/cjs/dcr/dynamic-client-registrar.d.ts +28 -0
- package/dist/cjs/dcr/dynamic-client-registrar.js +245 -0
- package/dist/cjs/dcr/dynamic-client-registrar.js.map +1 -0
- package/dist/cjs/dcr/index.d.cts +8 -0
- package/dist/cjs/dcr/index.d.ts +8 -0
- package/dist/cjs/dcr/index.js +24 -0
- package/dist/cjs/dcr/index.js.map +1 -0
- package/dist/cjs/index.d.cts +21 -0
- package/dist/cjs/index.d.ts +21 -0
- package/dist/cjs/index.js +94 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/monkey-patches.d.cts +6 -0
- package/dist/cjs/monkey-patches.d.ts +6 -0
- package/dist/cjs/monkey-patches.js +236 -0
- package/dist/cjs/monkey-patches.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/response-wrappers.d.cts +41 -0
- package/dist/cjs/response-wrappers.d.ts +41 -0
- package/dist/cjs/response-wrappers.js +443 -0
- package/dist/cjs/response-wrappers.js.map +1 -0
- package/dist/cjs/search/index.d.cts +6 -0
- package/dist/cjs/search/index.d.ts +6 -0
- package/dist/cjs/search/index.js +25 -0
- package/dist/cjs/search/index.js.map +1 -0
- package/dist/cjs/search/search.d.cts +22 -0
- package/dist/cjs/search/search.d.ts +22 -0
- package/dist/cjs/search/search.js +630 -0
- package/dist/cjs/search/search.js.map +1 -0
- package/dist/cjs/search/types.d.cts +122 -0
- package/dist/cjs/search/types.d.ts +122 -0
- package/dist/cjs/search/types.js +10 -0
- package/dist/cjs/search/types.js.map +1 -0
- package/dist/cjs/spawn/spawn-server.d.cts +83 -0
- package/dist/cjs/spawn/spawn-server.d.ts +83 -0
- package/dist/cjs/spawn/spawn-server.js +410 -0
- package/dist/cjs/spawn/spawn-server.js.map +1 -0
- package/dist/cjs/spawn/spawn-servers.d.cts +151 -0
- package/dist/cjs/spawn/spawn-servers.d.ts +151 -0
- package/dist/cjs/spawn/spawn-servers.js +911 -0
- package/dist/cjs/spawn/spawn-servers.js.map +1 -0
- package/dist/cjs/types.d.cts +11 -0
- package/dist/cjs/types.d.ts +11 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/logger.d.cts +24 -0
- package/dist/cjs/utils/logger.d.ts +24 -0
- package/dist/cjs/utils/logger.js +80 -0
- package/dist/cjs/utils/logger.js.map +1 -0
- package/dist/cjs/utils/path-utils.d.cts +45 -0
- package/dist/cjs/utils/path-utils.d.ts +45 -0
- package/dist/cjs/utils/path-utils.js +158 -0
- package/dist/cjs/utils/path-utils.js.map +1 -0
- package/dist/cjs/utils/sanitizer.d.cts +30 -0
- package/dist/cjs/utils/sanitizer.d.ts +30 -0
- package/dist/cjs/utils/sanitizer.js +124 -0
- package/dist/cjs/utils/sanitizer.js.map +1 -0
- package/dist/esm/auth/capability-discovery.d.ts +25 -0
- package/dist/esm/auth/capability-discovery.js +110 -0
- package/dist/esm/auth/capability-discovery.js.map +1 -0
- package/dist/esm/auth/index.d.ts +9 -0
- package/dist/esm/auth/index.js +6 -0
- package/dist/esm/auth/index.js.map +1 -0
- package/dist/esm/auth/interactive-oauth-flow.d.ts +58 -0
- package/dist/esm/auth/interactive-oauth-flow.js +217 -0
- package/dist/esm/auth/interactive-oauth-flow.js.map +1 -0
- package/dist/esm/auth/oauth-callback-listener.d.ts +56 -0
- package/dist/esm/auth/oauth-callback-listener.js +166 -0
- package/dist/esm/auth/oauth-callback-listener.js.map +1 -0
- package/dist/esm/auth/pkce.d.ts +17 -0
- package/dist/esm/auth/pkce.js +41 -0
- package/dist/esm/auth/pkce.js.map +1 -0
- package/dist/esm/auth/rfc9728-discovery.d.ts +34 -0
- package/dist/esm/auth/rfc9728-discovery.js +157 -0
- package/dist/esm/auth/rfc9728-discovery.js.map +1 -0
- package/dist/esm/auth/types.d.ts +137 -0
- package/dist/esm/auth/types.js +7 -0
- package/dist/esm/auth/types.js.map +1 -0
- package/dist/esm/client-helpers.d.ts +55 -0
- package/dist/esm/client-helpers.js +81 -0
- package/dist/esm/client-helpers.js.map +1 -0
- package/dist/esm/config/server-loader.d.ts +27 -0
- package/dist/esm/config/server-loader.js +49 -0
- package/dist/esm/config/server-loader.js.map +1 -0
- package/dist/esm/config/validate-config.d.ts +15 -0
- package/dist/esm/config/validate-config.js +76 -0
- package/dist/esm/config/validate-config.js.map +1 -0
- package/dist/esm/connection/connect-client.d.ts +59 -0
- package/dist/esm/connection/connect-client.js +272 -0
- package/dist/esm/connection/connect-client.js.map +1 -0
- package/dist/esm/connection/existing-process-transport.d.ts +40 -0
- package/dist/esm/connection/existing-process-transport.js +103 -0
- package/dist/esm/connection/existing-process-transport.js.map +1 -0
- package/dist/esm/connection/types.d.ts +61 -0
- package/dist/esm/connection/types.js +34 -0
- package/dist/esm/connection/types.js.map +1 -0
- package/dist/esm/connection/wait-for-http-ready.d.ts +15 -0
- package/dist/esm/connection/wait-for-http-ready.js +43 -0
- package/dist/esm/connection/wait-for-http-ready.js.map +1 -0
- package/dist/esm/dcr/dcr-authenticator.d.ts +73 -0
- package/dist/esm/dcr/dcr-authenticator.js +235 -0
- package/dist/esm/dcr/dcr-authenticator.js.map +1 -0
- package/dist/esm/dcr/dynamic-client-registrar.d.ts +28 -0
- package/dist/esm/dcr/dynamic-client-registrar.js +66 -0
- package/dist/esm/dcr/dynamic-client-registrar.js.map +1 -0
- package/dist/esm/dcr/index.d.ts +8 -0
- package/dist/esm/dcr/index.js +5 -0
- package/dist/esm/dcr/index.js.map +1 -0
- package/dist/esm/index.d.ts +21 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/monkey-patches.d.ts +6 -0
- package/dist/esm/monkey-patches.js +32 -0
- package/dist/esm/monkey-patches.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/response-wrappers.d.ts +41 -0
- package/dist/esm/response-wrappers.js +201 -0
- package/dist/esm/response-wrappers.js.map +1 -0
- package/dist/esm/search/index.d.ts +6 -0
- package/dist/esm/search/index.js +3 -0
- package/dist/esm/search/index.js.map +1 -0
- package/dist/esm/search/search.d.ts +22 -0
- package/dist/esm/search/search.js +236 -0
- package/dist/esm/search/search.js.map +1 -0
- package/dist/esm/search/types.d.ts +122 -0
- package/dist/esm/search/types.js +8 -0
- package/dist/esm/search/types.js.map +1 -0
- package/dist/esm/spawn/spawn-server.d.ts +83 -0
- package/dist/esm/spawn/spawn-server.js +145 -0
- package/dist/esm/spawn/spawn-server.js.map +1 -0
- package/dist/esm/spawn/spawn-servers.d.ts +151 -0
- package/dist/esm/spawn/spawn-servers.js +406 -0
- package/dist/esm/spawn/spawn-servers.js.map +1 -0
- package/dist/esm/types.d.ts +11 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +24 -0
- package/dist/esm/utils/logger.js +59 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/path-utils.d.ts +45 -0
- package/dist/esm/utils/path-utils.js +89 -0
- package/dist/esm/utils/path-utils.js.map +1 -0
- package/dist/esm/utils/sanitizer.d.ts +30 -0
- package/dist/esm/utils/sanitizer.js +43 -0
- package/dist/esm/utils/sanitizer.js.map +1 -0
- package/package.json +92 -0
- package/schemas/servers.d.ts +90 -0
- package/schemas/servers.schema.json +104 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wait-for-http-ready.ts
|
|
3
|
+
*
|
|
4
|
+
* Utility for waiting for HTTP servers to become ready.
|
|
5
|
+
*/ /**
|
|
6
|
+
* Wait for HTTP server to be ready by checking endpoint accessibility.
|
|
7
|
+
* Used to handle HTTP servers that need time to start listening.
|
|
8
|
+
*
|
|
9
|
+
* @param url - URL to check for server readiness
|
|
10
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 30000)
|
|
11
|
+
* @returns Promise that resolves when server is ready
|
|
12
|
+
* @throws Error if server doesn't become ready within timeout
|
|
13
|
+
*/ "use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "waitForHttpReady", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return waitForHttpReady;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
24
|
+
try {
|
|
25
|
+
var info = gen[key](arg);
|
|
26
|
+
var value = info.value;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
reject(error);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (info.done) {
|
|
32
|
+
resolve(value);
|
|
33
|
+
} else {
|
|
34
|
+
Promise.resolve(value).then(_next, _throw);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function _async_to_generator(fn) {
|
|
38
|
+
return function() {
|
|
39
|
+
var self = this, args = arguments;
|
|
40
|
+
return new Promise(function(resolve, reject) {
|
|
41
|
+
var gen = fn.apply(self, args);
|
|
42
|
+
function _next(value) {
|
|
43
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
44
|
+
}
|
|
45
|
+
function _throw(err) {
|
|
46
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
47
|
+
}
|
|
48
|
+
_next(undefined);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function _ts_generator(thisArg, body) {
|
|
53
|
+
var f, y, t, _ = {
|
|
54
|
+
label: 0,
|
|
55
|
+
sent: function() {
|
|
56
|
+
if (t[0] & 1) throw t[1];
|
|
57
|
+
return t[1];
|
|
58
|
+
},
|
|
59
|
+
trys: [],
|
|
60
|
+
ops: []
|
|
61
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
62
|
+
return d(g, "next", {
|
|
63
|
+
value: verb(0)
|
|
64
|
+
}), d(g, "throw", {
|
|
65
|
+
value: verb(1)
|
|
66
|
+
}), d(g, "return", {
|
|
67
|
+
value: verb(2)
|
|
68
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
69
|
+
value: function() {
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
}), g;
|
|
73
|
+
function verb(n) {
|
|
74
|
+
return function(v) {
|
|
75
|
+
return step([
|
|
76
|
+
n,
|
|
77
|
+
v
|
|
78
|
+
]);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function step(op) {
|
|
82
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
83
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
84
|
+
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;
|
|
85
|
+
if (y = 0, t) op = [
|
|
86
|
+
op[0] & 2,
|
|
87
|
+
t.value
|
|
88
|
+
];
|
|
89
|
+
switch(op[0]){
|
|
90
|
+
case 0:
|
|
91
|
+
case 1:
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
case 4:
|
|
95
|
+
_.label++;
|
|
96
|
+
return {
|
|
97
|
+
value: op[1],
|
|
98
|
+
done: false
|
|
99
|
+
};
|
|
100
|
+
case 5:
|
|
101
|
+
_.label++;
|
|
102
|
+
y = op[1];
|
|
103
|
+
op = [
|
|
104
|
+
0
|
|
105
|
+
];
|
|
106
|
+
continue;
|
|
107
|
+
case 7:
|
|
108
|
+
op = _.ops.pop();
|
|
109
|
+
_.trys.pop();
|
|
110
|
+
continue;
|
|
111
|
+
default:
|
|
112
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
113
|
+
_ = 0;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
117
|
+
_.label = op[1];
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
121
|
+
_.label = t[1];
|
|
122
|
+
t = op;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
if (t && _.label < t[2]) {
|
|
126
|
+
_.label = t[2];
|
|
127
|
+
_.ops.push(op);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (t[2]) _.ops.pop();
|
|
131
|
+
_.trys.pop();
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
op = body.call(thisArg, _);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
op = [
|
|
137
|
+
6,
|
|
138
|
+
e
|
|
139
|
+
];
|
|
140
|
+
y = 0;
|
|
141
|
+
} finally{
|
|
142
|
+
f = t = 0;
|
|
143
|
+
}
|
|
144
|
+
if (op[0] & 5) throw op[1];
|
|
145
|
+
return {
|
|
146
|
+
value: op[0] ? op[1] : void 0,
|
|
147
|
+
done: true
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function waitForHttpReady(url) {
|
|
152
|
+
var timeoutMs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 30000;
|
|
153
|
+
return _async_to_generator(function() {
|
|
154
|
+
var start, maxRetries, i, response, _error, elapsed;
|
|
155
|
+
return _ts_generator(this, function(_state) {
|
|
156
|
+
switch(_state.label){
|
|
157
|
+
case 0:
|
|
158
|
+
start = Date.now();
|
|
159
|
+
maxRetries = Math.ceil(timeoutMs / 100); // Check every 100ms
|
|
160
|
+
i = 0;
|
|
161
|
+
_state.label = 1;
|
|
162
|
+
case 1:
|
|
163
|
+
if (!(i < maxRetries)) return [
|
|
164
|
+
3,
|
|
165
|
+
8
|
|
166
|
+
];
|
|
167
|
+
_state.label = 2;
|
|
168
|
+
case 2:
|
|
169
|
+
_state.trys.push([
|
|
170
|
+
2,
|
|
171
|
+
4,
|
|
172
|
+
,
|
|
173
|
+
5
|
|
174
|
+
]);
|
|
175
|
+
return [
|
|
176
|
+
4,
|
|
177
|
+
fetch(url, {
|
|
178
|
+
method: 'HEAD',
|
|
179
|
+
headers: {
|
|
180
|
+
Connection: 'close'
|
|
181
|
+
},
|
|
182
|
+
signal: AbortSignal.timeout(500)
|
|
183
|
+
})
|
|
184
|
+
];
|
|
185
|
+
case 3:
|
|
186
|
+
response = _state.sent();
|
|
187
|
+
// Server is responding if we get any HTTP status
|
|
188
|
+
if (response.status >= 200 && response.status < 500) {
|
|
189
|
+
return [
|
|
190
|
+
2
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
return [
|
|
194
|
+
3,
|
|
195
|
+
5
|
|
196
|
+
];
|
|
197
|
+
case 4:
|
|
198
|
+
_error = _state.sent();
|
|
199
|
+
// Connection refused, timeout, or network error
|
|
200
|
+
// Server not ready yet, continue polling
|
|
201
|
+
if (i === maxRetries - 1) {
|
|
202
|
+
elapsed = Date.now() - start;
|
|
203
|
+
throw new Error("HTTP server ".concat(url, " not ready after ").concat(elapsed, "ms"));
|
|
204
|
+
}
|
|
205
|
+
return [
|
|
206
|
+
3,
|
|
207
|
+
5
|
|
208
|
+
];
|
|
209
|
+
case 5:
|
|
210
|
+
// Wait before retry
|
|
211
|
+
return [
|
|
212
|
+
4,
|
|
213
|
+
new Promise(function(resolve) {
|
|
214
|
+
return setTimeout(resolve, 100);
|
|
215
|
+
})
|
|
216
|
+
];
|
|
217
|
+
case 6:
|
|
218
|
+
_state.sent();
|
|
219
|
+
_state.label = 7;
|
|
220
|
+
case 7:
|
|
221
|
+
i++;
|
|
222
|
+
return [
|
|
223
|
+
3,
|
|
224
|
+
1
|
|
225
|
+
];
|
|
226
|
+
case 8:
|
|
227
|
+
throw new Error("HTTP server ".concat(url, " not ready after ").concat(timeoutMs, "ms"));
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
})();
|
|
231
|
+
}
|
|
232
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/libs/client/src/connection/wait-for-http-ready.ts"],"sourcesContent":["/**\n * wait-for-http-ready.ts\n *\n * Utility for waiting for HTTP servers to become ready.\n */\n\n/**\n * Wait for HTTP server to be ready by checking endpoint accessibility.\n * Used to handle HTTP servers that need time to start listening.\n *\n * @param url - URL to check for server readiness\n * @param timeoutMs - Maximum time to wait in milliseconds (default: 30000)\n * @returns Promise that resolves when server is ready\n * @throws Error if server doesn't become ready within timeout\n */\nexport async function waitForHttpReady(url: string, timeoutMs = 30000): Promise<void> {\n const start = Date.now();\n const maxRetries = Math.ceil(timeoutMs / 100); // Check every 100ms\n\n for (let i = 0; i < maxRetries; i++) {\n try {\n // Use HEAD request to check server is responding\n const response = await fetch(url, {\n method: 'HEAD',\n headers: { Connection: 'close' },\n signal: AbortSignal.timeout(500), // 500ms per attempt\n });\n\n // Server is responding if we get any HTTP status\n if (response.status >= 200 && response.status < 500) {\n return;\n }\n\n // Server error (5xx) - keep trying as it might still be starting\n } catch (_error) {\n // Connection refused, timeout, or network error\n // Server not ready yet, continue polling\n if (i === maxRetries - 1) {\n const elapsed = Date.now() - start;\n throw new Error(`HTTP server ${url} not ready after ${elapsed}ms`);\n }\n }\n\n // Wait before retry\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n throw new Error(`HTTP server ${url} not ready after ${timeoutMs}ms`);\n}\n"],"names":["waitForHttpReady","url","timeoutMs","start","maxRetries","i","response","_error","elapsed","Date","now","Math","ceil","fetch","method","headers","Connection","signal","AbortSignal","timeout","status","Error","Promise","resolve","setTimeout"],"mappings":"AAAA;;;;CAIC,GAED;;;;;;;;CAQC;;;;+BACqBA;;;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAf,SAAeA,iBAAiBC,GAAW;QAAEC,YAAAA,iEAAY;;YACxDC,OACAC,YAEGC,GAGCC,UAYCC,QAICC;;;;oBAtBNL,QAAQM,KAAKC,GAAG;oBAChBN,aAAaO,KAAKC,IAAI,CAACV,YAAY,MAAM,oBAAoB;oBAE1DG,IAAI;;;yBAAGA,CAAAA,IAAID,UAAS;;;;;;;;;;;;oBAGR;;wBAAMS,MAAMZ,KAAK;4BAChCa,QAAQ;4BACRC,SAAS;gCAAEC,YAAY;4BAAQ;4BAC/BC,QAAQC,YAAYC,OAAO,CAAC;wBAC9B;;;oBAJMb,WAAW;oBAMjB,iDAAiD;oBACjD,IAAIA,SAASc,MAAM,IAAI,OAAOd,SAASc,MAAM,GAAG,KAAK;wBACnD;;;oBACF;;;;;;oBAGOb;oBACP,gDAAgD;oBAChD,yCAAyC;oBACzC,IAAIF,MAAMD,aAAa,GAAG;wBAClBI,UAAUC,KAAKC,GAAG,KAAKP;wBAC7B,MAAM,IAAIkB,MAAM,AAAC,eAAqCb,OAAvBP,KAAI,qBAA2B,OAARO,SAAQ;oBAChE;;;;;;oBAGF,oBAAoB;oBACpB;;wBAAM,IAAIc,QAAQ,SAACC;mCAAYC,WAAWD,SAAS;;;;oBAAnD;;;oBAzB8BlB;;;;;;oBA4BhC,MAAM,IAAIgB,MAAM,AAAC,eAAqCnB,OAAvBD,KAAI,qBAA6B,OAAVC,WAAU;;;IAClE"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DCR Authenticator
|
|
3
|
+
* Consolidates DCR and OAuth flow logic for MCP HTTP servers
|
|
4
|
+
*/
|
|
5
|
+
import Keyv from 'keyv';
|
|
6
|
+
import type { AuthCapabilities, TokenSet } from '../auth/types.js';
|
|
7
|
+
import { type Logger } from '../utils/logger.js';
|
|
8
|
+
/**
|
|
9
|
+
* DcrAuthenticator configuration options
|
|
10
|
+
*/
|
|
11
|
+
export interface DcrAuthenticatorOptions {
|
|
12
|
+
/** Custom Keyv store (for testing) - if not provided, uses default ~/.mcpeasy/tokens.json */
|
|
13
|
+
tokenStore?: Keyv;
|
|
14
|
+
/** Headless mode (don't open browser) */
|
|
15
|
+
headless?: boolean;
|
|
16
|
+
/** Required redirect URI for OAuth callback */
|
|
17
|
+
redirectUri: string;
|
|
18
|
+
/** Optional logger for debug output (defaults to singleton logger) */
|
|
19
|
+
logger?: Logger;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* DcrAuthenticator manages authentication for MCP HTTP servers
|
|
23
|
+
* Handles DCR registration, OAuth flows, and token management
|
|
24
|
+
*/
|
|
25
|
+
export declare class DcrAuthenticator {
|
|
26
|
+
private tokenStore;
|
|
27
|
+
private dcrClient;
|
|
28
|
+
private oauthFlow;
|
|
29
|
+
private headless;
|
|
30
|
+
private redirectUri;
|
|
31
|
+
private logger;
|
|
32
|
+
constructor(options: DcrAuthenticatorOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Detect if server is self-hosted DCR (vs external OAuth provider)
|
|
35
|
+
* Self-hosted servers have their own OAuth endpoints and manage token storage
|
|
36
|
+
*/
|
|
37
|
+
private detectSelfHostedMode;
|
|
38
|
+
/**
|
|
39
|
+
* Ensure server is authenticated, performing DCR and OAuth if needed
|
|
40
|
+
* Proactively refreshes tokens if they're within 5 minutes of expiry
|
|
41
|
+
*
|
|
42
|
+
* @param baseUrl - Base URL of the server (e.g., https://example.com)
|
|
43
|
+
* @param capabilities - Auth capabilities from .well-known endpoint
|
|
44
|
+
* @returns Valid token set ready to use
|
|
45
|
+
*
|
|
46
|
+
* @throws Error if authentication fails
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const authenticator = new DcrAuthenticator({ redirectUri: 'http://localhost:3000/callback' });
|
|
50
|
+
* const tokens = await authenticator.ensureAuthenticated(
|
|
51
|
+
* 'https://example.com',
|
|
52
|
+
* capabilities
|
|
53
|
+
* );
|
|
54
|
+
*/
|
|
55
|
+
ensureAuthenticated(baseUrl: string, capabilities: AuthCapabilities): Promise<TokenSet>;
|
|
56
|
+
/**
|
|
57
|
+
* Handle authentication for self-hosted DCR servers
|
|
58
|
+
* Self-hosted servers manage their own token storage via /oauth/verify
|
|
59
|
+
*/
|
|
60
|
+
private ensureAuthenticatedSelfHosted;
|
|
61
|
+
/**
|
|
62
|
+
* Handle authentication for external OAuth providers (original implementation)
|
|
63
|
+
*/
|
|
64
|
+
private ensureAuthenticatedExternal;
|
|
65
|
+
/**
|
|
66
|
+
* Refresh access token using refresh token
|
|
67
|
+
*/
|
|
68
|
+
private refreshTokens;
|
|
69
|
+
/**
|
|
70
|
+
* Delete stored tokens for a server
|
|
71
|
+
*/
|
|
72
|
+
deleteTokens(baseUrl: string): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DCR Authenticator
|
|
3
|
+
* Consolidates DCR and OAuth flow logic for MCP HTTP servers
|
|
4
|
+
*/
|
|
5
|
+
import Keyv from 'keyv';
|
|
6
|
+
import type { AuthCapabilities, TokenSet } from '../auth/types.js';
|
|
7
|
+
import { type Logger } from '../utils/logger.js';
|
|
8
|
+
/**
|
|
9
|
+
* DcrAuthenticator configuration options
|
|
10
|
+
*/
|
|
11
|
+
export interface DcrAuthenticatorOptions {
|
|
12
|
+
/** Custom Keyv store (for testing) - if not provided, uses default ~/.mcpeasy/tokens.json */
|
|
13
|
+
tokenStore?: Keyv;
|
|
14
|
+
/** Headless mode (don't open browser) */
|
|
15
|
+
headless?: boolean;
|
|
16
|
+
/** Required redirect URI for OAuth callback */
|
|
17
|
+
redirectUri: string;
|
|
18
|
+
/** Optional logger for debug output (defaults to singleton logger) */
|
|
19
|
+
logger?: Logger;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* DcrAuthenticator manages authentication for MCP HTTP servers
|
|
23
|
+
* Handles DCR registration, OAuth flows, and token management
|
|
24
|
+
*/
|
|
25
|
+
export declare class DcrAuthenticator {
|
|
26
|
+
private tokenStore;
|
|
27
|
+
private dcrClient;
|
|
28
|
+
private oauthFlow;
|
|
29
|
+
private headless;
|
|
30
|
+
private redirectUri;
|
|
31
|
+
private logger;
|
|
32
|
+
constructor(options: DcrAuthenticatorOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Detect if server is self-hosted DCR (vs external OAuth provider)
|
|
35
|
+
* Self-hosted servers have their own OAuth endpoints and manage token storage
|
|
36
|
+
*/
|
|
37
|
+
private detectSelfHostedMode;
|
|
38
|
+
/**
|
|
39
|
+
* Ensure server is authenticated, performing DCR and OAuth if needed
|
|
40
|
+
* Proactively refreshes tokens if they're within 5 minutes of expiry
|
|
41
|
+
*
|
|
42
|
+
* @param baseUrl - Base URL of the server (e.g., https://example.com)
|
|
43
|
+
* @param capabilities - Auth capabilities from .well-known endpoint
|
|
44
|
+
* @returns Valid token set ready to use
|
|
45
|
+
*
|
|
46
|
+
* @throws Error if authentication fails
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const authenticator = new DcrAuthenticator({ redirectUri: 'http://localhost:3000/callback' });
|
|
50
|
+
* const tokens = await authenticator.ensureAuthenticated(
|
|
51
|
+
* 'https://example.com',
|
|
52
|
+
* capabilities
|
|
53
|
+
* );
|
|
54
|
+
*/
|
|
55
|
+
ensureAuthenticated(baseUrl: string, capabilities: AuthCapabilities): Promise<TokenSet>;
|
|
56
|
+
/**
|
|
57
|
+
* Handle authentication for self-hosted DCR servers
|
|
58
|
+
* Self-hosted servers manage their own token storage via /oauth/verify
|
|
59
|
+
*/
|
|
60
|
+
private ensureAuthenticatedSelfHosted;
|
|
61
|
+
/**
|
|
62
|
+
* Handle authentication for external OAuth providers (original implementation)
|
|
63
|
+
*/
|
|
64
|
+
private ensureAuthenticatedExternal;
|
|
65
|
+
/**
|
|
66
|
+
* Refresh access token using refresh token
|
|
67
|
+
*/
|
|
68
|
+
private refreshTokens;
|
|
69
|
+
/**
|
|
70
|
+
* Delete stored tokens for a server
|
|
71
|
+
*/
|
|
72
|
+
deleteTokens(baseUrl: string): Promise<void>;
|
|
73
|
+
}
|