@@ -3,7 +3,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
33import { createMcpServer } from '@/features/mcp/server' ;
44import { withOptionalAuthV2 } from '@/withAuthV2' ;
55import { isServiceError } from '@/lib/utils' ;
6- import { serviceErrorResponse , ServiceError } from '@/lib/serviceError' ;
6+ import { notAuthenticated , serviceErrorResponse , ServiceError } from '@/lib/serviceError' ;
77import { ErrorCode } from '@/lib/errorCodes' ;
88import { StatusCodes } from 'http-status-codes' ;
99import { NextRequest } from 'next/server' ;
@@ -44,6 +44,9 @@ const sessions = new Map<string, McpSession>();
4444export const POST = apiHandler ( async ( request : NextRequest ) => {
4545 const response = await sew ( ( ) =>
4646 withOptionalAuthV2 ( async ( { user } ) => {
47+ if ( env . EXPERIMENT_ASK_GH_ENABLED === 'true' && ! user ) {
48+ return notAuthenticated ( ) ;
49+ }
4750 const ownerId = user ?. id ?? null ;
4851 const sessionId = request . headers . get ( MCP_SESSION_ID_HEADER ) ;
4952
@@ -93,6 +96,9 @@ export const POST = apiHandler(async (request: NextRequest) => {
9396export const DELETE = apiHandler ( async ( request : NextRequest ) => {
9497 const result = await sew ( ( ) =>
9598 withOptionalAuthV2 ( async ( { user } ) => {
99+ if ( env . EXPERIMENT_ASK_GH_ENABLED === 'true' && ! user ) {
100+ return notAuthenticated ( ) ;
101+ }
96102 const ownerId = user ?. id ?? null ;
97103 const sessionId = request . headers . get ( MCP_SESSION_ID_HEADER ) ;
98104 if ( ! sessionId || ! sessions . has ( sessionId ) ) {
@@ -126,6 +132,9 @@ export const DELETE = apiHandler(async (request: NextRequest) => {
126132export const GET = apiHandler ( async ( request : NextRequest ) => {
127133 const result = await sew ( ( ) =>
128134 withOptionalAuthV2 ( async ( { user } ) => {
135+ if ( env . EXPERIMENT_ASK_GH_ENABLED === 'true' && ! user ) {
136+ return notAuthenticated ( ) ;
137+ }
129138 const ownerId = user ?. id ?? null ;
130139 const sessionId = request . headers . get ( MCP_SESSION_ID_HEADER ) ;
131140 if ( ! sessionId || ! sessions . has ( sessionId ) ) {
0 commit comments