Skip to content

Do not parameterize RootModel bases in generated types - #3413

Open
Viicos wants to merge 1 commit into
modelcontextprotocol:mainfrom
Viicos:vp/bare-rootmodel
Open

Do not parameterize RootModel bases in generated types#3413
Viicos wants to merge 1 commit into
modelcontextprotocol:mainfrom
Viicos:vp/bare-rootmodel

Conversation

@Viicos

@Viicos Viicos commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

When parameterized, a RootModel is usable directly as a type:

MyInt = RootModel[int]

MyInt.model_validate('1')
#> 1

However, when used as a base, the model build logic ends up running for nothing, because everything is overridden by the actual class:

class MyRoot(RootModel[int]):  # RootModel[int] is first built, then MyRoot
    root: int

By leaving models unparameterized, we gain some performance improvements on startup time: measured locally with hyperfine --warmup 3 --runs 50 'PYDANTIC_DISABLE_PLUGINS=1 python -c "from mcp_types import _types, _v2025_11_25, _v2026_07_28"':

before: 180ms, after: 170ms

I don't know if implementing a Jinja template is the right approach (there's a bit of duplication), but looks like it will be robust enough.

Motivation and Context

How Has This Been Tested?

Breaking Changes

Types of changes

Performance

Checklist

  • I am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer)
  • I have disclosed any AI assistance and can explain the change in my own words
  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Aug 29, 2026
@github-actions github-actions Bot closed this Aug 29, 2026
@maxisbey maxisbey added bypass-issue-check and removed missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) labels Aug 29, 2026
@maxisbey maxisbey reopened this Aug 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📚 Documentation preview

Preview https://pr-3413.mcp-python-docs.pages.dev
Deployment https://8dfb8138.mcp-python-docs.pages.dev
Commit e4dfda7
Triggered by @maxisbey
Updated 2026-08-29 20:54:11 UTC

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants