Skip to main content
Glama

get_section

Retrieve specific sections from memory documents to access structured project knowledge and build context for informed responses.

Instructions

Retrieve a specific section from a memory document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idYesThe ID of the memory document to read from
sectionYesThe section name to retrieve

Implementation Reference

  • The main handler function getSectionTool that retrieves and formats a specific section from a memory document using the StorageManager.
    export async function getSectionTool(
      storageManager: StorageManager,
      args: any
    ): Promise<any> {
      const params = args as GetSectionParams;
      
      if (!params.memory_id || !params.section) {
        throw new Error('Both memory_id and section are required');
      }
    
      // Read the memory document
      const memory = await storageManager.readMemory(params.memory_id);
      if (!memory) {
        throw new Error(`Memory document '${params.memory_id}' not found`);
      }
    
      // Find the section
      const section = storageManager.findSection(memory.content, params.section);
      if (!section) {
        // List available sections to help the user
        const allSections = storageManager.parseSections(memory.content);
        const sectionNames = allSections.map(s => s.name).join(', ');
        
        throw new Error(
          `Section '${params.section}' not found in memory document '${params.memory_id}'. ` +
          `Available sections: ${sectionNames}`
        );
      }
    
      const sectionContent = section.content || '(This section is empty)';
    
      return {
        content: [{
          type: 'text',
          text: `## ${section.name}
    
    ${sectionContent}
    
    ---
    *From memory document: ${params.memory_id}*
    *Last updated: ${memory.metadata.updated}*`
        }]
      };
    }
  • src/index.ts:82-99 (registration)
    Tool registration in the MCP server, including name, description, and input schema.
    {
      name: "get_section",
      description: "Retrieve a specific section from a memory document",
      inputSchema: {
        type: "object",
        properties: {
          memory_id: {
            type: "string",
            description: "The ID of the memory document to read from",
          },
          section: {
            type: "string",
            description: "The section name to retrieve",
          },
        },
        required: ["memory_id", "section"],
      },
    },
  • src/index.ts:265-266 (registration)
    Dispatch handler in the switch statement that calls the getSectionTool.
    case "get_section":
      return await getSectionTool(storageManager, args);
  • TypeScript interface defining the input parameters for the get_section tool.
    export interface GetSectionParams {
      memory_id: string;
      section: string;
    }
  • src/index.ts:12-12 (registration)
    Import of the getSectionTool function.
    import { getSectionTool } from "./tools/getSection.js";

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/nmeierpolys/mcp-structured-memory'

If you have feedback or need assistance with the MCP directory API, please join our Discord server