create_space
Create a new workspace in Anytype to organize objects and collaborate with others. Set up a fresh organizational container for your content by specifying a space name.
Instructions
Creates a new Anytype space with the specified name. This tool allows you to set up a fresh workspace for organizing objects and collaborating with others. Use this tool when you need to establish a new organizational container for your Anytype content.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name for the new space |
Implementation Reference
- src/index.ts:167-188 (registration)Registration of the 'create_space' MCP tool, including name, description, Zod input schema, and inline async handler function that performs the API call to create the space.this.server.tool( "create_space", "Creates a new Anytype space with the specified name. This tool allows you to set up a fresh workspace for organizing objects and collaborating with others. Use this tool when you need to establish a new organizational container for your Anytype content.", { name: z.string().describe("Name for the new space"), }, async ({ name }) => { try { const response = await this.makeRequest("post", "/spaces", { name }); return { content: [ { type: "text" as const, text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return this.handleApiError(error); } } );
- src/index.ts:173-187 (handler)The core handler function for 'create_space' tool: extracts 'name' parameter, makes POST request to Anytype API /spaces endpoint, returns JSON response or error.async ({ name }) => { try { const response = await this.makeRequest("post", "/spaces", { name }); return { content: [ { type: "text" as const, text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return this.handleApiError(error); } }
- src/index.ts:170-172 (schema)Zod schema for input parameters: requires a 'name' string for the new space.{ name: z.string().describe("Name for the new space"), },
- src/index.ts:915-938 (helper)Shared helper method 'makeRequest' used by the create_space handler to perform authenticated HTTP requests to the Anytype API.private async makeRequest( method: "get" | "post" | "delete", endpoint: string, data?: any, params?: any ) { try { const config = { method, url: `${this.apiBaseUrl}${endpoint}`, headers: { Authorization: `Bearer ${this.appKey}`, "Content-Type": "application/json", }, data, params, }; return await axios(config); } catch (error) { console.error(`API request error: ${error}`); throw error; } }
- src/index.ts:989-1050 (helper)Shared helper method 'handleApiError' used by the create_space handler to standardize error responses from API calls.private handleApiError(error: any) { let errorMessage = "Unknown API error"; // Handle network errors first if (error.code === "ECONNREFUSED") { errorMessage = "Anytype is not running. Launch it and try again."; return this.printError(error, errorMessage); } // Handle API response errors const status = error.response?.status; const apiError = error.response?.data?.error; switch (status) { case 400: errorMessage = apiError?.message || "Bad request"; if (apiError?.code === "validation_error") { errorMessage += ". Invalid parameters: " + (apiError.details ?.map((d: { field: string }) => d.field) .join(", ") || "unknown fields"); } break; case 401: errorMessage = "Unauthorized - Check your App Key"; break; case 403: errorMessage = "Forbidden - You don't have permission for this operation"; break; case 404: errorMessage = "Not found - The requested resource doesn't exist"; break; case 429: errorMessage = "Rate limit exceeded - Try again later"; break; case 500: errorMessage = "Internal server error - Contact Anytype support"; break; default: if (status >= 500 && status < 600) { errorMessage = `Server error (${status}) - Try again later`; } else if (apiError?.message) { errorMessage = apiError.message; } break; } return this.printError(apiError, errorMessage); } private printError(error: any, errorMessage: any) { return { content: [ { type: "text" as const, text: `Error: ${errorMessage}\n\n${error}`, }, ], isError: true, }; }