Skip to main content
Glama

select_columns

Extract specific columns from a dataframe while removing all others, validating column existence and reordering by selection order.

Instructions

Select specific columns from dataframe, removing all others.

Validates column existence and reorders by selection order. Returns selection details with before/after column counts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
columnsYesList of column names to select and keep

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
successNoWhether operation completed successfully
columns_afterYesNumber of columns after selection
columns_beforeYesNumber of columns before selection
selected_columnsYesList of selected column names

Implementation Reference

  • The main handler function for the 'select_columns' tool. It retrieves the current dataframe from the session, validates that the specified columns exist, creates a new dataframe with only the selected columns, updates the session, and returns a SelectColumnsResult with details on the selection.
    async def select_columns(
        ctx: Annotated[Context, Field(description="FastMCP context for session access")],
        columns: Annotated[list[str], Field(description="List of column names to select and keep")],
    ) -> SelectColumnsResult:
        """Select specific columns from dataframe, removing all others.
    
        Validates column existence and reorders by selection order. Returns selection details with
        before/after column counts.
        """
        # Get session_id from FastMCP context
        session_id = ctx.session_id
        session, df = get_session_data(session_id)
    
        # Validate columns exist
        missing_cols = [col for col in columns if col not in df.columns]
        if missing_cols:
            raise ColumnNotFoundError(missing_cols[0], df.columns.tolist())
    
        # Track counts before modification
        columns_before = len(df.columns)
    
        session.df = df[columns].copy()
        # No longer recording operations (simplified MCP architecture)
    
        return SelectColumnsResult(
            selected_columns=columns,
            columns_before=columns_before,
            columns_after=len(columns),
        )
  • Pydantic model defining the response schema for the 'select_columns' tool, including selected columns and before/after column counts.
    class SelectColumnsResult(BaseToolResponse):
        """Result of selecting specific columns."""
    
        model_config = ConfigDict(extra="forbid")
    
        selected_columns: list[str] = Field(description="List of selected column names")
        columns_before: int = Field(description="Number of columns before selection")
        columns_after: int = Field(description="Number of columns after selection")
  • Registration of the 'select_columns' tool on the column_server FastMCP instance.
    column_server.tool(name="select_columns")(select_columns)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: validation of column existence, reordering by selection order, and returning details with before/after counts. This covers mutation effects (removing columns), error handling (validation), and output format, though it could mention performance implications or data integrity aspects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is highly concise and front-loaded, with three sentences that each add value: the core action, validation/reordering details, and return information. There is no wasted text, and it efficiently communicates essential information without redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (dataframe mutation), no annotations, and the presence of an output schema (which handles return values), the description is largely complete. It covers purpose, behavior, and output context well. However, it could improve by mentioning potential errors (e.g., invalid column names) or linking to sibling tools for better integration, keeping it from a perfect score.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the parameter 'columns' well-documented in the schema. The description adds minimal semantics beyond the schema, only implying that columns are selected and kept in order. Since the schema already fully describes the parameter, the baseline score of 3 is appropriate, as the description does not significantly enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Select specific columns from dataframe, removing all others') and distinguishes it from sibling tools like 'remove_columns' (which likely removes specified columns while keeping others) and 'get_column_data' (which likely retrieves data without removing columns). It specifies both the selection and removal aspects, making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for selecting and reordering columns while removing others, but does not explicitly state when to use this tool versus alternatives like 'remove_columns' or 'rename_columns'. It provides context about validation and reordering, but lacks explicit guidance on scenarios or prerequisites for choosing this tool over siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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