Skip to content

Commit 4cb9c91

Browse files
committed
type checks
1 parent e18377d commit 4cb9c91

5 files changed

Lines changed: 17 additions & 230 deletions

File tree

apps/sim/app/api/copilot/confirm/route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type NextRequest, NextResponse } from 'next/server'
44
import { copilotConfirmBodySchema } from '@/lib/api/contracts/copilot'
55
import { validateSchema } from '@/lib/api/server'
66
import {
7+
ASYNC_TOOL_CONFIRMATION_STATUS,
78
ASYNC_TOOL_STATUS,
89
type AsyncCompletionData,
910
type AsyncConfirmationStatus,

apps/sim/app/api/knowledge/[id]/documents/[documentId]/tag-definitions/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ export const POST = withRouteHandler(
117117
const validatedData = validation.data
118118

119119
for (const def of validatedData.definitions) {
120-
if (!SUPPORTED_FIELD_TYPES.includes(def.fieldType)) {
120+
// Defense-in-depth runtime check: contract leaves `fieldType` as `z.string()`
121+
// because tightening to the enum cascades into UI form state types. Cast here
122+
// to allow `includes` to accept the wider input.
123+
if (!(SUPPORTED_FIELD_TYPES as readonly string[]).includes(def.fieldType)) {
121124
return NextResponse.json(
122125
{ error: 'Invalid request data', details: `Unsupported field type: ${def.fieldType}` },
123126
{ status: 400 }

apps/sim/app/api/mcp/serve/[serverId]/route.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import { workflow, workflowMcpServer, workflowMcpTool, workspace } from '@sim/db
2020
import { createLogger } from '@sim/logger'
2121
import { and, eq, isNull } from 'drizzle-orm'
2222
import { type NextRequest, NextResponse } from 'next/server'
23+
import {
24+
mcpJsonRpcNotificationSchema,
25+
mcpJsonRpcRequestSchema,
26+
mcpServeRouteParamsSchema,
27+
mcpToolCallParamsSchema,
28+
} from '@/lib/api/contracts/mcp'
2329
import { type AuthResult, AuthType, checkHybridAuth } from '@/lib/auth/hybrid'
2430
import { generateInternalToken } from '@/lib/auth/internal'
2531
import { getMaxExecutionTimeout } from '@/lib/core/execution-limits'
@@ -84,7 +90,7 @@ async function getServer(serverId: string) {
8490
export 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(
126132
export 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(
407413
export 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 })

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"check:api-validation": "bun run scripts/check-api-validation-contracts.ts --check",
2626
"check:api-validation:strict": "bun run scripts/check-api-validation-contracts.ts --check --enforce-boundary-baseline",
2727
"check:realtime-prune": "bun run scripts/check-realtime-prune-graph.ts",
28-
"check:zod-v4": "bun run scripts/check-zod-v4-readiness.ts --check",
2928
"mship-contracts:generate": "bun run scripts/sync-mothership-stream-contract.ts",
3029
"mship-contracts:check": "bun run scripts/sync-mothership-stream-contract.ts --check",
3130
"mship-tools:generate": "bun run scripts/sync-tool-catalog.ts",

scripts/check-zod-v4-readiness.ts

Lines changed: 0 additions & 222 deletions
This file was deleted.

0 commit comments

Comments
 (0)