search_space
Search within a specific Anytype space using filters by object type, sort options, and pagination controls to find relevant content and data.
Instructions
Executes a search within a specific space, with options for filtering by type and sorting.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| space_id | Yes | Space ID to search within | |
| query | No | Search term | |
| types | No | Optional list of object type keys or IDs to filter by | |
| sort_property | No | Property to sort by | last_modified_date |
| sort_direction | No | Sort direction | desc |
| offset | No | Pagination offset | |
| limit | No | Number of results per page (1-1000) | |
| full_response | No | Set to true to get full unfiltered response | |
| include_text | No | Set 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:771-821 (handler)The handler function that implements the core logic of the 'search_space' tool. It constructs a search request with query, types filter, and sorting options, performs a POST request to the Anytype API endpoint `/spaces/${space_id}/search`, optionally filters the response data, and returns the results as formatted text.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); } }
- src/index.ts:730-770 (schema)Zod input schema defining the parameters for the 'search_space' tool, including required space_id, optional query, type filters, sorting, pagination options, and flags for full response and text inclusion.{ 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." ), },
- src/index.ts:727-822 (registration)The registration of the 'search_space' tool on the MCP server using this.server.tool(), specifying the tool name, description, input schema, and handler function.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); } } );
- src/index.ts:826-912 (helper)Supporting helper method called by the search_space handler to process and filter API response data, simplifying objects and optionally extracting full text content.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, }; }