Skip to main content
Glama

set_cell_value

Update specific spreadsheet cells by row and column coordinates to modify CSV data values, tracking changes and returning operation results with data types.

Instructions

Set value of specific cell with coordinate targeting.

Supports column name or index, tracks old and new values. Returns operation result with coordinates and data type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
row_indexYesRow index (0-based) to update cell in
columnYesColumn name or column index (0-based) to update
valueYesNew value to set in the cell (str, int, float, bool, or None)

Implementation Reference

  • The handler function that executes the set_cell_value tool. Validates inputs, retrieves and updates the cell value in the pandas DataFrame, handles type conversions, tracks old/new values, and returns a SetCellResult.
    def set_cell_value( ctx: Annotated[Context, Field(description="FastMCP context for session access")], row_index: Annotated[int, Field(description="Row index (0-based) to update cell in")], column: Annotated[ str | int, Field(description="Column name or column index (0-based) to update"), ], value: Annotated[ CellValue, Field(description="New value to set in the cell (str, int, float, bool, or None)"), ], ) -> SetCellResult: """Set value of specific cell with coordinate targeting. Supports column name or index, tracks old and new values. Returns operation result with coordinates and data type. """ session_id = ctx.session_id _session, df = get_session_data(session_id) # Validate row index if row_index < 0 or row_index >= len(df): msg = f"Row index {row_index} out of range (0-{len(df) - 1})" raise ToolError(msg) # Handle column specification if isinstance(column, int): # Column index if column < 0 or column >= len(df.columns): msg = f"Column index {column} out of range (0-{len(df.columns) - 1})" raise ToolError(msg) column_name = df.columns[column] else: # Column name if column not in df.columns: raise ColumnNotFoundError(column, list(df.columns)) column_name = column # Get the old value for tracking old_value = df.iloc[row_index, df.columns.get_loc(column_name)] # type: ignore[index] if pd.isna(old_value): old_value = None elif hasattr(old_value, "item"): # numpy scalar old_value = old_value.item() # type: ignore[assignment] # Set the new value with explicit type conversion to avoid dtype compatibility warnings col_idx = df.columns.get_loc(column_name) current_dtype = df[column_name].dtype # Access dtype through column name instead # Convert value to match column dtype if possible converted_value: CellValue try: if pd.api.types.is_numeric_dtype(current_dtype) and isinstance(value, str): numeric_result = pd.to_numeric(value, errors="coerce") # Convert pandas numeric to Python type for CellValue compatibility if pd.isna(numeric_result): converted_value = None else: converted_value = ( float(numeric_result) if isinstance(numeric_result, (int, float)) else numeric_result.item() ) else: converted_value = value except (ValueError, TypeError): converted_value = value df.iloc[row_index, col_idx] = converted_value # type: ignore[index] # Get the new value for tracking (after pandas type conversion) new_value = df.iloc[row_index, df.columns.get_loc(column_name)] # type: ignore[index] if pd.isna(new_value): new_value = None elif hasattr(new_value, "item"): # numpy scalar new_value = new_value.item() # type: ignore[assignment] # Get column data type data_type = str(df[column_name].dtype) # No longer recording operations (simplified MCP architecture) return SetCellResult( coordinates={"row": row_index, "column": column_name}, old_value=old_value, new_value=new_value, data_type=data_type, )
  • Registers the set_cell_value handler as an MCP tool named 'set_cell_value' on the FastMCP server instance.
    row_operations_server.tool(name="set_cell_value")(set_cell_value)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jonpspri/databeak'

If you have feedback or need assistance with the MCP directory API, please join our Discord server