Skip to content

chore: improve tool input schema typing - #166

Open
f3tchcodes wants to merge 3 commits into
mozilla:mainfrom
f3tchcodes:chore/type-tool-input-schema
Open

chore: improve tool input schema typing#166
f3tchcodes wants to merge 3 commits into
mozilla:mainfrom
f3tchcodes:chore/type-tool-input-schema

Conversation

@f3tchcodes

Copy link
Copy Markdown
Contributor

Improving tools defination typing by adding interface for inputSchema.

@juliandescottes juliandescottes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Before we merge this, what is the intent: documentation (+ code hints etc...) or strict typechecks?

If we want to enforce a strict typecheck, at the moment it's not enough because many modules define tools which have very simple schemas. Example for clearConsole:

  inputSchema: {
    type: 'object',
    properties: {},
  },

Because of this above, all the other Console tools' properties will not be strictly checked (it's apparently known as subtype reduction, but I don't know much about typescript). And as I said that's the case for most modules at the moment.

If we want to enforce it, we would need to annotate all tools with satisfies ToolDefinition.

While I am a bit worried about freezing the shape of schema based on the current tools, at least if we have consistent failures when a tool no longer matches it, it will be easy to maintain.

Can you annotate the tools as suggested?

@f3tchcodes

f3tchcodes commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Yes, the intent was compile time checking.

The reason I initially didn't add satisfies ToolDefinition to every tool definition was mainly to avoid repeating it across every tool, since all of the definitions get passed through defineModule(...) for typechecking at the end anyway.

I expected the ToolDefinition typing there to provide the compile time checking at defineModule(...), but after some more research I see what you mean about subtype reduction allowing some definitions to avoid being checked as strictly as intended.

I can add satisfies ToolDefinition to each tool definition so the check is enforced, let me know if that's fine.

That should also let us make the schema typing stricter (adding stricter types for type property rather than keeping it string), since each tool defination would now be checked against ToolDefinition at declaration.

@juliandescottes

Copy link
Copy Markdown
Collaborator

I expected the ToolDefinition typing there to provide the compile time checking at defineModule(...), [...]

Same here, I was quite surprised it didn't work out of the box.

I can add satisfies ToolDefinition to each tool definition so the check is enforced, let me know if that's fine.

Yes, let's add the annotation, thanks!

@juliandescottes juliandescottes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's add the annotations :)

@f3tchcodes
f3tchcodes force-pushed the chore/type-tool-input-schema branch from 48b3044 to 9b55067 Compare August 25, 2026 21:14
@f3tchcodes

Copy link
Copy Markdown
Contributor Author

Added!

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