rohitg00/ai-engineering-from-scratch · error · RuntimeError

response["error"]["message"]

Error message

response["error"]["message"]

What it means

Error "response["error"]["message"]" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at phases/11-llm-engineering/14-model-context-protocol/code/main.py:308

        return {"jsonrpc": "2.0", "id": request_id, "result": result}


class MCPClient:
    def __init__(self, server: MCPServer) -> None:
        self.server = server
        self._id = 0

    def request(self, method: str, params: dict[str, Any] | None = None) -> dict[str, Any]:
        self._id += 1
        request_params = dict(params or {})
        request_params["_meta"] = request_metadata()
        response = self.server.handle(
            {"jsonrpc": "2.0", "id": self._id, "method": method, "params": request_params}
        )
        if response is None:
            raise RuntimeError("request did not receive a response")
        if "error" in response:
            raise RuntimeError(response["error"]["message"])
        return response["result"]


server = MCPServer("demo-server")


@server.tool(
    "add",
    "Add two integers and return the sum.",
    {
        "type": "object",
        "properties": {"a": {"type": "integer"}, "b": {"type": "integer"}},
        "required": ["a", "b"],
    },
)
def add(a: int, b: int) -> dict[str, int]:
    return {"sum": a + b}

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at phases/11-llm-engineering/14-model-context-protocol/code/main.py:308 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/bf4d54e8ace5ee06. Report an issue: GitHub.