Skip to content

How does fallback_interceptor works?Β #418

@Makoish

Description

@Makoish

Hello, I am trying to implement something using playwright MCP, sometimes this error happens [Cannot read property innerText](https://stackoverflow.com/questions/63367277/cannot-read-property-innertext-of-null-for-valid-selector-using-playwright) I want to ignore this error when it happens because it closes the session while I want to continue the navigation. I found https://docs.langchain.com/oss/python/langchain/mcp#writing-interceptors that I guess is the solution to my issue but it's not working probably with me so I guess I am doing something wrong

async def fallback_interceptor(
    request: MCPToolCallRequest,
    handler,
):
    """Return a fallback value if tool execution fails."""

    raise ValueError()
    try:
        return await handler(request)
    except Exception as e:
        
        return f"Tool {request.name} timed out. Ignore it and continue navigation"

  try:
        mcp_client = MultiServerMCPClient(connections=PLAYWRIGHT_MCP_CONNECTION, tool_interceptors=[fallback_interceptor])
        async with mcp_client.session("playwright") as session:
            available_tools: List[BaseTool] = await load_mcp_tools(session)
            llm = init_chat_model(
                model=LLM_MODEL_NAME, 
                model_provider="google_genai", 
                google_api_key=os.getenv("GOOGLE_KEY")
            )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions