Skip to content

feat: Add script to extract RPC method documentation#3853

Open
Mrtenz wants to merge 10 commits intomainfrom
mrtenz/extract-rpc-methods
Open

feat: Add script to extract RPC method documentation#3853
Mrtenz wants to merge 10 commits intomainfrom
mrtenz/extract-rpc-methods

Conversation

@Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Feb 12, 2026

This adds a script to extract types and documentation from the snaps-rpc-methods, which can then be used to generate documentation. It works by looking at the TypeScript AST to extract properties and type information, writing the result to a JSON file.

To make it easier to use the JSON in the docs website, it will be published to a schema directory on GitHub Pages.


Note

Medium Risk
Introduces a large new codegen script and changes handler/type definitions to support extraction, plus adds new release-time GitHub Pages publishing; failures could break schema/docs publishing or subtly alter exported types.

Overview
Adds a new @metamask/snaps-rpc-methods build step (build:schema) that generates schema/schema.json by walking the TypeScript AST to extract each permitted/restricted JSON-RPC method’s name, JSDoc description, params/result type strings, allowed caller type, and @example blocks.

Updates permitted handler exports to use satisfies PermittedHandlerExport with methodNames: [methodName] as const (to preserve literal types for extraction), tweaks a few SDK method type docs/aliases (notably DialogResultJson), and wires CI to publish the generated schema/ directory to gh-pages for main (schema/staging) and releases (schema/<tag> plus schema/latest).

Written by Cursor Bugbot for commit 32f4f4c. This will update automatically on new commits. Configure here.

@socket-security
Copy link

socket-security bot commented Feb 12, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedts-morph@​27.0.210010010082100

View full report

@socket-security
Copy link

socket-security bot commented Feb 12, 2026

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring alerts on:

  • @ts-morph/common@0.28.1

View full report

@Mrtenz
Copy link
Member Author

Mrtenz commented Feb 16, 2026

@SocketSecurity ignore npm/@ts-morph/common@0.28.1
Seems to be a false positive.

@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.59%. Comparing base (1052962) to head (32f4f4c).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3853      +/-   ##
==========================================
- Coverage   98.59%   98.59%   -0.01%     
==========================================
  Files         429      429              
  Lines       12417    12413       -4     
  Branches     1928     1928              
==========================================
- Hits        12242    12238       -4     
  Misses        175      175              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Mrtenz Mrtenz marked this pull request as ready for review February 16, 2026 14:34
@Mrtenz Mrtenz requested a review from a team as a code owner February 16, 2026 14:34
@FrederikBolding FrederikBolding self-requested a review February 16, 2026 14:41
}: DialogMethodHooks) {
return async function dialogImplementation(
args: RestrictedMethodOptions<DialogParameters>,
): Promise<boolean | null | string | Json> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some ways this was better at documenting the return types being different for different inputs 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but this was inferred as Json anyway. It was causing the type to be extracted in a weird way because of an edge case. I can add a way to handle the edge case as well instead of changing the type here, if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just documenting it thoroughly is better since it will be inferred for consumers.

Comment on lines 102 to 103
* - If the dialog is a `prompt`, the result is the value entered by
* the user.
Copy link
Member

@FrederikBolding FrederikBolding Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - If the dialog is a `prompt`, the result is the value entered by
* the user.
* - If the dialog is a `prompt`, the result is the value entered by
* the user.
* - If the dialog has no type, the result is entirely up to the Snap.

Or similar?

methodNames: [methodName] as const,
implementation: getCancelBackgroundEventImplementation,
hookNames,
} satisfies PermittedHandlerExport<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem with the changes, but why is this preferred?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes it slightly easier to extract type information. When using const foo: Type, any specific type information is lost. Could potentially work around the changes by looking at the type nodes (AST) instead of types, but this seemed like a better solution.

};

export const providerRequestHandler: PermittedHandlerExport<
export const providerRequestHandler = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized we should remove this, will open a PR

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.

2 participants