@@ -20,6 +20,12 @@ import { workflow, workflowMcpServer, workflowMcpTool, workspace } from '@sim/db
2020import { createLogger } from '@sim/logger'
2121import { and , eq , isNull } from 'drizzle-orm'
2222import { type NextRequest , NextResponse } from 'next/server'
23+ import {
24+ mcpJsonRpcNotificationSchema ,
25+ mcpJsonRpcRequestSchema ,
26+ mcpServeRouteParamsSchema ,
27+ mcpToolCallParamsSchema ,
28+ } from '@/lib/api/contracts/mcp'
2329import { type AuthResult , AuthType , checkHybridAuth } from '@/lib/auth/hybrid'
2430import { generateInternalToken } from '@/lib/auth/internal'
2531import { getMaxExecutionTimeout } from '@/lib/core/execution-limits'
@@ -84,7 +90,7 @@ async function getServer(serverId: string) {
8490export const GET = withRouteHandler (
8591 async ( request : NextRequest , { params } : { params : Promise < RouteParams > } ) => {
8692 try {
87- const { serverId } = routeParamsSchema . parse ( await params )
93+ const { serverId } = mcpServeRouteParamsSchema . parse ( await params )
8894 const server = await getServer ( serverId )
8995 if ( ! server ) {
9096 return NextResponse . json ( { error : 'Server not found' } , { status : 404 } )
@@ -126,7 +132,7 @@ export const GET = withRouteHandler(
126132export const POST = withRouteHandler (
127133 async ( request : NextRequest , { params } : { params : Promise < RouteParams > } ) => {
128134 try {
129- const { serverId } = routeParamsSchema . parse ( await params )
135+ const { serverId } = mcpServeRouteParamsSchema . parse ( await params )
130136 const server = await getServer ( serverId )
131137 if ( ! server ) {
132138 return NextResponse . json ( { error : 'Server not found' } , { status : 404 } )
@@ -170,7 +176,7 @@ export const POST = withRouteHandler(
170176 const message = body as JSONRPCMessage
171177
172178 if ( isJSONRPCNotification ( message ) ) {
173- const notificationValidation = jsonRpcNotificationSchema . safeParse ( message )
179+ const notificationValidation = mcpJsonRpcNotificationSchema . safeParse ( message )
174180 if ( ! notificationValidation . success ) {
175181 return NextResponse . json (
176182 createError ( 0 , ErrorCode . InvalidRequest , 'Invalid JSON-RPC message' ) ,
@@ -193,7 +199,7 @@ export const POST = withRouteHandler(
193199 )
194200 }
195201
196- const requestValidation = jsonRpcRequestSchema . safeParse ( message )
202+ const requestValidation = mcpJsonRpcRequestSchema . safeParse ( message )
197203 if ( ! requestValidation . success ) {
198204 return NextResponse . json (
199205 createError ( 0 , ErrorCode . InvalidRequest , 'Invalid JSON-RPC message' ) ,
@@ -222,7 +228,7 @@ export const POST = withRouteHandler(
222228 return handleToolsList ( id , serverId )
223229
224230 case 'tools/call' : {
225- const paramsValidation = toolCallParamsSchema . safeParse ( rpcParams )
231+ const paramsValidation = mcpToolCallParamsSchema . safeParse ( rpcParams )
226232 if ( ! paramsValidation . success ) {
227233 return NextResponse . json (
228234 createError ( id , ErrorCode . InvalidParams , 'Invalid tool call parameters' ) ,
@@ -407,7 +413,7 @@ async function handleToolsCall(
407413export const DELETE = withRouteHandler (
408414 async ( request : NextRequest , { params } : { params : Promise < RouteParams > } ) => {
409415 try {
410- const { serverId } = routeParamsSchema . parse ( await params )
416+ const { serverId } = mcpServeRouteParamsSchema . parse ( await params )
411417 const server = await getServer ( serverId )
412418 if ( ! server ) {
413419 return NextResponse . json ( { error : 'Server not found' } , { status : 404 } )
0 commit comments