Skip to main content
Glama
Qwinty
by Qwinty

get_objects

Search and retrieve objects from an Anytype space with filtering and pagination. Find specific items by name or browse collections, optionally including full text content.

Instructions

Searches for and retrieves objects within a specified Anytype space. This tool allows you to list all objects or filter them using a search query. Results are paginated for better performance with large spaces. Use this tool to discover objects within a space, find specific objects by name, or browse through collections of objects. The optional include_text parameter allows retrieving the full formatted text content of objects.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
space_idYesSpace ID to get objects from
offsetNoPagination offset
limitNoNumber of results per page (1-1000)
full_responseNoSet to true to get full unfiltered response
include_textNoSet to true to include full formatted text content from blocks

Implementation Reference

  • The async handler function that executes the get_objects tool logic: validates params, makes API GET request to /spaces/{space_id}/objects, optionally filters response data, and returns JSON-formatted content.
    async ({ space_id, offset, limit, full_response, include_text }) => {
      try {
        // Validate limit
        const validLimit = Math.max(1, Math.min(1000, limit));
    
        // Use the GET /objects endpoint
        const response = await this.makeRequest(
          "get",
          `/spaces/${space_id}/objects`,
          null, // No request body for GET
          { offset, limit: validLimit } // Pass offset and limit as query params
        );
    
        // Decide how to process the response data based on parameters
        let responseData;
        if (full_response) {
          // Return unfiltered data if full_response is true
          responseData = response.data;
        } else {
          // Filter the response data to remove unnecessary information
          responseData = this.filterObjectsData(response.data, include_text);
        }
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(responseData, null, 2),
            },
          ],
        };
      } catch (error) {
        return this.handleApiError(error);
      }
    }
  • Zod input schema defining parameters for the get_objects tool: space_id (required), offset, limit, full_response, include_text.
      space_id: z.string().describe("Space ID to get objects from"),
      offset: z.number().optional().default(0).describe("Pagination offset"),
      limit: z
        .number()
        .optional()
        .default(100)
        .describe("Number of results per page (1-1000)"),
      full_response: z
        .boolean()
        .optional()
        .default(false)
        .describe("Set to true to get full unfiltered response"),
      include_text: z
        .boolean()
        .optional()
        .default(false)
        .describe(
          "Set to true to include full formatted text content from blocks"
        ),
    },
  • src/index.ts:53-112 (registration)
    MCP server tool registration call for 'get_objects', including name, description, input schema, and inline handler function.
    this.server.tool(
      "get_objects",
      "Searches for and retrieves objects within a specified Anytype space. This tool allows you to list all objects or filter them using a search query. Results are paginated for better performance with large spaces. Use this tool to discover objects within a space, find specific objects by name, or browse through collections of objects. The optional include_text parameter allows retrieving the full formatted text content of objects.",
      {
        space_id: z.string().describe("Space ID to get objects from"),
        offset: z.number().optional().default(0).describe("Pagination offset"),
        limit: z
          .number()
          .optional()
          .default(100)
          .describe("Number of results per page (1-1000)"),
        full_response: z
          .boolean()
          .optional()
          .default(false)
          .describe("Set to true to get full unfiltered response"),
        include_text: z
          .boolean()
          .optional()
          .default(false)
          .describe(
            "Set to true to include full formatted text content from blocks"
          ),
      },
      async ({ space_id, offset, limit, full_response, include_text }) => {
        try {
          // Validate limit
          const validLimit = Math.max(1, Math.min(1000, limit));
    
          // Use the GET /objects endpoint
          const response = await this.makeRequest(
            "get",
            `/spaces/${space_id}/objects`,
            null, // No request body for GET
            { offset, limit: validLimit } // Pass offset and limit as query params
          );
    
          // Decide how to process the response data based on parameters
          let responseData;
          if (full_response) {
            // Return unfiltered data if full_response is true
            responseData = response.data;
          } else {
            // Filter the response data to remove unnecessary information
            responseData = this.filterObjectsData(response.data, include_text);
          }
    
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(responseData, null, 2),
              },
            ],
          };
        } catch (error) {
          return this.handleApiError(error);
        }
      }
    );
  • Helper method filterObjectsData used by get_objects to simplify and optionally include text in the API response data.
    private filterObjectsData(data: any, includeText: boolean = false): any {
      if (!data || !data.data || !Array.isArray(data.data)) {
        return data;
      }
    
      const filteredObjects = data.data.map((obj: any) => {
        // Create a simplified object with only essential information
        const simplified: any = {
          id: obj.id,
          type: obj.type,
          name: obj.name,
          icon: obj.icon,
          layout: obj.layout,
          space_id: obj.space_id,
          root_id: obj.root_id,
        };
    
        // Include snippet only if not requested full text
        if (!includeText) {
          simplified.snippet = obj.snippet;
        }
    
        // Process blocks data
        if (obj.blocks && Array.isArray(obj.blocks)) {
          simplified.blocks_count = obj.blocks.length;
    
          // Extract full text content if requested
          if (includeText) {
            const fullText = this.extractFullText(obj.blocks);
            if (fullText) {
              simplified.full_text = fullText;
            }
          }
        }
    
        // Include simplified details (dates and creator)
        if (obj.details && Array.isArray(obj.details)) {
          const dates: any = {};
          let created_by: any = null;
    
          obj.details.forEach((detail: any) => {
            if (detail.id === "created_date" && detail.details?.created_date) {
              dates.created_date = detail.details.created_date;
            }
            if (
              detail.id === "last_modified_date" &&
              detail.details?.last_modified_date
            ) {
              dates.last_modified_date = detail.details.last_modified_date;
            }
            if (
              detail.id === "last_opened_date" &&
              detail.details?.last_opened_date
            ) {
              dates.last_opened_date = detail.details.last_opened_date;
            }
            if (detail.id === "tags" && detail.details?.tags) {
              simplified.tags = detail.details.tags;
            }
            // Добавление информации о создателе
            if (detail.id === "created_by" && detail.details?.details) {
              created_by = {
                name: detail.details.details.name,
                identity: detail.details.details.identity,
                role: detail.details.details.role,
              };
            }
          });
    
          if (Object.keys(dates).length > 0) {
            simplified.dates = dates;
          }
    
          if (created_by) {
            simplified.created_by = created_by;
          }
        }
    
        return simplified;
      });
    
      // Return the filtered data with the same structure
      return {
        data: filteredObjects,
        pagination: data.pagination,
      };
    }

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