feat(mcp): implement MCP infrastructure
- Add `mcp_settings` table to database schema - Enable internal MCP API endpoint via middleware header authentication - Introduce runtime log directory and capture utilities for diagnostics - Update build pipeline to capture build logs
This commit is contained in:
1 parent
ae9b554189
commit
b2669e2ad5
19 files changed
+3280
-20
No files matched your search
+18
-3
@@ -7,12 +7,15 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
const SESSION_COOKIE = "datastack_admin_session";
|
||||
const SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
|
||||
|
||||
function isProtectedApi(pathname: string, method: string) {
|
||||
function isProtectedApi(pathname: string, method: string, hasInternalSecretHeader: boolean) {
|
||||
if (pathname === "/api/auth/login") return false;
|
||||
if (pathname === "/api/auth/setup" && method === "POST") return false;
|
||||
if (pathname === "/api/events" && method === "POST") return false;
|
||||
if (pathname === "/api/health" && method === "GET") return false;
|
||||
if (pathname === "/api/prometheus" && method === "GET") return false;
|
||||
if (pathname === "/api/internal/mcp" && method === "POST" && hasInternalSecretHeader) {
|
||||
return false;
|
||||
}
|
||||
return pathname.startsWith("/api/");
|
||||
}
|
||||
|
||||
@@ -62,14 +65,26 @@ export async function middleware(request: NextRequest) {
|
||||
(pathname === "/vcon" || pathname.startsWith("/vcon/")) &&
|
||||
!isLoginPage &&
|
||||
!isSetupPage;
|
||||
const isAdminApi = isProtectedApi(pathname, request.method);
|
||||
const hasInternalSecretHeader = Boolean(
|
||||
request.headers.get("x-datastack-internal-secret")?.trim(),
|
||||
);
|
||||
const isAdminApi = isProtectedApi(
|
||||
pathname,
|
||||
request.method,
|
||||
hasInternalSecretHeader,
|
||||
);
|
||||
const hasBearerAuth = Boolean(
|
||||
request.headers.get("authorization")?.toLowerCase().startsWith("bearer "),
|
||||
);
|
||||
const isStateChangingApi =
|
||||
pathname.startsWith("/api/") &&
|
||||
!SAFE_METHODS.has(request.method.toUpperCase()) &&
|
||||
!(pathname === "/api/events" && hasBearerAuth);
|
||||
!(pathname === "/api/events" && hasBearerAuth) &&
|
||||
!(
|
||||
pathname === "/api/internal/mcp" &&
|
||||
request.method.toUpperCase() === "POST" &&
|
||||
hasInternalSecretHeader
|
||||
);
|
||||
|
||||
const requestHeaders = new Headers(request.headers);
|
||||
requestHeaders.set("x-datastack-pathname", pathname);
|
||||
|
||||
Reference in new issue
Block a user