Skip to content

fix: resolve MCP tool validation errors in beta server#106

Merged
viratatwebflow merged 1 commit intosaifrom
fix/mcp-validation-errors
Apr 6, 2026
Merged

fix: resolve MCP tool validation errors in beta server#106
viratatwebflow merged 1 commit intosaifrom
fix/mcp-validation-errors

Conversation

@kiratchhina
Copy link
Copy Markdown
Collaborator

Summary

This PR fixes two validation errors in the beta MCP server that were causing tool failures in production.

Issue 1: Site Publishing Fails with customDomains Validation Error

Production Error:

{
  "message": "Validation Error: [\"Value (customDomains)'s type should be array\"]",
  "code": "validation_error",
  "statusCode": 400
}

Event ID: evt_3BlCAWmNUYSYB94s8VTWyvCJ5d0
Actor: kelly@vector.co
Timestamp: Apr 1, 2026, 10:35:26 AM

Root Cause:
Incorrect Zod chaining order in sites.ts. When .default([]) comes before .optional(), the field can still be undefined, causing the Webflow API to reject the request.

Before:

customDomains: z
  .array(z.string())
  .default([])      // ❌ Wrong order
  .optional()

After:

customDomains: z
  .array(z.string())
  .optional()       // ✅ Correct order
  .default([])

Why this works:
In Zod, .optional().default([]) ensures that if the field is omitted, it defaults to []. With the original order, the field could be undefined even with .default([]), which caused the API validation to fail.


Issue 2: Empty Error Messages in element_snapshot_tool

Production Error:

{
  "name": "Error",
  "message": "",
  "error": {}
}

Event ID: evt_3BpOqtX0Z2ZbizQ06We4pzL88rg
Resource: element_snapshot_tool
Timestamp: Apr 2, 2026, 10:18:58 PM

Root Cause:
When element_snapshot_tool's RPC call fails and returns an empty message, the error handler creates new Error(""), resulting in unhelpful debugging information.

Before:

return formatErrorResponse(new Error(message)); // ❌ Empty message

After:

return formatErrorResponse(
  new Error(
    message ||
    `Element snapshot failed with status: ${status}. Response: ${JSON.stringify({ status, message, data })}`
  )
);

Why this works:
Provides a fallback error message with full response details when the RPC call returns an empty message, making debugging significantly easier.


Testing

  • ✅ Changes applied to beta server only (mcp-server-beta)
  • ✅ Stable server unchanged for safety
  • ✅ Both fixes address real production errors with documented event IDs

Files Changed

  • mcp-server-beta/src/tools/sites.ts - Fixed customDomains Zod chaining
  • mcp-server-beta/src/tools/deElement.ts - Fixed empty error messages

Next Steps

After validation in beta:

  1. Monitor for recurrence of these errors
  2. If successful, apply to stable server
  3. Consider auditing other tools for similar patterns

## Issue 1: Site publishing fails with customDomains validation error

**Error:**
```
"message": "Validation Error: [\"Value (customDomains)'s type should be array\"]",
"code": "validation_error"
```

**Root cause:**
Incorrect Zod chaining order in sites.ts. When `.default()` comes before
`.optional()`, the field can still be `undefined`, causing the Webflow API
to reject the request.

**Fix:**
Changed customDomains schema from:
```typescript
z.array(z.string()).default([]).optional()
```
To:
```typescript
z.array(z.string()).optional().default([])
```

This ensures customDomains always defaults to an empty array instead of
potentially being undefined.

**Files changed:**
- mcp-server-beta/src/tools/sites.ts

## Issue 2: Empty error messages in element_snapshot_tool

**Error:**
```json
{
  "name": "Error",
  "message": "",
  "error": {}
}
```

**Root cause:**
When element_snapshot_tool's RPC call fails with an empty message, the error
handler creates `new Error("")`, resulting in unhelpful empty error messages.

**Fix:**
Added fallback error message with response details:
```typescript
new Error(
  message ||
  \`Element snapshot failed with status: \${status}. Response: \${JSON.stringify({ status, message, data })}\`
)
```

**Files changed:**
- mcp-server-beta/src/tools/deElement.ts

**Testing:**
These fixes target the beta server only for validation before rolling out
to stable.
@kiratchhina kiratchhina requested a review from a team as a code owner April 3, 2026 04:00
@kiratchhina kiratchhina requested review from morganthrapp and removed request for a team April 3, 2026 04:00
@viratatwebflow viratatwebflow merged commit 3ea1c44 into sai Apr 6, 2026
6 checks passed
@viratatwebflow viratatwebflow deleted the fix/mcp-validation-errors branch April 6, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants