oas2mcp.utils.lookup

Lookup helpers for normalized catalogs.

Purpose:

Provide convenient query helpers over normalized ApiCatalog objects so later classifiers and agents can work with targeted slices of the spec.

Design:
  • Keep helpers deterministic and side-effect free.

  • Return None for missing singular lookups rather than raising.

  • Preserve original operation objects rather than copying them.

Examples

operation = get_operation(catalog, method="GET", path="/pets/{petId}")
tagged = list_operations_by_tag(catalog, tag="pet")

Functions

get_operation(...)

Return one operation by HTTP method and path.

get_operation_by_id(...)

Return one operation by operationId.

get_security_scheme(...)

Return one security scheme by name.

list_mutating_operations(...)

Return all mutating operations.

list_operations_by_tag(...)

Return all operations associated with a tag.

list_read_operations(...)

Return all non-mutating operations.

Module Contents

oas2mcp.utils.lookup.get_operation(catalog: oas2mcp.models.normalized.ApiCatalog, *, method: str, path: str) oas2mcp.models.normalized.ApiOperation | None[source][source]

Return one operation by HTTP method and path.

Parameters:
  • catalog – The normalized API catalog.

  • method – The HTTP method to match.

  • path – The normalized or raw operation path.

Returns:

The matching operation if found, otherwise None.

Raises:

None.

Examples

operation = get_operation(
    catalog,
    method="GET",
    path="/pets/{petId}",
)
oas2mcp.utils.lookup.get_operation_by_id(catalog: oas2mcp.models.normalized.ApiCatalog, *, operation_id: str) oas2mcp.models.normalized.ApiOperation | None[source][source]

Return one operation by operationId.

Parameters:
  • catalog – The normalized API catalog.

  • operation_id – The target operationId.

Returns:

The matching operation if found, otherwise None.

Raises:

None.

Examples

operation = get_operation_by_id(
    catalog,
    operation_id="getPetById",
)
oas2mcp.utils.lookup.get_security_scheme(catalog: oas2mcp.models.normalized.ApiCatalog, *, name: str) oas2mcp.models.normalized.ApiSecurityScheme | None[source][source]

Return one security scheme by name.

Parameters:
  • catalog – The normalized API catalog.

  • name – The security scheme name.

Returns:

The matching security scheme if found, otherwise None.

Raises:

None.

Examples

scheme = get_security_scheme(catalog, name="api_key")
oas2mcp.utils.lookup.list_mutating_operations(catalog: oas2mcp.models.normalized.ApiCatalog) list[oas2mcp.models.normalized.ApiOperation][source][source]

Return all mutating operations.

Parameters:

catalog – The normalized API catalog.

Returns:

A list of mutating operations.

Raises:

None.

Examples

mutating = list_mutating_operations(catalog)
oas2mcp.utils.lookup.list_operations_by_tag(catalog: oas2mcp.models.normalized.ApiCatalog, *, tag: str) list[oas2mcp.models.normalized.ApiOperation][source][source]

Return all operations associated with a tag.

Parameters:
  • catalog – The normalized API catalog.

  • tag – The tag name to match.

Returns:

A list of matching operations.

Raises:

None.

Examples

pet_operations = list_operations_by_tag(catalog, tag="pet")
oas2mcp.utils.lookup.list_read_operations(catalog: oas2mcp.models.normalized.ApiCatalog) list[oas2mcp.models.normalized.ApiOperation][source][source]

Return all non-mutating operations.

Parameters:

catalog – The normalized API catalog.

Returns:

A list of read-oriented operations.

Raises:

None.

Examples

reads = list_read_operations(catalog)