Skip to main content
Glama
hyunjae-labs

xlwings Excel MCP Server

by hyunjae-labs

list_workbooks

Retrieve information about all currently open Excel workbooks to monitor active sessions and manage workbook operations through the xlwings Excel MCP Server.

Instructions

List all open workbook sessions.

Returns:
    List of session information dictionaries

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler and registration for the 'list_workbooks' tool using @mcp.tool() decorator. Delegates to SESSION_MANAGER.list_sessions() to return list of active sessions.
    @mcp.tool()
    def list_workbooks() -> List[Dict[str, Any]]:
        """
        List all open workbook sessions.
        
        Returns:
            List of session information dictionaries
        """
        try:
            return SESSION_MANAGER.list_sessions()
        except Exception as e:
            logger.error(f"Error listing workbooks: {e}")
            raise WorkbookError(f"Failed to list workbooks: {str(e)}")
  • ExcelSessionManager.list_sessions(): Core logic that iterates over active sessions and calls get_info() on each to build the response list.
    def list_sessions(self) -> list:
        """List all active sessions"""
        with self._sessions_lock:
            return [session.get_info() for session in self._sessions.values()]
  • ExcelSession.get_info(): Provides the detailed information dictionary for each session, including ID, path, visibility, timestamps, and list of sheets.
    def get_info(self) -> Dict[str, Any]:
        """Get session information"""
        return {
            "session_id": self.id,
            "filepath": self.filepath,
            "visible": self.visible,
            "read_only": self.read_only,
            "created_at": datetime.fromtimestamp(self.created_at).isoformat(),
            "last_access": datetime.fromtimestamp(self.last_accessed).isoformat(),
            "sheets": [sheet.name for sheet in self.workbook.sheets] if self.workbook else []
        }
  • Tool registration via FastMCP @mcp.tool() decorator with inferred schema from type hints (no parameters, returns List[Dict[str, Any]]).
    @mcp.tool()
    def list_workbooks() -> List[Dict[str, Any]]:
        """
        List all open workbook sessions.
        
        Returns:
            List of session information dictionaries
        """
        try:
            return SESSION_MANAGER.list_sessions()
        except Exception as e:
            logger.error(f"Error listing workbooks: {e}")
            raise WorkbookError(f"Failed to list workbooks: {str(e)}")

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A3.9/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It only states it lists open sessions, with no mention of behavioral traits like permissions, side effects, or performance implications. For a read-only list operation, this is minimal but not harmful.

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 extremely concise with two sentences, no redundant information, and the key action is stated first. Every sentence adds value.

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

Completeness5/5

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

For a tool with no parameters and an output schema, the description sufficiently explains the purpose and return type. No additional context is needed.

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

Parameters4/5

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

There are zero parameters, so the description need not add parameter details. The baseline score of 4 is appropriate as there is nothing missing.

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 it lists all open workbook sessions, using a specific verb ('list') and resource ('open workbook sessions'). It distinguishes from other sibling tools that create, close, or modify workbooks.

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?

No explicit guidance on when or when not to use this tool versus alternatives. However, since it's the only list tool among siblings, the usage is implied. A score of 3 reflects the lack of explicit context.

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