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
| 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: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); } } );
- src/index.ts:771-821 (handler)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); } }
- src/index.ts:730-770 (schema)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." ), },