-
Notifications
You must be signed in to change notification settings - Fork 86
error handling for speakeasy mcps #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 914609b The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
Claude finished @shagun-singh-inkeep's task —— View job Code Review: Error Handling for Speakeasy MCPsTodo List
Review FindingsHigh Priority Issues1. Unsafe JSON Parsing (Security & Stability Risk) // Line 846: Silent failure could mask errors
try { contentText = JSON.parse(rawResult?.content?.[0]?.text); } catch {}Issues:
Recommendation: let contentText: any;
try {
const rawText = rawResult?.content?.[0]?.text;
if (typeof rawText === 'string') {
contentText = JSON.parse(rawText);
}
} catch (parseError) {
logger.warn({
toolName,
toolCallId,
parseError: parseError.message,
rawText: rawResult?.content?.[0]?.text
}, 'Failed to parse MCP tool response as JSON');
}2. Hardcoded HTTP Status Codes (Maintainability) [400, 401, 403, 404, 422, 500].includes(contentText.StatusCode)Issues:
Recommendation: const ERROR_STATUS_CODES = [
400, // Bad Request
401, // Unauthorized
403, // Forbidden
404, // Not Found
422, // Unprocessable Entity
429, // Rate Limited
500, // Internal Server Error
503 // Service Unavailable
] as const;
const hasErrorInContent =
contentText?.StatusCode &&
ERROR_STATUS_CODES.includes(contentText.StatusCode);Medium Priority Issues3. Type Safety & Validation
Recommendation: Define proper interfaces: interface MCPToolResponse {
StatusCode?: number;
// other expected fields
}
interface MCPRawResult {
isError?: boolean;
content?: Array<{ text?: string }>;
}4. Inconsistent Error Message Handling const errorMessage = typeof rawText === 'string' ? rawText : JSON.stringify(rawText) || 'MCP tool returned an error';Recommendation: const errorMessage = rawText || 'MCP tool returned an error';Architecture & Design Considerations5. Single Responsibility Principle private isErrorResult(rawResult: unknown): { isError: boolean; errorMessage: string } {
// Extract all error detection logic here
}6. Logging Strategy if (hasExplicitError) {
logger.error({ toolName, toolCallId, errorType: 'explicit' }, 'MCP tool explicit error');
} else if (hasErrorInContent) {
logger.error({ toolName, toolCallId, errorType: 'status_code', statusCode: contentText.StatusCode }, 'MCP tool status code error');
}Questions for Clarification
Positive Aspects
Testing RecommendationsConsider adding tests for:
|
No description provided.