{"record":{"id":"5f3fc1fcaf460060","repo":"langchain-ai/deepagents","slug":"callback-url-is-missing-the-code-parameter","errorCode":null,"errorMessage":"Callback URL is missing the 'code' parameter.","messagePattern":"Callback URL is missing the 'code' parameter\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_auth.py","lineNumber":1195,"sourceCode":"    Args:\n        url: Raw callback URL pasted by the user.\n\n    Returns:\n        The `code` and optional `state` query parameters.\n\n    Raises:\n        RuntimeError: If the URL contains `error=` or lacks `code`.\n    \"\"\"\n    params = parse_qs(urlparse(url).query)\n    if \"error\" in params:\n        err_code = params[\"error\"][0]\n        err_desc = (params.get(\"error_description\") or [\"\"])[0]\n        detail = f\": {err_desc}\" if err_desc else \"\"\n        msg = f\"Authorization denied by provider: {err_code}{detail}\"\n        raise RuntimeError(msg)\n    if \"code\" not in params or not params[\"code\"]:\n        msg = \"Callback URL is missing the 'code' parameter.\"\n        raise RuntimeError(msg)\n    return params[\"code\"][0], (params.get(\"state\") or [None])[0]\n\n\ndef _default_ui() -> OAuthInteraction:\n    \"\"\"Return the default `OAuthInteraction` implementation (CLI stdio).\"\"\"\n    from deepagents_code.mcp_oauth_ui import CliOAuthInteraction\n\n    return CliOAuthInteraction()\n\n\ndef _make_loopback_handlers(\n    *,\n    callback_server: _LoopbackOAuthCallbackServer,\n    extra_auth_params: dict[str, str] | None = None,\n    ui: OAuthInteraction | None = None,\n) -> tuple[RedirectHandler, CallbackHandler]:\n    \"\"\"Create browser loopback redirect and callback handlers for OAuth.\n","sourceCodeStart":1177,"sourceCodeEnd":1213,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_auth.py#L1177-L1213","documentation":"_parse_callback_url requires an authorization `code` query parameter to exchange for tokens; a callback URL without one (and without an `error` parameter) is malformed and raises this RuntimeError. It protects against pasting the wrong URL or a truncated redirect.","triggerScenarios":"callback -> _parse_callback_url receives a URL missing `code` or with an empty `code` value - e.g. the base redirect URL pasted with no query string, or a URL that only carried `state`.","commonSituations":"User pasted the wrong URL from the browser (e.g. the login page or a truncated address bar copy), the provider redirected without a code because of a misconfigured redirect URI, or browser extensions stripped query parameters.","solutions":["Redo the login (`/mcp login <server>` / `dcode mcp login <server>`) and copy the full callback URL including ?code=...&state=...","Verify the provider's registered redirect URI matches what the tool expects so the provider actually issues a code.","If paste-back keeps failing, use the browser-based local callback listener instead of manual paste, or vice versa."],"exampleFix":"// before\nhttp://localhost:PORT/callback?state=abc            # missing code\n// after\nhttp://localhost:PORT/callback?code=xyz&state=abc   # full redirect URL from the provider","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse, parse_qs\nq = parse_qs(urlparse(callback_url).query)\nassert q.get(\"code\"), \"URL lacks authorization code; copy the full provider redirect URL\"","typeGuard":null,"tryCatchPattern":"try:\n    code, state = _parse_callback_url(url)\nexcept RuntimeError as e:\n    if \"missing the 'code' parameter\" in str(e):\n        show_user(\"Paste the complete redirect URL including ?code=...; restarting login.\")\n        restart_login_flow(server_name)\n    else:\n        raise","preventionTips":["Copy the whole callback URL from the browser address bar, including all query parameters.","Prefer the automatic local-callback listener over manual URL pasting when available.","Check the provider's redirect URI configuration if codes are consistently absent."],"tags":["mcp","oauth","callback","validation"],"backgroundTag":"oauth-missing-code-parameter","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}