File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { and , eq , isNull } from 'drizzle-orm'
22import type { NextRequest } from 'next/server'
33import { createLogger } from '@/lib/logs/console/logger'
4- import { withMcpAuth } from '@/lib/mcp/middleware'
4+ import { getParsedBody , withMcpAuth } from '@/lib/mcp/middleware'
55import { mcpService } from '@/lib/mcp/service'
66import { validateMcpServerUrl } from '@/lib/mcp/url-validator'
77import { createMcpErrorResponse , createMcpSuccessResponse } from '@/lib/mcp/utils'
@@ -46,7 +46,7 @@ export const GET = withMcpAuth('read')(
4646export const POST = withMcpAuth ( 'write' ) (
4747 async ( request : NextRequest , { userId, workspaceId, requestId } ) => {
4848 try {
49- const body = await request . json ( )
49+ const body = getParsedBody ( request ) || ( await request . json ( ) )
5050
5151 logger . info ( `[${ requestId } ] Registering new MCP server:` , {
5252 name : body . name ,
Original file line number Diff line number Diff line change 11import type { NextRequest } from 'next/server'
22import { createLogger } from '@/lib/logs/console/logger'
3- import { withMcpAuth } from '@/lib/mcp/middleware'
3+ import { getParsedBody , withMcpAuth } from '@/lib/mcp/middleware'
44import { mcpService } from '@/lib/mcp/service'
55import type { McpToolDiscoveryResponse } from '@/lib/mcp/types'
66import { categorizeError , createMcpErrorResponse , createMcpSuccessResponse } from '@/lib/mcp/utils'
@@ -61,7 +61,7 @@ export const GET = withMcpAuth('read')(
6161export const POST = withMcpAuth ( 'read' ) (
6262 async ( request : NextRequest , { userId, workspaceId, requestId } ) => {
6363 try {
64- const body = await request . json ( )
64+ const body = getParsedBody ( request ) || ( await request . json ( ) )
6565 const { serverIds } = body
6666
6767 if ( ! Array . isArray ( serverIds ) ) {
Original file line number Diff line number Diff line change @@ -104,15 +104,19 @@ export const POST = withMcpAuth('read')(
104104
105105 if ( result . isError ) {
106106 logger . warn ( `[${ requestId } ] Tool execution returned error for ${ toolName } on ${ serverId } ` )
107- return createMcpErrorResponse ( transformedResult , 'Tool execution failed' , 400 )
107+ return createMcpErrorResponse (
108+ transformedResult ,
109+ transformedResult . error || 'Tool execution failed' ,
110+ 400
111+ )
108112 }
109113 logger . info ( `[${ requestId } ] Successfully executed tool ${ toolName } on server ${ serverId } ` )
110114 return createMcpSuccessResponse ( transformedResult )
111115 } catch ( error ) {
112116 logger . error ( `[${ requestId } ] Error executing MCP tool:` , error )
113117
114118 const { message, status } = categorizeError ( error )
115- return createMcpErrorResponse ( new Error ( message ) , 'Tool execution failed' , status )
119+ return createMcpErrorResponse ( new Error ( message ) , message , status )
116120 }
117121 }
118122)
Original file line number Diff line number Diff line change @@ -37,17 +37,27 @@ class McpService {
3737 if ( ! envMatches ) return value
3838
3939 let resolvedValue = value
40+ const missingVars : string [ ] = [ ]
41+
4042 for ( const match of envMatches ) {
4143 const envKey = match . slice ( 2 , - 2 ) . trim ( )
4244 const envValue = envVars [ envKey ]
4345
4446 if ( envValue === undefined ) {
45- logger . warn ( `Environment variable " ${ envKey } " not found in MCP server config` )
47+ missingVars . push ( envKey )
4648 continue
4749 }
4850
4951 resolvedValue = resolvedValue . replace ( match , envValue )
5052 }
53+
54+ if ( missingVars . length > 0 ) {
55+ throw new Error (
56+ `Missing required environment variable${ missingVars . length > 1 ? 's' : '' } : ${ missingVars . join ( ', ' ) } . ` +
57+ `Please set ${ missingVars . length > 1 ? 'these variables' : 'this variable' } in your workspace or personal environment settings.`
58+ )
59+ }
60+
5161 return resolvedValue
5262 }
5363
You can’t perform that action at this time.
0 commit comments