global_search
Search across all accessible spaces with filtering by object type, sorting options, and pagination controls to find specific content.
Instructions
Executes a search across all spaces the user has access to, with options for filtering by type and sorting.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 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) | |
| 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:681-723 (handler)The async handler function that implements the core logic of the global_search tool: validates limit, builds search request with query, types, sort; POSTs to /search API; filters results with filterObjectsData; returns JSON text content.async ({ query, types, sort_property, sort_direction, offset, limit, 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", `/search`, searchRequest, { offset, limit: validLimit } ); // Pass include_text to filterObjectsData const 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:646-680 (schema)Zod input schema for the global_search tool parameters: required query, optional types filter, sorting (property/direction), pagination (offset/limit), and include_text flag.{ query: z.string().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)"), 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:643-724 (registration)MCP server tool registration call for 'global_search', specifying name, description, Zod input schema, and async handler function.this.server.tool( "global_search", "Executes a search across all spaces the user has access to, with options for filtering by type and sorting.", { query: z.string().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)"), 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 ({ query, types, sort_property, sort_direction, offset, limit, 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", `/search`, searchRequest, { offset, limit: validLimit } ); // Pass include_text to filterObjectsData const 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 invoked by the handler to process and simplify API response data, filtering out unnecessary fields and optionally extracting full markdown-formatted text from object blocks.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, }; }
- src/index.ts:915-938 (helper)Utility helper used by the handler to perform authenticated HTTP requests to the Anytype API using axios.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; } }