Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/social-zoos-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@inkeep/agents-run-api": patch
"@inkeep/agents-cli": patch
"@inkeep/agents-eval-api": patch
"@inkeep/agents-manage-api": patch
"@inkeep/agents-manage-ui": patch
"@inkeep/agents-core": patch
"@inkeep/agents-manage-mcp": patch
"@inkeep/agents-sdk": patch
"@inkeep/ai-sdk-provider": patch
"@inkeep/create-agents": patch
---

error handling
27 changes: 24 additions & 3 deletions agents-run-api/src/agents/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,11 +838,32 @@ export class Agent {

logger.debug({ toolName, toolCallId }, 'MCP Tool Called');

// HTTP status codes that indicate an error response from Speakeasy MCP tools
const SPEAKEASY_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;

try {
const rawResult = await originalTool.execute(finalArgs, { toolCallId });

if (rawResult && typeof rawResult === 'object' && rawResult.isError) {
const errorMessage = rawResult.content?.[0]?.text || 'MCP tool returned an error';
const hasExplicitError = rawResult && typeof rawResult === 'object' && rawResult.isError;
// Parse content text (MCP returns JSON string)
let contentText: any;
try { contentText = JSON.parse(rawResult?.content?.[0]?.text); } catch {}
const hasErrorInContent =
contentText?.StatusCode &&
SPEAKEASY_ERROR_STATUS_CODES.includes(contentText.StatusCode);

if (hasExplicitError || hasErrorInContent) {
const rawText = rawResult?.content?.[0]?.text;
const errorMessage =
typeof rawText === 'string' ? rawText : JSON.stringify(rawText) || 'MCP tool returned an error';
logger.error(
{ toolName, toolCallId, errorMessage, rawResult },
'MCP tool returned error status'
Expand Down
Loading