list_spaces
Retrieve all accessible workspaces for the currently authenticated user using the AITable MCP Server. Facilitates workspace management and access control.
Instructions
Fetches all workspaces that the currently authenticated user has permission to access.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:46-79 (handler)The handler function for the 'list_spaces' MCP tool. It fetches workspaces from the AITable API endpoint '/v1/spaces', checks for success, formats the response with space definitions, handles errors, and returns MCP CallToolResult.async () => { try { const result: ResponseVO<{ spaces: SpaceVO[] }> = await aitableService.fetchFromAPI("/v1/spaces", { method: "GET", }); if (!result.success) { console.error("Failed to fetch spaces:", result.message || "Unknown error"); return formatToolResponse({ success: false, message: result.message || "Failed to fetch spaces" }, true); } return formatToolResponse({ success: true, data: { spaces: result.data.spaces, definitions: { id: "The workspace ID", name: "The name of the workspace", isAdmin: "Indicates if the user has admin permissions in the workspace" } } }); } catch (error) { console.error("Error in list_spaces:", error); return formatToolResponse({ success: false, message: error instanceof Error ? error.message : "Unknown error occurred" }, true); } }
- src/index.ts:44-80 (registration)Registers the 'list_spaces' tool with the MCP server using server.tool(), providing a description and the inline handler function.server.tool("list_spaces", "Fetches all workspaces that the currently authenticated user has permission to access.", async () => { try { const result: ResponseVO<{ spaces: SpaceVO[] }> = await aitableService.fetchFromAPI("/v1/spaces", { method: "GET", }); if (!result.success) { console.error("Failed to fetch spaces:", result.message || "Unknown error"); return formatToolResponse({ success: false, message: result.message || "Failed to fetch spaces" }, true); } return formatToolResponse({ success: true, data: { spaces: result.data.spaces, definitions: { id: "The workspace ID", name: "The name of the workspace", isAdmin: "Indicates if the user has admin permissions in the workspace" } } }); } catch (error) { console.error("Error in list_spaces:", error); return formatToolResponse({ success: false, message: error instanceof Error ? error.message : "Unknown error occurred" }, true); } } );
- src/index.ts:33-42 (helper)Helper utility function to format the output of list_spaces (and other tools) into the required MCP CallToolResult structure with JSON content.const formatToolResponse = (data: unknown, isError = false): CallToolResult => { return { content: [{ type: 'text', mimeType: 'application/json', text: JSON.stringify(data), }], isError, }; };