Skip to content

Conversation

@bjoaquinc
Copy link
Contributor

@bjoaquinc bjoaquinc commented Sep 5, 2025

📝 Summary

During migration of the mcp-server from TypedDict to dataclass VariableValue caused a pydantic parsing error due to mgspec.Struct not being a pydantic-compatible type. I resolved this by creating a type called CellVariableValue that mirrors VariableValue but is pydantic-compatible.

Screenshot 2025-09-06 at 12 38 18 AM

🔍 Description of Changes

📋 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 5, 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 5, 2025 10:49pm

@manzt
Copy link
Contributor

manzt commented Sep 5, 2025

@mscolnick , when we make a msgspec BaseStruct we could try to add support for serialization with pydantic more generally:

class BaseStruct(msgspec.Struct):

    def __get_pydantic_core_schema__(self): ...
    

@mscolnick mscolnick merged commit c7be32a into marimo-team:main Sep 6, 2025
33 of 37 checks passed
@bjoaquinc bjoaquinc deleted the pydantic-parsing-error branch September 6, 2025 07:23
@manzt manzt added the bug Something isn't working label Sep 11, 2025
mscolnick pushed a commit that referenced this pull request Sep 26, 2025
…ma__ class method and refactor MCP msgspec.Struct types to use it (#6540)

## 📝 Summary

<!--
Provide a concise summary of what this pull request is addressing.

If this PR fixes any issues, list them here by number (e.g., Fixes
#123).
-->
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

<!--
Detail the specific changes made in this pull request. Explain the
problem addressed and how it was resolved. If applicable, provide before
and after comparisons, screenshots, or any relevant details to help
reviewers understand the changes easily.
-->
- 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

- [x] I have read the [contributor
guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md).
- [ ] For large changes, or changes that affect the public API: this
change was discussed or approved through an issue, on
[Discord](https://marimo.io/discord?ref=pr), or the community
[discussions](https://github.com/marimo-team/marimo/discussions) (Please
provide a link if applicable).
- [ ] I have added tests for the changes made.
- [x] I have run the code and verified that it works as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants