Skip to main content
Glama
Qwinty
by Qwinty

get_templates

Retrieve available templates for a specific object type in Anytype to create new objects with pre-configured structures and content.

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
NameRequiredDescriptionDefault
space_idYesSpace ID containing the type
type_idYesType ID to get templates for
offsetNoPagination offset
limitNoNumber of results per page (1-1000)

Implementation Reference

  • src/index.ts:441-477 (registration)
    Registration of the get_templates MCP tool with description, Zod input schema, and inline asynchronous handler function that proxies requests to the Anytype API endpoint `/spaces/{space_id}/types/{type_id}/templates`.
    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);
        }
      }
    );
  • The core handler function for get_templates: validates pagination limit, performs authenticated GET request to Anytype API for templates of a type in a space, returns formatted JSON response or handles errors via shared helper.
    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);
      }
    }
  • Zod schema defining input parameters for get_templates tool: required space_id and type_id strings, optional offset (default 0) and limit (default 100, clamped 1-1000) numbers 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)"),
    },
  • Shared helper method used by get_templates (and other tools) to make authenticated HTTP requests to Anytype API using axios, with Bearer token from env var.
    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;
      }
    }
  • Shared error handling helper invoked by get_templates handler to format and return standardized error responses for API failures, network issues, and HTTP status codes.
    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,
      };
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It clearly states that the tool retrieves data (read-only operation), returns a list with IDs, names, and metadata, and that results are paginated. It doesn't mention rate limits, authentication needs, or error conditions, but for a read-only tool with pagination described, this is reasonably transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is three sentences, each earning its place: first states purpose, second explains what templates are, third describes output and pagination, fourth provides usage guidance. It's front-loaded with the core purpose and wastes no words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a read-only tool with no output schema, the description does well by explaining what the return value contains (list with IDs, names, metadata) and pagination behavior. It could mention error cases or authentication requirements, but given the tool's relative simplicity and clear purpose, it's mostly complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema (e.g., it doesn't explain what 'space_id' or 'type_id' represent in context). Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('retrieves') and resource ('all available templates for a specific object type in an Anytype space'), distinguishing it from siblings like get_template_details (which presumably gets details for a single template) and get_types (which gets types rather than templates). It specifies the scope (templates for a specific type in a specific space) and what templates are used for.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool: 'Use this tool when you need to find appropriate templates for creating new objects of a specific type.' It distinguishes from alternatives by focusing on template retrieval for a specific type, unlike global_search or search_space which are broader, and get_template_details which likely provides detailed info for a single template.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Qwinty/anytype-mcp'

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