Skip to content

OpenAPI tools ignore operation- and path-level server overrides #8064

Description

@sumedh-aerram

Describe the bug
OpenApiSpecParser always uses the root servers[0].url, even when a path item or an operation declares its own servers. Per the OpenAPI spec (Operation Object / Path Item Object), operation servers override path servers, and path servers override root servers. So every generated RestApiTool sends requests to the root server.

Root cause: openapi_spec_parser.py picks the root server once, outside the operation loop, and reuses it as base_url for every OperationEndpoint.

To reproduce (offline, on main)

from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_spec_parser import OpenApiSpecParser
from google.adk.tools.openapi_tool.openapi_spec_parser.rest_api_tool import RestApiTool

spec = {'openapi': '3.0.0', 'info': {'title': 'demo', 'version': '1'},
        'servers': [{'url': 'https://root.example.test/v1'}],
        'paths': {'/items': {
            'servers': [{'url': 'https://path.example.test/v2'}],
            'get': {'operationId': 'listItems',
                    'servers': [{'url': 'https://operation.example.test/v3'}],
                    'responses': {'200': {'description': 'OK'}}},
            'post': {'operationId': 'addItem',
                     'responses': {'200': {'description': 'OK'}}}}}}

for parsed in OpenApiSpecParser().parse(spec):
  tool = RestApiTool.from_parsed_operation(parsed)
  request = tool._prepare_request_params(tool._operation_parser.get_parameters(), {})
  print(parsed.endpoint.method.upper(), request['url'])

Expected: GET https://operation.example.test/v3/items and POST https://path.example.test/v2/items.

Actual: both go to https://root.example.test/v1/items.

Environment: ADK main (2.14.0), Python 3.11, macOS. No model involved.

I'd like to send a fix: choose the server per operation (operation, then path, then root, keeping the current fallback when none is declared), with parser tests for each level.

Activity

  1. julienparenti commented on Nov 10, 2026

    @julienparenti

    I'd like to take this one. I have a fix ready that resolves the base URL per operation in spec order (operation servers, then path servers, then root servers), with unit tests and an end-to-end check against local servers. I'll open a PR unless someone is already on it.

  2. added a commit that references this issue on Nov 10, 2026
    518500c
  3. sumedh-aerram commented on Nov 11, 2026

    @sumedh-aerram
    Author

    Thanks @julienparenti. Since #8088 is already up, go ahead with it and I will drop mine. One case worth covering if it isn't already: an explicitly empty servers: [] on a path or operation should fall through to the next level rather than produce an empty base URL.

  4. julienparenti commented on Nov 11, 2026

    @julienparenti

    Thanks @sumedh-aerram! Yes, an empty servers: [] falls through to the next level on both paths and operations. #8088 already tests the operation case, and I've just added test_empty_path_servers_fall_back_to_root_servers for the path case.

  5. sanketpatil06 commented on Nov 12, 2026

    @sanketpatil06

    Hi @sumedh-aerram, thanks for the report and repro.

    I've confirmed this on main. #8088 from @julienparenti fixes it by picking the server for each operation in spec order: operation, then path, then root. Locally, your repro now gives the expected URLs, and the existing tool tests pass.

    the PR is under review and will be merged once approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

tools[Component] This issue is related to tools

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions