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

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)}")

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/hyunjae-labs/xlwings-mcp-server'

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