get_object_content
Retrieve detailed content and metadata for a specific object in an Anytype space, including properties, relations, and optional formatted text content.
Instructions
Retrieves detailed content and metadata for a specific object in an Anytype space. This tool provides comprehensive information about an object including its properties, relations, and content. Use this tool when you need to examine a specific object's details after discovering its ID through the get_objects tool. The optional include_text parameter allows retrieving the full formatted text content of the object.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| space_id | Yes | Space ID containing the object | |
| object_id | Yes | Object ID to retrieve | |
| include_text | No | Set to true to include full formatted text content from blocks |
Implementation Reference
- src/index.ts:129-163 (handler)The async handler function for the get_object_content tool. It makes a GET request to the Anytype API to fetch the object details, handles nested response format, optionally extracts full text from blocks using extractFullText, and returns the formatted JSON response or error.async ({ space_id, object_id, include_text }) => { try { const response = await this.makeRequest( "get", `/spaces/${space_id}/objects/${object_id}` ); // Handle new response format with nested 'object' property const responseData = response.data.object || response.data; // Если запрошен полный текст и есть блоки с содержимым if ( include_text && responseData && responseData.blocks && Array.isArray(responseData.blocks) ) { const fullText = this.extractFullText(responseData.blocks); if (fullText) { responseData.full_text = fullText; } } return { content: [ { type: "text" as const, text: JSON.stringify(responseData, null, 2), }, ], }; } catch (error) { return this.handleApiError(error); } }
- src/index.ts:118-128 (schema)Zod schema defining input parameters: space_id (required string), object_id (required string), include_text (optional boolean, default false).{ space_id: z.string().describe("Space ID containing the object"), object_id: z.string().describe("Object ID to retrieve"), include_text: z .boolean() .optional() .default(false) .describe( "Set to true to include full formatted text content from blocks" ), },
- src/index.ts:115-164 (registration)Registration of the get_object_content tool using this.server.tool(), including name, description, input schema, and handler function.this.server.tool( "get_object_content", "Retrieves detailed content and metadata for a specific object in an Anytype space. This tool provides comprehensive information about an object including its properties, relations, and content. Use this tool when you need to examine a specific object's details after discovering its ID through the get_objects tool. The optional include_text parameter allows retrieving the full formatted text content of the object.", { space_id: z.string().describe("Space ID containing the object"), object_id: z.string().describe("Object ID to retrieve"), include_text: z .boolean() .optional() .default(false) .describe( "Set to true to include full formatted text content from blocks" ), }, async ({ space_id, object_id, include_text }) => { try { const response = await this.makeRequest( "get", `/spaces/${space_id}/objects/${object_id}` ); // Handle new response format with nested 'object' property const responseData = response.data.object || response.data; // Если запрошен полный текст и есть блоки с содержимым if ( include_text && responseData && responseData.blocks && Array.isArray(responseData.blocks) ) { const fullText = this.extractFullText(responseData.blocks); if (fullText) { responseData.full_text = fullText; } } return { content: [ { type: "text" as const, text: JSON.stringify(responseData, null, 2), }, ], }; } catch (error) { return this.handleApiError(error); } } );
- src/index.ts:941-986 (helper)Helper function extractFullText used by the handler to extract and format full text content from object blocks into Markdown-like text when include_text is true.private extractFullText(blocks: any[]): string { if (!blocks || !Array.isArray(blocks)) { return ""; } // Сопоставление стилей Anytype с текстовыми эквивалентами const styleMap: Record<string, { prefix: string; suffix: string }> = { Header1: { prefix: "# ", suffix: "\n\n" }, Header2: { prefix: "## ", suffix: "\n\n" }, Header3: { prefix: "### ", suffix: "\n\n" }, Header4: { prefix: "#### ", suffix: "\n\n" }, Paragraph: { prefix: "", suffix: "\n\n" }, Marked: { prefix: "* ", suffix: "\n" }, // Маркированный список Checkbox: { prefix: "- [ ] ", suffix: "\n" }, // Чекбокс по умолчанию не отмечен Quote: { prefix: "> ", suffix: "\n\n" }, Code: { prefix: "```\n", suffix: "\n```\n\n" }, // Блок кода }; // Формирование отформатированного текста из блоков const textParts: string[] = []; blocks.forEach((block) => { if (block.text && typeof block.text.text === "string") { const style = block.text.style || "Paragraph"; const isChecked = block.text.checked === true; // Получение форматирования для данного стиля let formatting = styleMap[style] || { prefix: "", suffix: "\n" }; // Особая обработка для чекбоксов if (style === "Checkbox") { formatting = { prefix: isChecked ? "- [x] " : "- [ ] ", suffix: "\n", }; } // Добавление форматированного текста textParts.push( `${formatting.prefix}${block.text.text}${formatting.suffix}` ); } }); return textParts.join(""); }