Skip to main content
Glama
Qwinty
by Qwinty

search_space

Search for objects within a specific Anytype space, with options to filter by type, sort results, and control pagination.

Instructions

Executes a search within a specific space, with options for filtering by type and sorting.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
space_idYesSpace ID to search within
queryNoSearch term
typesNoOptional list of object type keys or IDs to filter by
sort_propertyNoProperty to sort bylast_modified_date
sort_directionNoSort directiondesc
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. USE WITH CAUTION: This can return a large amount of data.

Implementation Reference

  • src/index.ts:727-822 (registration)
    Complete registration of the 'search_space' MCP tool, including description, Zod input schema for parameters like space_id, query, types, sorting, pagination, full_response, include_text, and inline async handler that validates limit, builds search request, calls Anytype API POST /spaces/{space_id}/search, optionally filters results with filterObjectsData, handles errors, and returns JSON-formatted response as text content.
    this.server.tool(
      "search_space",
      "Executes a search within a specific space, with options for filtering by type and sorting.",
      {
        space_id: z.string().describe("Space ID to search within"),
        query: z.string().optional().describe("Search term"),
        types: z
          .array(z.string())
          .optional()
          .describe("Optional list of object type keys or IDs to filter by"),
        sort_property: z
          .enum([
            "created_date",
            "last_modified_date",
            "last_opened_date",
            "name",
          ])
          .optional()
          .default("last_modified_date")
          .describe("Property to sort by"),
        sort_direction: z
          .enum(["asc", "desc"])
          .optional()
          .default("desc")
          .describe("Sort direction"),
        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. USE WITH CAUTION: This can return a large amount of data."
          ),
      },
      async ({
        space_id,
        query,
        types,
        sort_property,
        sort_direction,
        offset,
        limit,
        full_response,
        include_text,
      }) => {
        try {
          const validLimit = Math.max(1, Math.min(1000, limit));
          const searchRequest: any = { query };
          if (types) {
            searchRequest.types = types;
          }
          searchRequest.sort = {
            property: sort_property,
            direction: sort_direction,
          };
    
          const response = await this.makeRequest(
            "post",
            `/spaces/${space_id}/search`,
            searchRequest,
            { offset, limit: validLimit }
          );
    
          // 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
            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);
        }
      }
    );
  • The inline handler function executing the 'search_space' tool logic: constructs and sends POST request to Anytype API `/spaces/${space_id}/search` with query, types, sort params; optionally applies filtering; returns structured content response or error.
    async ({
      space_id,
      query,
      types,
      sort_property,
      sort_direction,
      offset,
      limit,
      full_response,
      include_text,
    }) => {
      try {
        const validLimit = Math.max(1, Math.min(1000, limit));
        const searchRequest: any = { query };
        if (types) {
          searchRequest.types = types;
        }
        searchRequest.sort = {
          property: sort_property,
          direction: sort_direction,
        };
    
        const response = await this.makeRequest(
          "post",
          `/spaces/${space_id}/search`,
          searchRequest,
          { offset, limit: validLimit }
        );
    
        // 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
          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 schema for 'search_space' tool inputs: required space_id; optional query, types array, sort_property (enum), sort_direction, offset, limit (1-1000), full_response boolean, include_text boolean.
    {
      space_id: z.string().describe("Space ID to search within"),
      query: z.string().optional().describe("Search term"),
      types: z
        .array(z.string())
        .optional()
        .describe("Optional list of object type keys or IDs to filter by"),
      sort_property: z
        .enum([
          "created_date",
          "last_modified_date",
          "last_opened_date",
          "name",
        ])
        .optional()
        .default("last_modified_date")
        .describe("Property to sort by"),
      sort_direction: z
        .enum(["asc", "desc"])
        .optional()
        .default("desc")
        .describe("Sort direction"),
      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. USE WITH CAUTION: This can return a large amount of data."
        ),
    },

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