get_sfra_document
Retrieve detailed SFRA documentation to explore properties, methods, and usage examples for classes or modules. Use this when developing SFRA controllers, middleware, or implementing SFRA-based features.
Instructions
Get complete SFRA class or module documentation with detailed information about properties, methods, and usage examples. Use this when working with SFRA controllers, middleware, or when you need to understand how SFRA components work together. Perfect for implementing SFRA-based features.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| documentName | Yes | The SFRA document name (e.g., 'server', 'request', 'response', 'querystring', 'render') |
Implementation Reference
- Tool handler configuration: validates 'documentName' argument, executes SFRAClient.getSFRADocument, throws error if not found, provides log message.get_sfra_document: { defaults: (args: ToolArguments) => args, validate: (args: ToolArguments, toolName: string) => { ValidationHelpers.validateArguments(args, CommonValidations.requiredString('documentName'), toolName); }, exec: async (args: ToolArguments, context: ToolExecutionContext) => { const client = context.sfraClient as SFRAClient; const result = await client.getSFRADocument(args.documentName as string); if (!result) { throw new Error(`SFRA document "${args.documentName}" not found`); } return result; }, logMessage: (args: ToolArguments) => `SFRA doc ${args.documentName}`, },
- src/core/handlers/sfra-handler.ts:13-55 (registration)SFRAToolHandler registers the get_sfra_document tool (and other SFRA tools) by providing SFRA_TOOL_CONFIG and SFRAClient instance to the base handler.export class SFRAToolHandler extends BaseToolHandler<SFRAToolName> { private sfraClient: SFRAClient | null = null; constructor(context: HandlerContext, subLoggerName: string) { super(context, subLoggerName); } protected async onInitialize(): Promise<void> { if (!this.sfraClient) { this.sfraClient = new SFRAClient(); this.logger.debug('SFRA client initialized'); } } protected async onDispose(): Promise<void> { this.sfraClient = null; this.logger.debug('SFRA client disposed'); } canHandle(toolName: string): boolean { return SFRA_TOOL_NAMES_SET.has(toolName as SFRAToolName); } protected getToolNameSet(): Set<SFRAToolName> { return SFRA_TOOL_NAMES_SET; } protected getToolConfig(): Record<string, GenericToolSpec<ToolArguments, any>> { return SFRA_TOOL_CONFIG; } protected async createExecutionContext(): Promise<ToolExecutionContext> { if (!this.sfraClient) { throw new Error('SFRA client not initialized'); } return { handlerContext: this.context, logger: this.logger, sfraClient: this.sfraClient, }; } }
- src/core/tool-definitions.ts:174-186 (schema)MCP tool definition including name, description, and input schema requiring 'documentName' string.name: 'get_sfra_document', description: 'Get complete SFRA class, module, or model documentation with detailed information about properties, methods, and usage examples. Use this when working with SFRA controllers, middleware, models, or when you need to understand how SFRA components work together. Perfect for implementing SFRA-based features. Now supports all 26+ SFRA documents including core classes, product models, order/cart models, customer models, pricing models, and more.', inputSchema: { type: 'object', properties: { documentName: { type: 'string', description: 'The SFRA document name (e.g., \'server\', \'request\', \'response\', \'querystring\', \'render\', \'cart\', \'product-full\', \'account\', \'billing\', \'shipping\', etc.). Use get_available_sfra_documents to see all available options.', }, }, required: ['documentName'], }, },
- src/clients/sfra-client.ts:240-272 (helper)Core helper method implementing document retrieval: normalizes name, gets metadata, loads full content from filesystem with path validation and caching.async getSFRADocument(documentName: string): Promise<SFRADocument | null> { // Normalize document name for consistent lookup const normalizedDocumentName = documentName.toLowerCase(); // First try to get from metadata cache const metadata = await this.getSFRADocumentMetadata(documentName); if (!metadata) { return null; } // If the content is already loaded, return it if (metadata.content?.trim()) { return metadata; } // Otherwise, load the full content try { const filePath = await this.validateAndConstructPath(documentName); const content = await fs.readFile(filePath, 'utf-8'); const fullDocument: SFRADocument = { ...metadata, content, }; // Update cache using normalized name this.documentsCache.set(normalizedDocumentName, fullDocument); return fullDocument; } catch (error) { this.logger.error(`Error loading full SFRA document ${normalizedDocumentName}:`, error); return metadata; // Return metadata even if content loading failed } }