Skip to content

Handle errors thrown in McpAgent init method showing the error message in the response or add an onError method #385

Description

@remorses

Currently if the init method in McpAgent throws an error the user will only see Error 1101

This is not ideal. If I wrap the serveSSE methods calls with catch I still see the Error 1101 screen

export class MyMCP extends McpAgent<Env> {
    server = new Server(
        {
            name: 'Framer MCP',
            version: '1.8.0',
        },
        {
            capabilities: {
                tools: {},
                prompts: {},
                resources: {},
            },
        },
    )

    // ideal solution, allow user to handle errors. Pass a default onError handler
    async onError(error) {
        return new Response(
            error instanceof Error ? error.message : String(error),
            { status: 500 },
        )
    }

    async init() {
        throw new Error(
            'this error is impossible to handle sending a Response back',
        )
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions