Skip to content

Conversation

@bjoaquinc
Copy link
Contributor

@bjoaquinc bjoaquinc commented Sep 26, 2025

📝 Summary

Create BaseStruct to make msgspec.Struct types compatible with pydantic typechecking (for MCP Server tools). Update old code to now use this and remove redundant types.

This PR reverses the temporary fix implemented in #6265

🔍 Description of Changes

  • Create BaseStruct with get_pydantic_core_schema in marimo/_utils/msgspec_basestruct.py
  • Update datatypes in marimo/_data/models.py to use BaseStruct for marimo/_ai/_tools/tools/tables_and_variables.py tool
  • Update CellVariableValue -> VariableValue(BaseStruct) in tables_and_variables.py and cells.py
  • Update tests to use VariableValue, inherit Session for type saftey, and use correct DataType enums
  • Add pydantic >2 as mcp dependency in pyproject.toml
  • Add test that checks if all exposed msgspec.Struct classes exposed to tools Args or Output use BaseStruct

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • I have added tests for the changes made.
  • I have run the code and verified that it works as expected.

@vercel
Copy link

vercel bot commented Sep 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Sep 26, 2025 3:26pm

if var_name in all_variables:
var_value = all_variables[var_name]
cell_variables[var_name] = CellVariableValue(
cell_variables[var_name] = VariableValue(
Copy link
Contributor

Choose a reason for hiding this comment

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

could this just be cell_variables[var_name] = var_value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that makes sense. Done!

mscolnick
mscolnick previously approved these changes Sep 26, 2025
@mscolnick mscolnick merged commit 93398c2 into marimo-team:main Sep 26, 2025
37 of 39 checks passed
@bjoaquinc bjoaquinc deleted the msgspec-pydantic-integration branch September 26, 2025 16:01
@dmadisetti dmadisetti added the enhancement New feature or request label Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants