Build a structured MCP error response for tool calls (L3 error compliance).
(code: string, opts: { message: string; details?: unknown; recovery?: string; field?: string }, context?: unknown)
| 49 | |
| 50 | /** Build a structured MCP error response for tool calls (L3 error compliance). */ |
| 51 | function adcpError(code: string, opts: { message: string; details?: unknown; recovery?: string; field?: string }, context?: unknown) { |
| 52 | const errorObj = { code, ...opts }; |
| 53 | const body = context !== undefined |
| 54 | ? { adcp_error: errorObj, context } |
| 55 | : { adcp_error: errorObj }; |
| 56 | return { |
| 57 | isError: true, |
| 58 | content: [{ type: 'text' as const, text: JSON.stringify(body) }], |
| 59 | structuredContent: body, |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | // Derive types from SDK request types that aren't re-exported from main entry |
| 64 | type PackageUpdate = NonNullable<UpdateMediaBuyRequest['packages']>[number]; |