get_templates
Retrieve available templates for specific object types to create new objects with pre-configured structures and content in your Anytype space.
Instructions
Retrieves all available templates for a specific object type in an Anytype space. Templates provide pre-configured structures and content for creating new objects. This tool returns a list of templates with their IDs, names, and metadata. Results are paginated for types with many templates. Use this tool when you need to find appropriate templates for creating new objects of a specific type.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| space_id | Yes | Space ID containing the type | |
| type_id | Yes | Type ID to get templates for | |
| offset | No | Pagination offset | |
| limit | No | Number of results per page (1-1000) |
Implementation Reference
- src/index.ts:454-476 (handler)The handler function that implements the core logic of the 'get_templates' tool. It validates pagination parameters, calls the Anytype API to fetch templates for a specific type in a space, formats the response as JSON text, and handles errors using the shared handleApiError method.async ({ space_id, type_id, offset, limit }) => { try { // Validate limit const validLimit = Math.max(1, Math.min(1000, limit)); const response = await this.makeRequest( "get", `/spaces/${space_id}/types/${type_id}/templates`, null, { offset, limit: validLimit } ); return { content: [ { type: "text" as const, text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return this.handleApiError(error); } }
- src/index.ts:444-452 (schema)Zod input schema defining the parameters for the get_templates tool: required space_id and type_id, optional offset and limit for pagination.{ space_id: z.string().describe("Space ID containing the type"), type_id: z.string().describe("Type ID to get templates for"), offset: z.number().optional().default(0).describe("Pagination offset"), limit: z .number() .optional() .default(100) .describe("Number of results per page (1-1000)"),
- src/index.ts:441-477 (registration)Full registration of the 'get_templates' tool using McpServer.tool(), including name, description, input schema, and inline handler function.this.server.tool( "get_templates", "Retrieves all available templates for a specific object type in an Anytype space. Templates provide pre-configured structures and content for creating new objects. This tool returns a list of templates with their IDs, names, and metadata. Results are paginated for types with many templates. Use this tool when you need to find appropriate templates for creating new objects of a specific type.", { space_id: z.string().describe("Space ID containing the type"), type_id: z.string().describe("Type ID to get templates for"), offset: z.number().optional().default(0).describe("Pagination offset"), limit: z .number() .optional() .default(100) .describe("Number of results per page (1-1000)"), }, async ({ space_id, type_id, offset, limit }) => { try { // Validate limit const validLimit = Math.max(1, Math.min(1000, limit)); const response = await this.makeRequest( "get", `/spaces/${space_id}/types/${type_id}/templates`, null, { offset, limit: validLimit } ); return { content: [ { type: "text" as const, text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return this.handleApiError(error); } } );