list_calendars
Retrieve a list of Feishu calendars with an optional limit on results.
Instructions
获取飞书日历列表
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | 返回数量(默认20) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/feishu_mcp_server/server.py:133-146 (handler)The MCP tool handler for 'list_calendars' - decorated with @mcp.tool(), calls client.list_calendars() and returns JSON.
@mcp.tool() def list_calendars(page_size: int = 20) -> str: """获取飞书日历列表 Args: page_size: 返回数量(默认20) """ if not config.enable_calendar: return json.dumps({"error": "日历功能未启用"}, ensure_ascii=False) try: result = client.list_calendars(page_size) return json.dumps(result, ensure_ascii=False, indent=2, default=str) except Exception as e: return json.dumps({"error": str(e)}, ensure_ascii=False) - The FeishuClient method that makes the actual API request to /calendar/v4/calendars to list calendars.
def list_calendars(self, page_size: int = 20) -> dict[str, Any]: """获取日历列表""" return self._request("GET", "/calendar/v4/calendars", params={"page_size": page_size}) - src/feishu_mcp_server/server.py:133-146 (registration)The tool is registered via the @mcp.tool() decorator on the list_calendars function.
@mcp.tool() def list_calendars(page_size: int = 20) -> str: """获取飞书日历列表 Args: page_size: 返回数量(默认20) """ if not config.enable_calendar: return json.dumps({"error": "日历功能未启用"}, ensure_ascii=False) try: result = client.list_calendars(page_size) return json.dumps(result, ensure_ascii=False, indent=2, default=str) except Exception as e: return json.dumps({"error": str(e)}, ensure_ascii=False) - Schema/input - accepts page_size: int = 20, returns str (JSON). Docstring defines the tool description and parameter.
@mcp.tool() def list_calendars(page_size: int = 20) -> str: """获取飞书日历列表 Args: page_size: 返回数量(默认20) """ if not config.enable_calendar: return json.dumps({"error": "日历功能未启用"}, ensure_ascii=False) try: result = client.list_calendars(page_size) return json.dumps(result, ensure_ascii=False, indent=2, default=str) except Exception as e: return json.dumps({"error": str(e)}, ensure_ascii=False) - The _request helper method used by list_calendars to actually send the HTTP GET request to the Feishu API.
self, method: str, path: str, *, params: Optional[dict] = None, json_data: Optional[dict] = None, ) -> dict[str, Any]: """发送API请求""" token = self._get_tenant_token() headers = { "Authorization": f"Bearer {token}", "Content-Type": "application/json", } resp = self._http.request( method, f"{self.config.base_url}{path}", headers=headers, params=params, json=json_data, ) data = resp.json() if data.get("code") != 0: raise ValueError(f"API调用失败 [{data.get('code')}]: {data.get('msg', '未知错误')}") return data.get("data", {})