burn-mcp-server 2.0.6 → 2.0.7
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/README.md +57 -2
- package/api/health.mjs +7 -0
- package/api/mcp.js +36075 -0
- package/dist/http.mjs +1131 -0
- package/dist/index.js +1021 -1009
- package/package.json +7 -3
- package/public/index.html +47 -0
- package/server.json +16 -2
- package/src/http-dev.ts +56 -0
- package/src/http.ts +62 -0
- package/src/index.ts +28 -1624
- package/src/lib/auth-stdio.ts +26 -0
- package/src/lib/auth.ts +71 -0
- package/src/setup.ts +1529 -0
- package/src/vercel-handler.ts +20 -0
- package/src/vercel-node-handler.ts +76 -0
- package/tsconfig.json +10 -6
- package/vercel.json +9 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Vercel Edge handler — pre-bundled by esbuild into api/mcp.mjs
|
|
2
|
+
|
|
3
|
+
import { handleMcpRequest } from './http.js'
|
|
4
|
+
|
|
5
|
+
export const config = { runtime: 'edge' }
|
|
6
|
+
|
|
7
|
+
export default async function handler(req: Request): Promise<Response> {
|
|
8
|
+
try {
|
|
9
|
+
return await handleMcpRequest(req)
|
|
10
|
+
} catch (e: any) {
|
|
11
|
+
return new Response(JSON.stringify({
|
|
12
|
+
error: 'Handler threw',
|
|
13
|
+
message: String(e?.message || e),
|
|
14
|
+
stack: String(e?.stack || '').slice(0, 2000),
|
|
15
|
+
}), {
|
|
16
|
+
status: 500,
|
|
17
|
+
headers: { 'content-type': 'application/json' },
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Vercel Node runtime handler — uses StreamableHTTPServerTransport (non-Web variant).
|
|
2
|
+
// Pre-bundled by esbuild into api/mcp.js (Vercel detects .js as Node function).
|
|
3
|
+
|
|
4
|
+
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
5
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
|
|
6
|
+
import { createClient } from '@supabase/supabase-js'
|
|
7
|
+
import { getOrExchangeSession } from './lib/auth.js'
|
|
8
|
+
import { createBurnServer } from './setup.js'
|
|
9
|
+
|
|
10
|
+
const SUPABASE_URL = process.env.BURN_SUPABASE_URL || 'https://juqtxylquemiuvvmgbej.supabase.co'
|
|
11
|
+
const SUPABASE_ANON_KEY = process.env.BURN_SUPABASE_ANON_KEY || 'sb_publishable_reVgmmCC6ndIo6jFRMM2LQ_wujj5FrO'
|
|
12
|
+
|
|
13
|
+
export default async function handler(req: IncomingMessage, res: ServerResponse): Promise<void> {
|
|
14
|
+
try {
|
|
15
|
+
// --- Auth ---
|
|
16
|
+
const authHeader = (req.headers.authorization || req.headers.Authorization || '') as string
|
|
17
|
+
const m = authHeader.match(/^Bearer\s+(.+)$/i)
|
|
18
|
+
const token = m?.[1]?.trim()
|
|
19
|
+
|
|
20
|
+
if (!token) {
|
|
21
|
+
res.statusCode = 401
|
|
22
|
+
res.setHeader('content-type', 'application/json')
|
|
23
|
+
res.end(JSON.stringify({
|
|
24
|
+
error: 'Missing Authorization header',
|
|
25
|
+
hint: 'Add `Authorization: Bearer <BURN_MCP_TOKEN>` — get yours at https://burn451.cloud → Settings → MCP Server.',
|
|
26
|
+
}))
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// --- Exchange token → Supabase session (in-memory cache per token) ---
|
|
31
|
+
let session
|
|
32
|
+
try {
|
|
33
|
+
session = await getOrExchangeSession(token)
|
|
34
|
+
} catch (e: any) {
|
|
35
|
+
res.statusCode = 401
|
|
36
|
+
res.setHeader('content-type', 'application/json')
|
|
37
|
+
res.end(JSON.stringify({ error: 'Invalid or expired Burn MCP token', detail: String(e?.message || e) }))
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// --- Per-request Supabase client with JWT in headers ---
|
|
42
|
+
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
|
|
43
|
+
auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false },
|
|
44
|
+
global: { headers: { Authorization: `Bearer ${session.access_token}` } },
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const server = createBurnServer(supabase, { rateLimitPerMin: 60 })
|
|
48
|
+
|
|
49
|
+
// --- Stateless transport, JSON response mode ---
|
|
50
|
+
const transport = new StreamableHTTPServerTransport({
|
|
51
|
+
sessionIdGenerator: undefined,
|
|
52
|
+
enableJsonResponse: true,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
await server.connect(transport)
|
|
56
|
+
|
|
57
|
+
// Read body — Vercel Node already parses JSON for us at req.body, but let's be safe
|
|
58
|
+
let parsedBody: unknown
|
|
59
|
+
if ((req as any).body !== undefined) {
|
|
60
|
+
parsedBody = (req as any).body
|
|
61
|
+
} else {
|
|
62
|
+
const chunks: Buffer[] = []
|
|
63
|
+
for await (const c of req) chunks.push(c as Buffer)
|
|
64
|
+
const raw = Buffer.concat(chunks).toString('utf8')
|
|
65
|
+
try { parsedBody = raw ? JSON.parse(raw) : undefined } catch { parsedBody = undefined }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await transport.handleRequest(req as any, res, parsedBody)
|
|
69
|
+
} catch (e: any) {
|
|
70
|
+
if (!res.headersSent) {
|
|
71
|
+
res.statusCode = 500
|
|
72
|
+
res.setHeader('content-type', 'application/json')
|
|
73
|
+
res.end(JSON.stringify({ error: 'Handler threw', message: String(e?.message || e), stack: String(e?.stack || '').slice(0, 2000) }))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "
|
|
5
|
-
"
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ES2022",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": ["ES2022"],
|
|
6
7
|
"outDir": "./dist",
|
|
7
8
|
"rootDir": "./src",
|
|
8
|
-
"strict":
|
|
9
|
+
"strict": false,
|
|
9
10
|
"esModuleInterop": true,
|
|
10
11
|
"skipLibCheck": true,
|
|
11
|
-
"resolveJsonModule": true
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"allowJs": true
|
|
12
15
|
},
|
|
13
|
-
"include": ["src/**/*"]
|
|
16
|
+
"include": ["src/lib/**/*", "src/index.ts", "src/http.ts", "src/http-dev.ts"],
|
|
17
|
+
"exclude": ["src/setup.ts", "api/**/*", "dist/**/*", "node_modules/**/*"]
|
|
14
18
|
}
|
package/vercel.json
ADDED