Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions marimo/_mcp/server/tools/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from marimo._mcp.server.responses import (
SuccessResult,
)
from marimo._messaging.ops import VariableValue
from marimo._server.api.deps import AppStateBase
from marimo._types.ids import CellId_t, SessionId

Expand Down Expand Up @@ -69,7 +68,14 @@ class CellRuntimeMetadata:
execution_time: Optional[float]


CellVariables = dict[str, VariableValue]
@dataclass(kw_only=True)
class CellVariableValue:
name: str
value: Optional[str] = None
datatype: Optional[str] = None


CellVariables = dict[str, CellVariableValue]


@dataclass(kw_only=True)
Expand Down Expand Up @@ -407,6 +413,11 @@ def _get_cell_variables(
for var_name in cell_defs:
if var_name in all_variables:
var_value = all_variables[var_name]
cell_variables[var_name] = var_value
# Convert VariableValue to pydantic parsable dataclass
cell_variables[var_name] = CellVariableValue(
name=var_name,
value=var_value.value,
datatype=var_value.datatype,
)

return cell_variables
16 changes: 14 additions & 2 deletions tests/_mcp/server/tools/test_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CellErrors,
CellRuntimeMetadata,
CellVariables,
CellVariableValue,
SupportedCellType,
_determine_cell_type,
_get_cell_errors,
Expand Down Expand Up @@ -241,7 +242,14 @@ def test_get_cell_variables_with_variables():

result = _get_cell_variables(session, cell_data)

expected: CellVariables = {"x": var_x, "y": var_y}
expected: CellVariables = {
"x": CellVariableValue(
name="x", value=var_x.value, datatype=var_x.datatype
),
"y": CellVariableValue(
name="y", value=var_y.value, datatype=var_y.datatype
),
}
assert result == expected
assert (
"z" not in result
Expand All @@ -262,5 +270,9 @@ def test_get_cell_variables_missing_variables():
result = _get_cell_variables(session, cell_data)

# Should only include variables that exist in session
expected: CellVariables = {"x": var_x}
expected: CellVariables = {
"x": CellVariableValue(
name="x", value=var_x.value, datatype=var_x.datatype
)
}
assert result == expected
Loading