@studiometa/forge-mcp 0.2.2 → 0.2.4

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.
Files changed (44) hide show
  1. package/README.md +61 -19
  2. package/dist/auth.d.ts +12 -1
  3. package/dist/auth.d.ts.map +1 -1
  4. package/dist/auth.js +19 -1
  5. package/dist/auth.js.map +1 -1
  6. package/dist/crypto.d.ts +56 -0
  7. package/dist/crypto.d.ts.map +1 -0
  8. package/dist/crypto.js +110 -0
  9. package/dist/crypto.js.map +1 -0
  10. package/dist/handlers/auto-resolve.d.ts +24 -0
  11. package/dist/handlers/auto-resolve.d.ts.map +1 -0
  12. package/dist/handlers/batch.d.ts +14 -0
  13. package/dist/handlers/batch.d.ts.map +1 -0
  14. package/dist/handlers/context.d.ts +14 -0
  15. package/dist/handlers/context.d.ts.map +1 -0
  16. package/dist/handlers/help.d.ts.map +1 -1
  17. package/dist/handlers/index.d.ts.map +1 -1
  18. package/dist/handlers/schema.d.ts.map +1 -1
  19. package/dist/handlers/servers.d.ts +6 -1
  20. package/dist/handlers/servers.d.ts.map +1 -1
  21. package/dist/handlers/sites.d.ts +6 -1
  22. package/dist/handlers/sites.d.ts.map +1 -1
  23. package/dist/{http-BMOiJdyw.js → http-DN0I5GR6.js} +16 -4
  24. package/dist/http-DN0I5GR6.js.map +1 -0
  25. package/dist/http.d.ts +1 -1
  26. package/dist/http.d.ts.map +1 -1
  27. package/dist/http.js +2 -2
  28. package/dist/index.js +1 -1
  29. package/dist/oauth.d.ts +118 -0
  30. package/dist/oauth.d.ts.map +1 -0
  31. package/dist/oauth.js +571 -0
  32. package/dist/oauth.js.map +1 -0
  33. package/dist/server.d.ts +24 -6
  34. package/dist/server.d.ts.map +1 -1
  35. package/dist/server.js +33 -9
  36. package/dist/server.js.map +1 -1
  37. package/dist/tools.d.ts +1 -1
  38. package/dist/tools.d.ts.map +1 -1
  39. package/dist/{version-D3OFS3DQ.js → version-Gjth4BwC.js} +2799 -2450
  40. package/dist/version-Gjth4BwC.js.map +1 -0
  41. package/package.json +9 -1
  42. package/skills/SKILL.md +152 -29
  43. package/dist/http-BMOiJdyw.js.map +0 -1
  44. package/dist/version-D3OFS3DQ.js.map +0 -1
@@ -0,0 +1,118 @@
1
+ /**
2
+ * OAuth 2.1 endpoints for Claude Desktop integration
3
+ *
4
+ * Implements OAuth 2.1 with PKCE as specified in the MCP authorization spec.
5
+ * Uses stateless encrypted tokens — no server-side storage required.
6
+ *
7
+ * Spec: https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization
8
+ *
9
+ * Flow:
10
+ * 1. Claude redirects user to /authorize with OAuth params (including PKCE)
11
+ * 2. User enters their Forge API token in a login form
12
+ * 3. Server encrypts the token + PKCE challenge into an authorization code
13
+ * 4. Redirects back to Claude with the code
14
+ * 5. Claude exchanges code for access token via /token (with code_verifier)
15
+ * 6. Server validates PKCE and returns base64-encoded access token
16
+ */
17
+ /**
18
+ * Create a base64-encoded access token from a Forge API token.
19
+ * The access token is simply base64(apiToken) so that parseAuthHeader
20
+ * can decode it on every request without any server-side lookup.
21
+ */
22
+ export declare function createAccessToken(apiToken: string): string;
23
+ /**
24
+ * OAuth metadata for discovery (RFC 8414)
25
+ * GET /.well-known/oauth-authorization-server
26
+ *
27
+ * MCP clients MUST check this endpoint first for server capabilities.
28
+ */
29
+ export declare const oauthMetadataHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, {
30
+ issuer: string;
31
+ authorization_endpoint: string;
32
+ token_endpoint: string;
33
+ response_types_supported: string[];
34
+ grant_types_supported: string[];
35
+ code_challenge_methods_supported: string[];
36
+ token_endpoint_auth_methods_supported: string[];
37
+ registration_endpoint: string;
38
+ scopes_supported: string[];
39
+ service_documentation: string;
40
+ }>;
41
+ /**
42
+ * Protected resource metadata (RFC 9728)
43
+ * GET /.well-known/oauth-protected-resource
44
+ *
45
+ * Tells MCP clients where to find the OAuth authorization server.
46
+ */
47
+ export declare const protectedResourceHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, {
48
+ resource: string;
49
+ authorization_servers: string[];
50
+ bearer_methods_supported: string[];
51
+ scopes_supported: string[];
52
+ }>;
53
+ /**
54
+ * Dynamic Client Registration endpoint (RFC 7591)
55
+ * POST /register
56
+ *
57
+ * MCP servers SHOULD support DCR to allow clients to register automatically.
58
+ * Since we use stateless tokens, we accept any registration and return
59
+ * a generated client_id.
60
+ */
61
+ export declare const registerHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
62
+ error: string;
63
+ error_description: string;
64
+ client_id?: undefined;
65
+ client_name?: undefined;
66
+ redirect_uris?: undefined;
67
+ token_endpoint_auth_method?: undefined;
68
+ grant_types?: undefined;
69
+ response_types?: undefined;
70
+ } | {
71
+ client_id: string;
72
+ client_name: string;
73
+ redirect_uris: string[];
74
+ token_endpoint_auth_method: string;
75
+ grant_types: string[];
76
+ response_types: string[];
77
+ error?: undefined;
78
+ error_description?: undefined;
79
+ }>>;
80
+ /**
81
+ * Authorization endpoint — shows login form
82
+ * GET /authorize
83
+ */
84
+ export declare const authorizeGetHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, string | import("h3").HTTPResponse>;
85
+ /**
86
+ * Authorization endpoint — process login
87
+ * POST /authorize
88
+ */
89
+ export declare const authorizePostHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<string>>;
90
+ /**
91
+ * Token endpoint — exchange code for access token
92
+ * POST /token
93
+ *
94
+ * Supports:
95
+ * - authorization_code grant (with PKCE validation)
96
+ * - refresh_token grant
97
+ */
98
+ export declare const tokenHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
99
+ error: string;
100
+ error_description: string;
101
+ access_token?: undefined;
102
+ token_type?: undefined;
103
+ expires_in?: undefined;
104
+ refresh_token?: undefined;
105
+ } | {
106
+ access_token: string;
107
+ token_type: string;
108
+ expires_in: number;
109
+ refresh_token: string;
110
+ error?: undefined;
111
+ error_description?: undefined;
112
+ }>>;
113
+ /**
114
+ * Create S256 PKCE challenge from verifier
115
+ * SHA256(code_verifier) encoded as base64url
116
+ */
117
+ export declare function createS256Challenge(codeVerifier: string): string;
118
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAgBH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;EAyB/B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB;;;;;EAcnC,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;GAoC1B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,0GAyC9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uFAuD/B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;GA4EvB,CAAC;AA0CH;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEhE"}
package/dist/oauth.js ADDED
@@ -0,0 +1,571 @@
1
+ import { createAuthCode, decodeAuthCode } from "./crypto.js";
2
+ import { createHash } from "node:crypto";
3
+ import { defineEventHandler, getQuery, getRequestHeader, readBody, sendRedirect, setResponseHeader, setResponseStatus } from "h3";
4
+ /**
5
+ * OAuth 2.1 endpoints for Claude Desktop integration
6
+ *
7
+ * Implements OAuth 2.1 with PKCE as specified in the MCP authorization spec.
8
+ * Uses stateless encrypted tokens — no server-side storage required.
9
+ *
10
+ * Spec: https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization
11
+ *
12
+ * Flow:
13
+ * 1. Claude redirects user to /authorize with OAuth params (including PKCE)
14
+ * 2. User enters their Forge API token in a login form
15
+ * 3. Server encrypts the token + PKCE challenge into an authorization code
16
+ * 4. Redirects back to Claude with the code
17
+ * 5. Claude exchanges code for access token via /token (with code_verifier)
18
+ * 6. Server validates PKCE and returns base64-encoded access token
19
+ */
20
+ /**
21
+ * Create a base64-encoded access token from a Forge API token.
22
+ * The access token is simply base64(apiToken) so that parseAuthHeader
23
+ * can decode it on every request without any server-side lookup.
24
+ */
25
+ function createAccessToken(apiToken) {
26
+ return Buffer.from(apiToken).toString("base64");
27
+ }
28
+ /**
29
+ * OAuth metadata for discovery (RFC 8414)
30
+ * GET /.well-known/oauth-authorization-server
31
+ *
32
+ * MCP clients MUST check this endpoint first for server capabilities.
33
+ */
34
+ const oauthMetadataHandler = defineEventHandler((event) => {
35
+ const host = getRequestHeader(event, "host") || "localhost:3000";
36
+ const baseUrl = `${getRequestHeader(event, "x-forwarded-proto") || "http"}://${host}`;
37
+ setResponseHeader(event, "Content-Type", "application/json");
38
+ setResponseHeader(event, "Cache-Control", "public, max-age=3600");
39
+ return {
40
+ issuer: baseUrl,
41
+ authorization_endpoint: `${baseUrl}/authorize`,
42
+ token_endpoint: `${baseUrl}/token`,
43
+ response_types_supported: ["code"],
44
+ grant_types_supported: ["authorization_code", "refresh_token"],
45
+ code_challenge_methods_supported: ["S256"],
46
+ token_endpoint_auth_methods_supported: ["none"],
47
+ registration_endpoint: `${baseUrl}/register`,
48
+ scopes_supported: ["forge"],
49
+ service_documentation: "https://github.com/studiometa/forge-tools"
50
+ };
51
+ });
52
+ /**
53
+ * Protected resource metadata (RFC 9728)
54
+ * GET /.well-known/oauth-protected-resource
55
+ *
56
+ * Tells MCP clients where to find the OAuth authorization server.
57
+ */
58
+ const protectedResourceHandler = defineEventHandler((event) => {
59
+ const host = getRequestHeader(event, "host") || "localhost:3000";
60
+ const baseUrl = `${getRequestHeader(event, "x-forwarded-proto") || "http"}://${host}`;
61
+ setResponseHeader(event, "Content-Type", "application/json");
62
+ setResponseHeader(event, "Cache-Control", "public, max-age=3600");
63
+ return {
64
+ resource: `${baseUrl}/mcp`,
65
+ authorization_servers: [baseUrl],
66
+ bearer_methods_supported: ["header"],
67
+ scopes_supported: ["forge"]
68
+ };
69
+ });
70
+ /**
71
+ * Dynamic Client Registration endpoint (RFC 7591)
72
+ * POST /register
73
+ *
74
+ * MCP servers SHOULD support DCR to allow clients to register automatically.
75
+ * Since we use stateless tokens, we accept any registration and return
76
+ * a generated client_id.
77
+ */
78
+ const registerHandler = defineEventHandler(async (event) => {
79
+ setResponseHeader(event, "Content-Type", "application/json");
80
+ let body;
81
+ try {
82
+ body = await readBody(event);
83
+ } catch {
84
+ setResponseStatus(event, 400);
85
+ return {
86
+ error: "invalid_request",
87
+ error_description: "Invalid JSON body"
88
+ };
89
+ }
90
+ const clientName = body.client_name || "MCP Client";
91
+ const redirectUris = body.redirect_uris || [];
92
+ const clientId = Buffer.from(JSON.stringify({
93
+ name: clientName,
94
+ ts: Date.now()
95
+ })).toString("base64url");
96
+ setResponseStatus(event, 201);
97
+ return {
98
+ client_id: clientId,
99
+ client_name: clientName,
100
+ redirect_uris: redirectUris,
101
+ token_endpoint_auth_method: "none",
102
+ grant_types: ["authorization_code", "refresh_token"],
103
+ response_types: ["code"]
104
+ };
105
+ });
106
+ /**
107
+ * Authorization endpoint — shows login form
108
+ * GET /authorize
109
+ */
110
+ const authorizeGetHandler = defineEventHandler((event) => {
111
+ const query = getQuery(event);
112
+ const redirectUri = query.redirect_uri;
113
+ const state = query.state;
114
+ const codeChallenge = query.code_challenge;
115
+ const codeChallengeMethod = query.code_challenge_method;
116
+ if (!redirectUri) {
117
+ setResponseHeader(event, "Content-Type", "text/html; charset=utf-8");
118
+ setResponseStatus(event, 400);
119
+ return renderErrorPage("Missing required parameter: redirect_uri");
120
+ }
121
+ if (!codeChallenge) {
122
+ const errorUrl = new URL(redirectUri);
123
+ errorUrl.searchParams.set("error", "invalid_request");
124
+ errorUrl.searchParams.set("error_description", "code_challenge is required");
125
+ if (state) errorUrl.searchParams.set("state", state);
126
+ return sendRedirect(event, errorUrl.toString(), 302);
127
+ }
128
+ if (codeChallengeMethod && codeChallengeMethod !== "S256") {
129
+ const errorUrl = new URL(redirectUri);
130
+ errorUrl.searchParams.set("error", "invalid_request");
131
+ errorUrl.searchParams.set("error_description", "Only S256 code_challenge_method is supported");
132
+ if (state) errorUrl.searchParams.set("state", state);
133
+ return sendRedirect(event, errorUrl.toString(), 302);
134
+ }
135
+ setResponseHeader(event, "Content-Type", "text/html; charset=utf-8");
136
+ return renderLoginForm({
137
+ redirectUri,
138
+ state,
139
+ codeChallenge,
140
+ codeChallengeMethod: codeChallengeMethod || "S256"
141
+ });
142
+ });
143
+ /**
144
+ * Authorization endpoint — process login
145
+ * POST /authorize
146
+ */
147
+ const authorizePostHandler = defineEventHandler(async (event) => {
148
+ const { apiToken, redirectUri, state, codeChallenge, codeChallengeMethod } = await readBody(event);
149
+ if (!redirectUri) {
150
+ setResponseHeader(event, "Content-Type", "text/html; charset=utf-8");
151
+ setResponseStatus(event, 400);
152
+ return renderErrorPage("Missing redirect_uri parameter");
153
+ }
154
+ try {
155
+ const uri = new URL(redirectUri);
156
+ const isLocalhost = uri.hostname === "localhost" || uri.hostname === "127.0.0.1";
157
+ const isHttps = uri.protocol === "https:";
158
+ if (!isLocalhost && !isHttps) {
159
+ setResponseStatus(event, 400);
160
+ return renderErrorPage("redirect_uri must be HTTPS or localhost");
161
+ }
162
+ } catch {
163
+ setResponseStatus(event, 400);
164
+ return renderErrorPage("Invalid redirect_uri format");
165
+ }
166
+ if (!apiToken) {
167
+ setResponseHeader(event, "Content-Type", "text/html; charset=utf-8");
168
+ return renderLoginForm({
169
+ redirectUri,
170
+ state,
171
+ codeChallenge,
172
+ codeChallengeMethod,
173
+ error: "Forge API Token is required"
174
+ });
175
+ }
176
+ const code = createAuthCode({
177
+ apiToken,
178
+ codeChallenge,
179
+ codeChallengeMethod: codeChallengeMethod || "S256"
180
+ });
181
+ const redirectUrl = new URL(redirectUri);
182
+ redirectUrl.searchParams.set("code", code);
183
+ if (state) redirectUrl.searchParams.set("state", state);
184
+ setResponseHeader(event, "Content-Type", "text/html; charset=utf-8");
185
+ return renderSuccessPage(redirectUrl.toString());
186
+ });
187
+ /**
188
+ * Token endpoint — exchange code for access token
189
+ * POST /token
190
+ *
191
+ * Supports:
192
+ * - authorization_code grant (with PKCE validation)
193
+ * - refresh_token grant
194
+ */
195
+ const tokenHandler = defineEventHandler(async (event) => {
196
+ setResponseHeader(event, "Content-Type", "application/json");
197
+ const { grant_type, code, code_verifier, refresh_token } = await readBody(event);
198
+ if (grant_type === "refresh_token") return handleRefreshToken(event, refresh_token);
199
+ if (grant_type !== "authorization_code") {
200
+ setResponseStatus(event, 400);
201
+ return {
202
+ error: "unsupported_grant_type",
203
+ error_description: "Supported grant types: authorization_code, refresh_token"
204
+ };
205
+ }
206
+ if (!code) {
207
+ setResponseStatus(event, 400);
208
+ return {
209
+ error: "invalid_request",
210
+ error_description: "Missing authorization code"
211
+ };
212
+ }
213
+ if (!code_verifier) {
214
+ setResponseStatus(event, 400);
215
+ return {
216
+ error: "invalid_request",
217
+ error_description: "Missing code_verifier (PKCE required)"
218
+ };
219
+ }
220
+ try {
221
+ const payload = decodeAuthCode(code);
222
+ if (payload.codeChallenge) {
223
+ if (createS256Challenge(code_verifier) !== payload.codeChallenge) {
224
+ setResponseStatus(event, 400);
225
+ return {
226
+ error: "invalid_grant",
227
+ error_description: "Invalid code_verifier"
228
+ };
229
+ }
230
+ }
231
+ return {
232
+ access_token: createAccessToken(payload.apiToken),
233
+ token_type: "Bearer",
234
+ expires_in: 3600,
235
+ refresh_token: createAuthCode({ apiToken: payload.apiToken }, 86400 * 30)
236
+ };
237
+ } catch (error) {
238
+ setResponseStatus(event, 400);
239
+ return {
240
+ error: "invalid_grant",
241
+ error_description: error instanceof Error ? error.message : "Invalid authorization code"
242
+ };
243
+ }
244
+ });
245
+ /**
246
+ * Handle refresh token grant
247
+ */
248
+ function handleRefreshToken(event, refreshToken) {
249
+ if (!refreshToken) {
250
+ setResponseStatus(event, 400);
251
+ return {
252
+ error: "invalid_request",
253
+ error_description: "Missing refresh_token"
254
+ };
255
+ }
256
+ try {
257
+ const payload = decodeAuthCode(refreshToken);
258
+ return {
259
+ access_token: createAccessToken(payload.apiToken),
260
+ token_type: "Bearer",
261
+ expires_in: 3600,
262
+ refresh_token: createAuthCode({ apiToken: payload.apiToken }, 86400 * 30)
263
+ };
264
+ } catch (error) {
265
+ setResponseStatus(event, 400);
266
+ return {
267
+ error: "invalid_grant",
268
+ error_description: error instanceof Error ? error.message : "Invalid refresh token"
269
+ };
270
+ }
271
+ }
272
+ /**
273
+ * Create S256 PKCE challenge from verifier
274
+ * SHA256(code_verifier) encoded as base64url
275
+ */
276
+ function createS256Challenge(codeVerifier) {
277
+ return createHash("sha256").update(codeVerifier).digest("base64url");
278
+ }
279
+ /**
280
+ * Escape HTML special characters
281
+ */
282
+ function escapeHtml(str) {
283
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
284
+ }
285
+ /**
286
+ * Render the login form HTML
287
+ */
288
+ function renderLoginForm(params) {
289
+ const { redirectUri, state, codeChallenge, codeChallengeMethod, error } = params;
290
+ return `<!DOCTYPE html>
291
+ <html lang="en">
292
+ <head>
293
+ <meta charset="UTF-8">
294
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
295
+ <title>Connect to Laravel Forge</title>
296
+ <style>
297
+ * { box-sizing: border-box; margin: 0; padding: 0; }
298
+ body {
299
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
300
+ background: linear-gradient(135deg, #18b69b 0%, #0e7460 100%);
301
+ min-height: 100vh;
302
+ display: flex;
303
+ align-items: center;
304
+ justify-content: center;
305
+ padding: 20px;
306
+ }
307
+ .container {
308
+ background: white;
309
+ border-radius: 16px;
310
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
311
+ padding: 40px;
312
+ width: 100%;
313
+ max-width: 420px;
314
+ }
315
+ .logo {
316
+ text-align: center;
317
+ margin-bottom: 24px;
318
+ }
319
+ .logo svg { width: 48px; height: 48px; }
320
+ h1 {
321
+ text-align: center;
322
+ color: #1a1a2e;
323
+ font-size: 24px;
324
+ margin-bottom: 8px;
325
+ }
326
+ .subtitle {
327
+ text-align: center;
328
+ color: #666;
329
+ font-size: 14px;
330
+ margin-bottom: 32px;
331
+ }
332
+ .error {
333
+ background: #fee2e2;
334
+ border: 1px solid #fecaca;
335
+ color: #dc2626;
336
+ padding: 12px 16px;
337
+ border-radius: 8px;
338
+ margin-bottom: 24px;
339
+ font-size: 14px;
340
+ }
341
+ .notice {
342
+ background: #f0fdf4;
343
+ border: 1px solid #bbf7d0;
344
+ color: #166534;
345
+ padding: 12px 16px;
346
+ border-radius: 8px;
347
+ margin-bottom: 24px;
348
+ font-size: 13px;
349
+ line-height: 1.4;
350
+ }
351
+ .form-group { margin-bottom: 20px; }
352
+ label {
353
+ display: block;
354
+ font-size: 14px;
355
+ font-weight: 500;
356
+ color: #374151;
357
+ margin-bottom: 6px;
358
+ }
359
+ input {
360
+ width: 100%;
361
+ padding: 12px 16px;
362
+ border: 1px solid #d1d5db;
363
+ border-radius: 8px;
364
+ font-size: 16px;
365
+ transition: border-color 0.2s, box-shadow 0.2s;
366
+ }
367
+ input:focus {
368
+ outline: none;
369
+ border-color: #18b69b;
370
+ box-shadow: 0 0 0 3px rgba(24, 182, 155, 0.2);
371
+ }
372
+ input::placeholder { color: #9ca3af; }
373
+ .help-text {
374
+ font-size: 12px;
375
+ color: #6b7280;
376
+ margin-top: 4px;
377
+ }
378
+ .help-text a { color: #18b69b; text-decoration: none; }
379
+ .help-text a:hover { text-decoration: underline; }
380
+ button {
381
+ width: 100%;
382
+ padding: 14px 24px;
383
+ background: linear-gradient(135deg, #18b69b 0%, #0e7460 100%);
384
+ color: white;
385
+ border: none;
386
+ border-radius: 8px;
387
+ font-size: 16px;
388
+ font-weight: 600;
389
+ cursor: pointer;
390
+ transition: transform 0.2s, box-shadow 0.2s;
391
+ }
392
+ button:hover {
393
+ transform: translateY(-1px);
394
+ box-shadow: 0 4px 12px rgba(24, 182, 155, 0.4);
395
+ }
396
+ button:active { transform: translateY(0); }
397
+ .footer {
398
+ text-align: center;
399
+ margin-top: 24px;
400
+ font-size: 12px;
401
+ color: #9ca3af;
402
+ }
403
+ .footer a { color: #18b69b; text-decoration: none; }
404
+ .footer a:hover { text-decoration: underline; }
405
+ </style>
406
+ </head>
407
+ <body>
408
+ <div class="container">
409
+ <div class="logo">
410
+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
411
+ <path d="M12 2L2 7L12 12L22 7L12 2Z" stroke="#18b69b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
412
+ <path d="M2 17L12 22L22 17" stroke="#0e7460" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
413
+ <path d="M2 12L12 17L22 12" stroke="#18b69b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
414
+ </svg>
415
+ </div>
416
+ <h1>Connect to Laravel Forge</h1>
417
+ <p class="subtitle">Enter your Forge API token to connect with Claude</p>
418
+
419
+ ${error ? `<div class="error">${escapeHtml(error)}</div>` : ""}
420
+
421
+ <div class="notice">
422
+ <strong>Your token is not stored on this server.</strong> It is encrypted into the authorization code and sent back to Claude Desktop, which holds it in its own secure storage.
423
+ </div>
424
+
425
+ <form method="POST" action="/authorize">
426
+ <input type="hidden" name="redirectUri" value="${escapeHtml(redirectUri || "")}">
427
+ <input type="hidden" name="state" value="${escapeHtml(state || "")}">
428
+ <input type="hidden" name="codeChallenge" value="${escapeHtml(codeChallenge || "")}">
429
+ <input type="hidden" name="codeChallengeMethod" value="${escapeHtml(codeChallengeMethod || "S256")}">
430
+
431
+ <div class="form-group">
432
+ <label for="apiToken">Forge API Token *</label>
433
+ <input type="password" id="apiToken" name="apiToken" required placeholder="Enter your Forge API token">
434
+ <p class="help-text">
435
+ Generate at <a href="https://forge.laravel.com/user-profile/api" target="_blank" rel="noopener">forge.laravel.com → API Tokens</a>
436
+ </p>
437
+ </div>
438
+
439
+ <button type="submit">Connect to Forge</button>
440
+ </form>
441
+
442
+ <p class="footer">
443
+ Powered by <a href="https://github.com/studiometa/forge-tools" target="_blank" rel="noopener">forge-tools</a>
444
+ </p>
445
+ </div>
446
+ </body>
447
+ </html>`;
448
+ }
449
+ /**
450
+ * Render success page with auto-redirect
451
+ */
452
+ function renderSuccessPage(redirectUrl) {
453
+ return `<!DOCTYPE html>
454
+ <html lang="en">
455
+ <head>
456
+ <meta charset="UTF-8">
457
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
458
+ <meta http-equiv="refresh" content="2;url=${escapeHtml(redirectUrl)}">
459
+ <title>Connected — Forge MCP</title>
460
+ <style>
461
+ * { box-sizing: border-box; margin: 0; padding: 0; }
462
+ body {
463
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
464
+ background: linear-gradient(135deg, #18b69b 0%, #0e7460 100%);
465
+ min-height: 100vh;
466
+ display: flex;
467
+ align-items: center;
468
+ justify-content: center;
469
+ padding: 20px;
470
+ }
471
+ .container {
472
+ background: white;
473
+ border-radius: 16px;
474
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
475
+ padding: 40px;
476
+ width: 100%;
477
+ max-width: 420px;
478
+ text-align: center;
479
+ }
480
+ .success-icon {
481
+ width: 64px;
482
+ height: 64px;
483
+ margin: 0 auto 24px;
484
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%);
485
+ border-radius: 50%;
486
+ display: flex;
487
+ align-items: center;
488
+ justify-content: center;
489
+ }
490
+ .success-icon svg { width: 32px; height: 32px; stroke: white; }
491
+ h1 { color: #1a1a2e; font-size: 24px; margin-bottom: 8px; }
492
+ .message { color: #666; font-size: 14px; margin-bottom: 24px; }
493
+ .spinner {
494
+ width: 24px;
495
+ height: 24px;
496
+ border: 3px solid #e5e7eb;
497
+ border-top-color: #18b69b;
498
+ border-radius: 50%;
499
+ animation: spin 1s linear infinite;
500
+ margin: 0 auto 16px;
501
+ }
502
+ @keyframes spin { to { transform: rotate(360deg); } }
503
+ .redirect-text { color: #9ca3af; font-size: 13px; margin-bottom: 16px; }
504
+ .manual-link { color: #18b69b; text-decoration: none; font-size: 14px; }
505
+ .manual-link:hover { text-decoration: underline; }
506
+ </style>
507
+ </head>
508
+ <body>
509
+ <div class="container">
510
+ <div class="success-icon">
511
+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
512
+ <path d="M20 6L9 17L4 12" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
513
+ </svg>
514
+ </div>
515
+ <h1>Successfully Connected!</h1>
516
+ <p class="message">Your Forge API token has been encrypted and transmitted securely.</p>
517
+ <div class="spinner"></div>
518
+ <p class="redirect-text">Redirecting to Claude Desktop...</p>
519
+ <a href="${escapeHtml(redirectUrl)}" class="manual-link">Click here if not redirected automatically</a>
520
+ </div>
521
+ <script>
522
+ setTimeout(function() {
523
+ window.location.href = ${JSON.stringify(redirectUrl)};
524
+ }, 2000);
525
+ <\/script>
526
+ </body>
527
+ </html>`;
528
+ }
529
+ /**
530
+ * Render error page
531
+ */
532
+ function renderErrorPage(message) {
533
+ return `<!DOCTYPE html>
534
+ <html lang="en">
535
+ <head>
536
+ <meta charset="UTF-8">
537
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
538
+ <title>Error — Forge MCP</title>
539
+ <style>
540
+ body {
541
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
542
+ background: #f3f4f6;
543
+ min-height: 100vh;
544
+ display: flex;
545
+ align-items: center;
546
+ justify-content: center;
547
+ padding: 20px;
548
+ }
549
+ .container {
550
+ background: white;
551
+ border-radius: 16px;
552
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
553
+ padding: 40px;
554
+ text-align: center;
555
+ max-width: 400px;
556
+ }
557
+ h1 { color: #dc2626; margin-bottom: 16px; }
558
+ p { color: #6b7280; }
559
+ </style>
560
+ </head>
561
+ <body>
562
+ <div class="container">
563
+ <h1>Error</h1>
564
+ <p>${escapeHtml(message)}</p>
565
+ </div>
566
+ </body>
567
+ </html>`;
568
+ }
569
+ export { authorizeGetHandler, authorizePostHandler, createAccessToken, createS256Challenge, oauthMetadataHandler, protectedResourceHandler, registerHandler, tokenHandler };
570
+
571
+ //# sourceMappingURL=oauth.js.map