@wootsup/mcp 0.1.0 → 0.4.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/CHANGELOG.md +157 -83
- package/README.md +31 -27
- package/SECURITY.md +15 -6
- package/dist/auth/keychain.d.ts +27 -1
- package/dist/auth/keychain.js +48 -2
- package/dist/auth/keychain.js.map +1 -1
- package/dist/catalog/build-catalog.d.ts +31 -0
- package/dist/catalog/build-catalog.js +68 -0
- package/dist/catalog/build-catalog.js.map +1 -0
- package/dist/cli-hint.d.ts +22 -0
- package/dist/cli-hint.js +55 -0
- package/dist/cli-hint.js.map +1 -0
- package/dist/index.js +129 -22
- package/dist/index.js.map +1 -1
- package/dist/install-skill.js +1 -1
- package/dist/modules/apimapper/auto-layout.d.ts +21 -0
- package/dist/modules/apimapper/auto-layout.js +54 -0
- package/dist/modules/apimapper/auto-layout.js.map +1 -0
- package/dist/modules/apimapper/cache.js +25 -17
- package/dist/modules/apimapper/cache.js.map +1 -1
- package/dist/modules/apimapper/client.d.ts +115 -4
- package/dist/modules/apimapper/client.js +699 -304
- package/dist/modules/apimapper/client.js.map +1 -1
- package/dist/modules/apimapper/connections-format.d.ts +31 -1
- package/dist/modules/apimapper/connections-format.js +97 -5
- package/dist/modules/apimapper/connections-format.js.map +1 -1
- package/dist/modules/apimapper/connections.d.ts +9 -7
- package/dist/modules/apimapper/connections.js +449 -127
- package/dist/modules/apimapper/connections.js.map +1 -1
- package/dist/modules/apimapper/credential-sanitizer.d.ts +5 -0
- package/dist/modules/apimapper/credential-sanitizer.js +60 -1
- package/dist/modules/apimapper/credential-sanitizer.js.map +1 -1
- package/dist/modules/apimapper/credentials.js +105 -61
- package/dist/modules/apimapper/credentials.js.map +1 -1
- package/dist/modules/apimapper/diagnose.js +21 -2
- package/dist/modules/apimapper/diagnose.js.map +1 -1
- package/dist/modules/apimapper/elicitation.d.ts +29 -0
- package/dist/modules/apimapper/elicitation.js +62 -0
- package/dist/modules/apimapper/elicitation.js.map +1 -1
- package/dist/modules/apimapper/example-extract.d.ts +13 -0
- package/dist/modules/apimapper/example-extract.js +111 -0
- package/dist/modules/apimapper/example-extract.js.map +1 -0
- package/dist/modules/apimapper/filter-operators.d.ts +24 -0
- package/dist/modules/apimapper/filter-operators.js +103 -0
- package/dist/modules/apimapper/filter-operators.js.map +1 -0
- package/dist/modules/apimapper/flows-format.js +92 -22
- package/dist/modules/apimapper/flows-format.js.map +1 -1
- package/dist/modules/apimapper/flows.d.ts +8 -7
- package/dist/modules/apimapper/flows.js +275 -120
- package/dist/modules/apimapper/flows.js.map +1 -1
- package/dist/modules/apimapper/gateway/advanced-read-tool.d.ts +9 -0
- package/dist/modules/apimapper/gateway/advanced-read-tool.js +172 -0
- package/dist/modules/apimapper/gateway/advanced-read-tool.js.map +1 -0
- package/dist/modules/apimapper/gateway/advanced-tool.js +66 -106
- package/dist/modules/apimapper/gateway/advanced-tool.js.map +1 -1
- package/dist/modules/apimapper/gateway/collect-module-tools.d.ts +17 -0
- package/dist/modules/apimapper/gateway/collect-module-tools.js +44 -0
- package/dist/modules/apimapper/gateway/collect-module-tools.js.map +1 -0
- package/dist/modules/apimapper/gateway/essentials.d.ts +1 -1
- package/dist/modules/apimapper/gateway/essentials.js +21 -2
- package/dist/modules/apimapper/gateway/essentials.js.map +1 -1
- package/dist/modules/apimapper/gateway/gateway-shared.d.ts +21 -0
- package/dist/modules/apimapper/gateway/gateway-shared.js +124 -0
- package/dist/modules/apimapper/gateway/gateway-shared.js.map +1 -0
- package/dist/modules/apimapper/gateway/test-support.d.ts +1 -17
- package/dist/modules/apimapper/gateway/test-support.js +4 -33
- package/dist/modules/apimapper/gateway/test-support.js.map +1 -1
- package/dist/modules/apimapper/get-skill-cores.d.ts +4 -0
- package/dist/modules/apimapper/get-skill-cores.js +220 -0
- package/dist/modules/apimapper/get-skill-cores.js.map +1 -0
- package/dist/modules/apimapper/get-skill.d.ts +1 -1
- package/dist/modules/apimapper/get-skill.js +74 -9
- package/dist/modules/apimapper/get-skill.js.map +1 -1
- package/dist/modules/apimapper/graph-builder.d.ts +85 -2
- package/dist/modules/apimapper/graph-builder.js +151 -15
- package/dist/modules/apimapper/graph-builder.js.map +1 -1
- package/dist/modules/apimapper/graph.js +152 -48
- package/dist/modules/apimapper/graph.js.map +1 -1
- package/dist/modules/apimapper/index.js +27 -13
- package/dist/modules/apimapper/index.js.map +1 -1
- package/dist/modules/apimapper/jmespath-test.d.ts +4 -0
- package/dist/modules/apimapper/jmespath-test.js +152 -0
- package/dist/modules/apimapper/jmespath-test.js.map +1 -0
- package/dist/modules/apimapper/library.js +553 -88
- package/dist/modules/apimapper/library.js.map +1 -1
- package/dist/modules/apimapper/license.js +12 -36
- package/dist/modules/apimapper/license.js.map +1 -1
- package/dist/modules/apimapper/list-footer.d.ts +27 -0
- package/dist/modules/apimapper/list-footer.js +57 -0
- package/dist/modules/apimapper/list-footer.js.map +1 -0
- package/dist/modules/apimapper/local-sources.js +100 -57
- package/dist/modules/apimapper/local-sources.js.map +1 -1
- package/dist/modules/apimapper/mcp-client-identity.d.ts +32 -0
- package/dist/modules/apimapper/mcp-client-identity.js +70 -0
- package/dist/modules/apimapper/mcp-client-identity.js.map +1 -0
- package/dist/modules/apimapper/merge-constants.d.ts +6 -0
- package/dist/modules/apimapper/merge-constants.js +26 -0
- package/dist/modules/apimapper/merge-constants.js.map +1 -0
- package/dist/modules/apimapper/misc.js +13 -27
- package/dist/modules/apimapper/misc.js.map +1 -1
- package/dist/modules/apimapper/node-schema.d.ts +52 -2
- package/dist/modules/apimapper/node-schema.js +95 -4
- package/dist/modules/apimapper/node-schema.js.map +1 -1
- package/dist/modules/apimapper/onboarding.d.ts +59 -1
- package/dist/modules/apimapper/onboarding.js +231 -28
- package/dist/modules/apimapper/onboarding.js.map +1 -1
- package/dist/modules/apimapper/read-cache.d.ts +16 -3
- package/dist/modules/apimapper/read-cache.js +59 -4
- package/dist/modules/apimapper/read-cache.js.map +1 -1
- package/dist/modules/apimapper/render/index.js +26 -5
- package/dist/modules/apimapper/render/index.js.map +1 -1
- package/dist/modules/apimapper/resource-id.d.ts +13 -0
- package/dist/modules/apimapper/resource-id.js +69 -0
- package/dist/modules/apimapper/resource-id.js.map +1 -0
- package/dist/modules/apimapper/schema.js +9 -18
- package/dist/modules/apimapper/schema.js.map +1 -1
- package/dist/modules/apimapper/settings.js +49 -52
- package/dist/modules/apimapper/settings.js.map +1 -1
- package/dist/modules/apimapper/sites-tools.d.ts +29 -0
- package/dist/modules/apimapper/sites-tools.js +165 -0
- package/dist/modules/apimapper/sites-tools.js.map +1 -0
- package/dist/modules/apimapper/tool-result.d.ts +66 -0
- package/dist/modules/apimapper/tool-result.js +125 -0
- package/dist/modules/apimapper/tool-result.js.map +1 -0
- package/dist/modules/apimapper/toolslist-size.d.ts +12 -11
- package/dist/modules/apimapper/toolslist-size.js +34 -21
- package/dist/modules/apimapper/toolslist-size.js.map +1 -1
- package/dist/modules/apimapper/types.d.ts +34 -0
- package/dist/modules/apimapper/types.js +1 -1
- package/dist/modules/apimapper/types.js.map +1 -1
- package/dist/modules/apimapper/whitelist-drift.d.ts +85 -0
- package/dist/modules/apimapper/whitelist-drift.js +375 -0
- package/dist/modules/apimapper/whitelist-drift.js.map +1 -0
- package/dist/modules/apimapper/workflows.js +302 -58
- package/dist/modules/apimapper/workflows.js.map +1 -1
- package/dist/modules/apimapper/yootheme-binding.d.ts +35 -0
- package/dist/modules/apimapper/yootheme-binding.js +267 -0
- package/dist/modules/apimapper/yootheme-binding.js.map +1 -0
- package/dist/platform/index.d.ts +56 -0
- package/dist/platform/index.js +158 -2
- package/dist/platform/index.js.map +1 -1
- package/dist/proxy/bridge.d.ts +35 -0
- package/dist/proxy/bridge.js +129 -0
- package/dist/proxy/bridge.js.map +1 -0
- package/dist/proxy/mode.d.ts +9 -0
- package/dist/proxy/mode.js +20 -0
- package/dist/proxy/mode.js.map +1 -0
- package/dist/setup/detect-clients.d.ts +40 -1
- package/dist/setup/detect-clients.js +148 -1
- package/dist/setup/detect-clients.js.map +1 -1
- package/dist/setup/probe-auth.d.ts +51 -0
- package/dist/setup/probe-auth.js +141 -0
- package/dist/setup/probe-auth.js.map +1 -0
- package/dist/setup/probe-handshake.js +40 -7
- package/dist/setup/probe-handshake.js.map +1 -1
- package/dist/setup/remove-config.d.ts +8 -0
- package/dist/setup/remove-config.js +145 -0
- package/dist/setup/remove-config.js.map +1 -0
- package/dist/setup/uninstall.d.ts +34 -0
- package/dist/setup/uninstall.js +147 -0
- package/dist/setup/uninstall.js.map +1 -0
- package/dist/setup-cli.d.ts +16 -0
- package/dist/setup-cli.js +63 -1
- package/dist/setup-cli.js.map +1 -1
- package/dist/sites/loader.d.ts +48 -0
- package/dist/sites/loader.js +134 -0
- package/dist/sites/loader.js.map +1 -0
- package/dist/sites/schema.d.ts +69 -0
- package/dist/sites/schema.js +71 -0
- package/dist/sites/schema.js.map +1 -0
- package/dist/sites/secret-resolver.d.ts +47 -0
- package/dist/sites/secret-resolver.js +150 -0
- package/dist/sites/secret-resolver.js.map +1 -0
- package/dist/skill-instructions.d.ts +14 -1
- package/dist/skill-instructions.js +35 -6
- package/dist/skill-instructions.js.map +1 -1
- package/dist/transports/stdio.js +4 -4
- package/dist/transports/stdio.js.map +1 -1
- package/dist/uninstall-skill.d.ts +27 -0
- package/dist/uninstall-skill.js +89 -0
- package/dist/uninstall-skill.js.map +1 -0
- package/docs/architecture.md +21 -21
- package/docs/customgraph-internal-migration.md +4 -4
- package/docs/security.md +2 -21
- package/docs/tools.md +40 -12
- package/manifest.json +77 -79
- package/package.json +69 -65
- package/skills/apimapper/SKILL.md +128 -7
- package/skills/apimapper/reference/conditional-style-multi-items.md +114 -0
- package/skills/apimapper/reference/dynamize-existing-layout.md +158 -0
- package/skills/apimapper/reference/jmespath-cookbook.md +241 -0
- package/skills/apimapper/reference/jmespath-pitfalls.md +189 -0
- package/skills/apimapper/reference/joomla.md +1 -1
- package/skills/apimapper/reference/library-template-discovery.md +65 -0
- package/skills/apimapper/reference/merge-two-sources-on-key.md +204 -0
- package/skills/apimapper/reference/oauth.md +143 -52
- package/skills/apimapper/reference/troubleshooting.md +22 -2
- package/skills/apimapper/reference/yootheme-source-to-builder-handoff.md +348 -0
- package/skills/apimapper/reference/yootheme.md +75 -44
- package/dist/auth/oauth-provider.d.ts +0 -68
- package/dist/auth/oauth-provider.js +0 -232
- package/dist/auth/oauth-provider.js.map +0 -1
- package/dist/server-http.d.ts +0 -22
- package/dist/server-http.js +0 -159
- package/dist/server-http.js.map +0 -1
- package/dist/transports/http.d.ts +0 -29
- package/dist/transports/http.js +0 -267
- package/dist/transports/http.js.map +0 -1
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
// src/auth/oauth-provider.ts — Phase 9.2.
|
|
2
|
-
//
|
|
3
|
-
// Minimal in-memory OAuth 2.0 Authorization-Code + PKCE + Dynamic Client
|
|
4
|
-
// Registration (DCR) provider for the remote HTTP MCP transport.
|
|
5
|
-
//
|
|
6
|
-
// References:
|
|
7
|
-
// - RFC 6749 (OAuth 2.0)
|
|
8
|
-
// - RFC 7636 (PKCE)
|
|
9
|
-
// - RFC 7591 (Dynamic Client Registration)
|
|
10
|
-
// - workers-oauth-provider (Cloudflare reference, in-memory variant)
|
|
11
|
-
//
|
|
12
|
-
// Storage backend is process-local Maps with TTL-based expiry — the
|
|
13
|
-
// hosted production service (mcp.wootsup.com) is expected to swap in a
|
|
14
|
-
// persistent backend, but for unit/integration tests + the local DXT
|
|
15
|
-
// bundle, in-memory is sufficient.
|
|
16
|
-
//
|
|
17
|
-
// Security notes:
|
|
18
|
-
// - Tokens are 32 random bytes hex-encoded (no JWT — keeps the surface
|
|
19
|
-
// tiny and prevents misuse of unverified payloads).
|
|
20
|
-
// - Authorization codes are 32 random bytes hex; single-use; bound to
|
|
21
|
-
// client_id + redirect_uri + code_challenge.
|
|
22
|
-
// - PKCE S256 is REQUIRED; "plain" is rejected.
|
|
23
|
-
// - On refresh, the old refresh token is invalidated (rotation).
|
|
24
|
-
import { randomBytes, createHash, timingSafeEqual } from "node:crypto";
|
|
25
|
-
// ── Helpers ────────────────────────────────────────────────────────────
|
|
26
|
-
function randomId(prefix) {
|
|
27
|
-
return `${prefix}${randomBytes(12).toString("hex")}`;
|
|
28
|
-
}
|
|
29
|
-
function randomOpaque() {
|
|
30
|
-
return randomBytes(32).toString("hex");
|
|
31
|
-
}
|
|
32
|
-
/** Constant-time compare to thwart timing oracles on token / verifier lookups. */
|
|
33
|
-
function safeEquals(a, b) {
|
|
34
|
-
const ba = Buffer.from(a);
|
|
35
|
-
const bb = Buffer.from(b);
|
|
36
|
-
if (ba.length !== bb.length)
|
|
37
|
-
return false;
|
|
38
|
-
return timingSafeEqual(ba, bb);
|
|
39
|
-
}
|
|
40
|
-
function s256(input) {
|
|
41
|
-
return createHash("sha256").update(input).digest("base64url");
|
|
42
|
-
}
|
|
43
|
-
// ── Factory ────────────────────────────────────────────────────────────
|
|
44
|
-
export function createOAuthProvider(options = {}) {
|
|
45
|
-
const now = options.now ?? (() => Math.floor(Date.now() / 1000));
|
|
46
|
-
const codeTtl = options.codeTtlSeconds ?? 600;
|
|
47
|
-
const tokenTtl = options.tokenTtlSeconds ?? 86_400;
|
|
48
|
-
const refreshTtl = options.refreshTtlSeconds ?? 7 * 86_400;
|
|
49
|
-
const clients = new Map();
|
|
50
|
-
const codes = new Map();
|
|
51
|
-
const tokens = new Map();
|
|
52
|
-
const refreshes = new Map();
|
|
53
|
-
function registerClient(args) {
|
|
54
|
-
if (!Array.isArray(args.redirect_uris) || args.redirect_uris.length === 0) {
|
|
55
|
-
throw new Error("invalid_redirect_uri: at least one redirect_uri required");
|
|
56
|
-
}
|
|
57
|
-
for (const uri of args.redirect_uris) {
|
|
58
|
-
if (typeof uri !== "string" || uri.length === 0) {
|
|
59
|
-
throw new Error("invalid_redirect_uri");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const reg = {
|
|
63
|
-
client_id: randomId("cli_"),
|
|
64
|
-
client_id_issued_at: now(),
|
|
65
|
-
redirect_uris: [...args.redirect_uris],
|
|
66
|
-
client_name: args.client_name,
|
|
67
|
-
token_endpoint_auth_method: "none", // public client (mobile/native/AI)
|
|
68
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
69
|
-
response_types: ["code"],
|
|
70
|
-
};
|
|
71
|
-
clients.set(reg.client_id, reg);
|
|
72
|
-
return reg;
|
|
73
|
-
}
|
|
74
|
-
function getClient(client_id) {
|
|
75
|
-
return clients.get(client_id) ?? null;
|
|
76
|
-
}
|
|
77
|
-
function issueCode(args) {
|
|
78
|
-
const client = clients.get(args.client_id);
|
|
79
|
-
if (!client)
|
|
80
|
-
throw new Error("unknown_client");
|
|
81
|
-
if (!client.redirect_uris.includes(args.redirect_uri)) {
|
|
82
|
-
throw new Error("invalid_redirect_uri");
|
|
83
|
-
}
|
|
84
|
-
if (!args.code_challenge || typeof args.code_challenge !== "string") {
|
|
85
|
-
throw new Error("invalid_request: code_challenge required");
|
|
86
|
-
}
|
|
87
|
-
if (args.code_challenge_method !== "S256") {
|
|
88
|
-
// Reject "plain" — S256 is mandatory for safety.
|
|
89
|
-
throw new Error("invalid_request: code_challenge_method must be S256");
|
|
90
|
-
}
|
|
91
|
-
const code = randomId("code_");
|
|
92
|
-
codes.set(code, {
|
|
93
|
-
client_id: args.client_id,
|
|
94
|
-
redirect_uri: args.redirect_uri,
|
|
95
|
-
code_challenge: args.code_challenge,
|
|
96
|
-
code_challenge_method: args.code_challenge_method,
|
|
97
|
-
scope: args.scope,
|
|
98
|
-
expires_at: now() + codeTtl,
|
|
99
|
-
used: false,
|
|
100
|
-
});
|
|
101
|
-
return code;
|
|
102
|
-
}
|
|
103
|
-
function exchangeCode(args) {
|
|
104
|
-
const rec = codes.get(args.code);
|
|
105
|
-
if (!rec)
|
|
106
|
-
throw new Error("invalid_grant: code not found");
|
|
107
|
-
if (rec.used)
|
|
108
|
-
throw new Error("invalid_grant: code already used");
|
|
109
|
-
if (rec.expires_at < now())
|
|
110
|
-
throw new Error("invalid_grant: code expired");
|
|
111
|
-
if (rec.client_id !== args.client_id) {
|
|
112
|
-
throw new Error("invalid_grant: client_id mismatch");
|
|
113
|
-
}
|
|
114
|
-
if (rec.redirect_uri !== args.redirect_uri) {
|
|
115
|
-
throw new Error("invalid_grant: redirect_uri mismatch");
|
|
116
|
-
}
|
|
117
|
-
const challengeFromVerifier = s256(args.code_verifier);
|
|
118
|
-
if (!safeEquals(challengeFromVerifier, rec.code_challenge)) {
|
|
119
|
-
throw new Error("invalid_grant: code_verifier mismatch");
|
|
120
|
-
}
|
|
121
|
-
rec.used = true;
|
|
122
|
-
const accessToken = randomOpaque();
|
|
123
|
-
const refreshToken = randomOpaque();
|
|
124
|
-
tokens.set(accessToken, {
|
|
125
|
-
client_id: rec.client_id,
|
|
126
|
-
scope: rec.scope,
|
|
127
|
-
expires_at: now() + tokenTtl,
|
|
128
|
-
});
|
|
129
|
-
refreshes.set(refreshToken, {
|
|
130
|
-
client_id: rec.client_id,
|
|
131
|
-
scope: rec.scope,
|
|
132
|
-
expires_at: now() + refreshTtl,
|
|
133
|
-
revoked: false,
|
|
134
|
-
});
|
|
135
|
-
return {
|
|
136
|
-
access_token: accessToken,
|
|
137
|
-
refresh_token: refreshToken,
|
|
138
|
-
token_type: "Bearer",
|
|
139
|
-
expires_in: tokenTtl,
|
|
140
|
-
scope: rec.scope,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function refreshToken(args) {
|
|
144
|
-
const rec = refreshes.get(args.refresh_token);
|
|
145
|
-
if (!rec)
|
|
146
|
-
throw new Error("invalid_grant: refresh_token not found");
|
|
147
|
-
if (rec.revoked)
|
|
148
|
-
throw new Error("invalid_grant: refresh_token revoked");
|
|
149
|
-
if (rec.expires_at < now()) {
|
|
150
|
-
throw new Error("invalid_grant: refresh_token expired");
|
|
151
|
-
}
|
|
152
|
-
if (rec.client_id !== args.client_id) {
|
|
153
|
-
throw new Error("invalid_grant: client_id mismatch");
|
|
154
|
-
}
|
|
155
|
-
// Rotate: revoke the old refresh token, mint a new pair.
|
|
156
|
-
rec.revoked = true;
|
|
157
|
-
const accessToken = randomOpaque();
|
|
158
|
-
const newRefresh = randomOpaque();
|
|
159
|
-
tokens.set(accessToken, {
|
|
160
|
-
client_id: rec.client_id,
|
|
161
|
-
scope: rec.scope,
|
|
162
|
-
expires_at: now() + tokenTtl,
|
|
163
|
-
});
|
|
164
|
-
refreshes.set(newRefresh, {
|
|
165
|
-
client_id: rec.client_id,
|
|
166
|
-
scope: rec.scope,
|
|
167
|
-
expires_at: now() + refreshTtl,
|
|
168
|
-
revoked: false,
|
|
169
|
-
});
|
|
170
|
-
return {
|
|
171
|
-
access_token: accessToken,
|
|
172
|
-
refresh_token: newRefresh,
|
|
173
|
-
token_type: "Bearer",
|
|
174
|
-
expires_in: tokenTtl,
|
|
175
|
-
scope: rec.scope,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
function verifyAccessToken(token) {
|
|
179
|
-
const rec = tokens.get(token);
|
|
180
|
-
if (!rec)
|
|
181
|
-
return null;
|
|
182
|
-
if (rec.expires_at < now())
|
|
183
|
-
return null;
|
|
184
|
-
return {
|
|
185
|
-
client_id: rec.client_id,
|
|
186
|
-
scope: rec.scope,
|
|
187
|
-
expires_at: rec.expires_at,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function sweep() {
|
|
191
|
-
const t = now();
|
|
192
|
-
let evicted = 0;
|
|
193
|
-
for (const [k, v] of codes) {
|
|
194
|
-
if (v.expires_at < t || v.used) {
|
|
195
|
-
codes.delete(k);
|
|
196
|
-
evicted++;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
for (const [k, v] of tokens) {
|
|
200
|
-
if (v.expires_at < t) {
|
|
201
|
-
tokens.delete(k);
|
|
202
|
-
evicted++;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
for (const [k, v] of refreshes) {
|
|
206
|
-
if (v.expires_at < t || v.revoked) {
|
|
207
|
-
refreshes.delete(k);
|
|
208
|
-
evicted++;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return evicted;
|
|
212
|
-
}
|
|
213
|
-
function stats() {
|
|
214
|
-
return {
|
|
215
|
-
clients: clients.size,
|
|
216
|
-
codes: codes.size,
|
|
217
|
-
tokens: tokens.size,
|
|
218
|
-
refreshes: refreshes.size,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
registerClient,
|
|
223
|
-
getClient,
|
|
224
|
-
issueCode,
|
|
225
|
-
exchangeCode,
|
|
226
|
-
refreshToken,
|
|
227
|
-
verifyAccessToken,
|
|
228
|
-
sweep,
|
|
229
|
-
stats,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
//# sourceMappingURL=oauth-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-provider.js","sourceRoot":"","sources":["../../src/auth/oauth-provider.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,yEAAyE;AACzE,iEAAiE;AACjE,EAAE;AACF,cAAc;AACd,yBAAyB;AACzB,oBAAoB;AACpB,2CAA2C;AAC3C,qEAAqE;AACrE,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,qEAAqE;AACrE,mCAAmC;AACnC,EAAE;AACF,kBAAkB;AAClB,uEAAuE;AACvE,sDAAsD;AACtD,sEAAsE;AACtE,+CAA+C;AAC/C,gDAAgD;AAChD,iEAAiE;AAEjE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmGvE,0EAA0E;AAE1E,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,GAAG,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,WAAW,CAAC,EAAE,CAAC,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AAC;AACJ,CAAC"}
|
package/dist/server-http.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
-
import { type ModuleStatus } from "@getimo/mcp-toolkit";
|
|
4
|
-
import { type McpHandler, type HttpTransportServer } from "./transports/http.js";
|
|
5
|
-
import { type OAuthProvider } from "./auth/oauth-provider.js";
|
|
6
|
-
export interface BootOptions {
|
|
7
|
-
/** TCP port. Default: process.env.APIMAPPER_HTTP_PORT or 8901. */
|
|
8
|
-
port?: number;
|
|
9
|
-
/** Public URL hint for OAuth metadata. */
|
|
10
|
-
publicBaseUrl?: string;
|
|
11
|
-
/** Pluggable MCP handler — defaults to a stub that returns the original JSON-RPC id with an empty result. */
|
|
12
|
-
mcpHandler?: McpHandler;
|
|
13
|
-
}
|
|
14
|
-
export interface BootedHttpServer extends HttpTransportServer {
|
|
15
|
-
oauth: OAuthProvider;
|
|
16
|
-
}
|
|
17
|
-
/** Test-only — exposes the server + module load status for assertions. */
|
|
18
|
-
export declare function _testGetMcpServer(): {
|
|
19
|
-
server: McpServer | null;
|
|
20
|
-
modules: ModuleStatus[];
|
|
21
|
-
};
|
|
22
|
-
export declare function bootHttpServer(options?: BootOptions): Promise<BootedHttpServer>;
|
package/dist/server-http.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// src/server-http.ts — Phase 9.2 HTTP entry point.
|
|
3
|
-
//
|
|
4
|
-
// Boots the http+OAuth transport for the API Mapper MCP server. Used by:
|
|
5
|
-
// - `npm run start:http` (local dev / staging)
|
|
6
|
-
// - the future hosted service at mcp.wootsup.com (Phase 10+)
|
|
7
|
-
//
|
|
8
|
-
// The MCP handler bridges incoming JSON-RPC requests to a real
|
|
9
|
-
// SDK-managed McpServer via `createServer()` + `InMemoryTransport.createLinkedPair()`.
|
|
10
|
-
// Each HTTP request is serialised through the in-memory transport pair so
|
|
11
|
-
// the MCP server's full handler-registry runs (initialize, tools/list,
|
|
12
|
-
// tools/call all dispatch correctly). Tests can pass their own handler
|
|
13
|
-
// stub via `bootHttpServer({ mcpHandler })`.
|
|
14
|
-
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
15
|
-
import { loadModules } from "@getimo/mcp-toolkit";
|
|
16
|
-
import { createHttpTransportServer } from "./transports/http.js";
|
|
17
|
-
import { createOAuthProvider } from "./auth/oauth-provider.js";
|
|
18
|
-
import { createServer } from "./index.js";
|
|
19
|
-
import { apimapperRestModule } from "./modules/apimapper/index.js";
|
|
20
|
-
const DEFAULT_PORT = (() => {
|
|
21
|
-
const env = process.env.APIMAPPER_HTTP_PORT;
|
|
22
|
-
const parsed = env ? Number.parseInt(env, 10) : NaN;
|
|
23
|
-
return Number.isFinite(parsed) ? parsed : 8901;
|
|
24
|
-
})();
|
|
25
|
-
/**
|
|
26
|
-
* Default MCP handler — closes Phase 9.2 "deferred SDK binding" gap
|
|
27
|
-
* (R7 audit finding 2026-05-18).
|
|
28
|
-
*
|
|
29
|
-
* Lazily boots a real McpServer + loads all api-mapper modules + connects
|
|
30
|
-
* it to one end of an InMemoryTransport pair. The HTTP handler-callback
|
|
31
|
-
* sends each incoming JSON-RPC request through the other end and awaits
|
|
32
|
-
* the matching response by id.
|
|
33
|
-
*
|
|
34
|
-
* This makes the HTTP transport functionally equivalent to stdio:
|
|
35
|
-
* initialize, tools/list, tools/call all dispatch through the same
|
|
36
|
-
* McpServer instance + tool registry that the stdio transport uses.
|
|
37
|
-
*/
|
|
38
|
-
let mcpHandlerSingleton = null;
|
|
39
|
-
let mcpServerSingleton = null;
|
|
40
|
-
let mcpModuleStatuses = [];
|
|
41
|
-
async function getDefaultMcpHandler() {
|
|
42
|
-
if (mcpHandlerSingleton)
|
|
43
|
-
return mcpHandlerSingleton;
|
|
44
|
-
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
45
|
-
const server = createServer();
|
|
46
|
-
mcpServerSingleton = server;
|
|
47
|
-
mcpModuleStatuses = await loadModules(server, [apimapperRestModule]);
|
|
48
|
-
await server.connect(serverTransport);
|
|
49
|
-
// The client end stays open for the lifetime of the HTTP server. Each
|
|
50
|
-
// HTTP request sends a JSON-RPC message in and registers a one-shot
|
|
51
|
-
// resolver keyed on the JSON-RPC id; the McpServer's reply lands on
|
|
52
|
-
// clientTransport.onmessage and resolves the matching pending promise.
|
|
53
|
-
await clientTransport.start();
|
|
54
|
-
const pending = new Map();
|
|
55
|
-
clientTransport.onmessage = (message) => {
|
|
56
|
-
const m = message;
|
|
57
|
-
if (m && m.id !== undefined && pending.has(m.id)) {
|
|
58
|
-
const resolve = pending.get(m.id);
|
|
59
|
-
pending.delete(m.id);
|
|
60
|
-
resolve(message);
|
|
61
|
-
}
|
|
62
|
-
// Server-initiated notifications (no id) are intentionally dropped —
|
|
63
|
-
// the HTTP transport is request/response only.
|
|
64
|
-
};
|
|
65
|
-
mcpHandlerSingleton = async (body) => {
|
|
66
|
-
const req = body;
|
|
67
|
-
// Notifications carry no id and expect no response. Forward + return
|
|
68
|
-
// 202-like empty body to caller.
|
|
69
|
-
if (req.id === undefined) {
|
|
70
|
-
try {
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK message type is broader
|
|
72
|
-
await clientTransport.send(body);
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
/* ignore — notification fire-and-forget */
|
|
76
|
-
}
|
|
77
|
-
return { jsonrpc: "2.0", result: { ok: true } };
|
|
78
|
-
}
|
|
79
|
-
// Request/response: register resolver, send, await reply.
|
|
80
|
-
return new Promise((resolve) => {
|
|
81
|
-
const timer = setTimeout(() => {
|
|
82
|
-
if (pending.has(req.id)) {
|
|
83
|
-
pending.delete(req.id);
|
|
84
|
-
resolve({
|
|
85
|
-
jsonrpc: "2.0",
|
|
86
|
-
id: req.id,
|
|
87
|
-
error: { code: -32000, message: "HTTP→MCP dispatch timed out after 30s" },
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}, 30_000);
|
|
91
|
-
pending.set(req.id, (msg) => {
|
|
92
|
-
clearTimeout(timer);
|
|
93
|
-
resolve(msg);
|
|
94
|
-
});
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK message type is broader
|
|
96
|
-
void clientTransport.send(body).catch((err) => {
|
|
97
|
-
clearTimeout(timer);
|
|
98
|
-
pending.delete(req.id);
|
|
99
|
-
resolve({
|
|
100
|
-
jsonrpc: "2.0",
|
|
101
|
-
id: req.id,
|
|
102
|
-
error: { code: -32603, message: `dispatch failed: ${err.message}` },
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
return mcpHandlerSingleton;
|
|
108
|
-
}
|
|
109
|
-
/** Test-only — exposes the server + module load status for assertions. */
|
|
110
|
-
export function _testGetMcpServer() {
|
|
111
|
-
return { server: mcpServerSingleton, modules: mcpModuleStatuses };
|
|
112
|
-
}
|
|
113
|
-
export async function bootHttpServer(options = {}) {
|
|
114
|
-
const port = options.port ?? DEFAULT_PORT;
|
|
115
|
-
const oauth = createOAuthProvider();
|
|
116
|
-
const mcpHandler = options.mcpHandler ?? (await getDefaultMcpHandler());
|
|
117
|
-
const transport = await createHttpTransportServer({
|
|
118
|
-
port,
|
|
119
|
-
oauth,
|
|
120
|
-
mcpHandler,
|
|
121
|
-
publicBaseUrl: options.publicBaseUrl,
|
|
122
|
-
});
|
|
123
|
-
return { ...transport, oauth };
|
|
124
|
-
}
|
|
125
|
-
// ── CLI entry ──────────────────────────────────────────────────────────
|
|
126
|
-
// Only auto-boot when this file is executed as the process entrypoint
|
|
127
|
-
// (i.e. `node dist/server-http.js`), never when imported by tests.
|
|
128
|
-
const isEntry = (() => {
|
|
129
|
-
if (typeof process.argv[1] !== "string")
|
|
130
|
-
return false;
|
|
131
|
-
// import.meta.url is a file:// URL; argv[1] is a path. Map both to
|
|
132
|
-
// a comparable form.
|
|
133
|
-
try {
|
|
134
|
-
const argvUrl = new URL(`file://${process.argv[1]}`).href;
|
|
135
|
-
return argvUrl === import.meta.url;
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
})();
|
|
141
|
-
if (isEntry) {
|
|
142
|
-
bootHttpServer()
|
|
143
|
-
.then((s) => {
|
|
144
|
-
// eslint-disable-next-line no-console -- intentional startup log
|
|
145
|
-
console.error(`[apimapper-mcp] HTTP transport listening on ${s.url}`);
|
|
146
|
-
const shutdown = async () => {
|
|
147
|
-
await s.close();
|
|
148
|
-
process.exit(0);
|
|
149
|
-
};
|
|
150
|
-
process.on("SIGTERM", shutdown);
|
|
151
|
-
process.on("SIGINT", shutdown);
|
|
152
|
-
})
|
|
153
|
-
.catch((err) => {
|
|
154
|
-
// eslint-disable-next-line no-console -- intentional fatal log
|
|
155
|
-
console.error("[apimapper-mcp] HTTP boot failed:", err);
|
|
156
|
-
process.exit(1);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
//# sourceMappingURL=server-http.js.map
|
package/dist/server-http.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server-http.js","sourceRoot":"","sources":["../src/server-http.ts"],"names":[],"mappings":";AACA,mDAAmD;AACnD,EAAE;AACF,yEAAyE;AACzE,iDAAiD;AACjD,+DAA+D;AAC/D,EAAE;AACF,+DAA+D;AAC/D,uFAAuF;AACvF,0EAA0E;AAC1E,uEAAuE;AACvE,uEAAuE;AACvE,6CAA6C;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAqB,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAA6C,MAAM,sBAAsB,CAAC;AAC5G,OAAO,EAAE,mBAAmB,EAAsB,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,YAAY,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
-
import { type Server } from "node:http";
|
|
2
|
-
import type { OAuthProvider } from "../auth/oauth-provider.js";
|
|
3
|
-
export interface HttpAuthInfo {
|
|
4
|
-
client_id: string;
|
|
5
|
-
scope: string;
|
|
6
|
-
}
|
|
7
|
-
export type McpHandler = (body: unknown, authInfo: HttpAuthInfo | null) => Promise<unknown>;
|
|
8
|
-
export interface HttpTransportOptions {
|
|
9
|
-
/** TCP port to bind. Use 0 for an ephemeral port. */
|
|
10
|
-
port: number;
|
|
11
|
-
/** OAuth provider state — typically a singleton per process. */
|
|
12
|
-
oauth: OAuthProvider;
|
|
13
|
-
/** MCP routing callback. Receives parsed JSON body + auth info. */
|
|
14
|
-
mcpHandler: McpHandler;
|
|
15
|
-
/**
|
|
16
|
-
* Public base URL used in OAuth metadata. Default: derived from the
|
|
17
|
-
* bound address (`http://127.0.0.1:<port>`).
|
|
18
|
-
*/
|
|
19
|
-
publicBaseUrl?: string;
|
|
20
|
-
}
|
|
21
|
-
export interface HttpTransportServer {
|
|
22
|
-
/** http.Server instance. */
|
|
23
|
-
server: Server;
|
|
24
|
-
/** Resolved base URL (with port). */
|
|
25
|
-
url: string;
|
|
26
|
-
/** Stop accepting new connections + close existing keep-alives. */
|
|
27
|
-
close(): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
export declare function createHttpTransportServer(options: HttpTransportOptions): Promise<HttpTransportServer>;
|