Skip to content

Annotate the actions that declare an outputSchema as PageResult - #14

Merged
arrufat merged 1 commit into
mainfrom
generated-return-types
Oct 1, 2026
Merged

arrufat merged 1 commit into
mainfrom
generated-return-types

Conversation

@arrufat

@arrufat arrufat commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Item 1 of #6, as far as the wire allows.

lightpanda-io/browser#3694 gave goto, click, fill, scroll, hover, press, selectOption and setChecked a structuredContent answer, declared by an outputSchema on tools/list, and Session.call already turns that answer into a PageResult (#12). generate_methods.py now reads the schema, so those sixteen methods (sync and async) are annotated -> PageResult instead of -> Any. Nothing in the generator names the eight tools: a tool that gains or drops an outputSchema changes its annotation on the next regeneration, which CI already enforces.

Browser.tools keeps the schema as output_schema (None when a tool declares none), which is where the generator reads it.

PageResult is imported under TYPE_CHECKING in the generated module, because browser.py imports _methods.py and a runtime import would be circular. pdoc evaluates that block: the rendered page links all sixteen return annotations to PageResult.

The regeneration also picks up nightly's reworded goto description (it now points at the HTTP status), which main would need anyway to pass the drift check.

Still Any

The data tools (tree, links, extract, …) return JSON as text, and MCP carries no shape for that unless the tool declares an outputSchema, which #3694 deliberately left off them (it would oblige a structuredContent copy of a payload that can run to tens of KB, and arrays would need a wrapper). Narrowing those would mean a hand-written map in the generator, which is what this approach avoids. Several of their descriptions already state the shape in prose, and that prose is in the docstrings.

The eight tools that answer with structuredContent (goto and the actions)
now say so on tools/list with an outputSchema, and `Session.call` already
returns a `PageResult` for exactly those answers. The generator reads that
schema, so their methods are annotated `-> PageResult` instead of `Any`
without a hand-maintained list. `Browser.tools` carries it as
`output_schema`.

`PageResult` is imported under TYPE_CHECKING, since browser.py imports
the generated module; pdoc still resolves and links it.

Also picks up nightly's new `goto` description.

Part of #6.
@arrufat
arrufat merged commit c7ca24f into main Oct 1, 2026
11 checks passed
@arrufat
arrufat deleted the generated-return-types branch October 1, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant