get_rfc_section
Extract specific sections from IETF RFC documents by providing the RFC number and section title or number for targeted information retrieval.
Instructions
Get a specific section from an RFC
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| number | Yes | RFC number (e.g. "2616") | |
| section | Yes | Section title or number to retrieve |
Implementation Reference
- src/index.ts:281-330 (handler)The handler logic for the 'get_rfc_section' tool within the CallToolRequestSchema handler. It fetches the RFC using rfcService, searches for a matching section by title, and returns the section as JSON or an error message.case 'get_rfc_section': { if (typeof typedArgs.number !== 'string' || typeof typedArgs.section !== 'string') { throw new McpError( ErrorCode.InvalidParams, 'RFC number and section must be strings' ); } try { const rfc = await rfcService.fetchRfc(typedArgs.number); // Find the matching section const sectionQuery = typedArgs.section.toLowerCase(); const section = rfc.sections.find(s => s.title.toLowerCase().includes(sectionQuery) || s.title.toLowerCase() === sectionQuery ); if (!section) { return { content: [ { type: 'text', text: `Section "${typedArgs.section}" not found in RFC ${typedArgs.number}`, }, ], isError: true, }; } return { content: [ { type: 'text', text: JSON.stringify(section, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching section from RFC ${typedArgs.number}: ${error}`, }, ], isError: true, }; } }
- src/index.ts:167-185 (schema)The tool schema definition including name, description, and inputSchema for 'get_rfc_section', provided in the ListToolsRequestSchema response.{ name: 'get_rfc_section', description: 'Get a specific section from an RFC', inputSchema: { type: 'object', properties: { number: { type: 'string', description: 'RFC number (e.g. "2616")', }, section: { type: 'string', description: 'Section title or number to retrieve', }, }, required: ['number', 'section'], additionalProperties: false, }, },
- src/services/rfcService.ts:37-65 (helper)The fetchRfc helper function that retrieves and parses an RFC document (preferring HTML, falling back to TXT), populating structured sections used by the tool handler to extract specific sections.async fetchRfc(rfcNumber: string): Promise<RfcContent> { // Check cache first if (this.cache.has(rfcNumber)) { return this.cache.get(rfcNumber)!; } // Fetch the RFC in both HTML and TXT formats const txtUrl = `${this.baseUrl}/rfc${rfcNumber}.txt`; const htmlUrl = `${this.baseUrl}/rfc${rfcNumber}/`; try { // Try HTML first for better structure const htmlResponse = await axios.get(htmlUrl); const rfc = this.parseHtmlRfc(htmlResponse.data, rfcNumber, htmlUrl); this.cache.set(rfcNumber, rfc); return rfc; } catch (error) { try { // Fallback to TXT format console.error(`Failed to fetch HTML format for RFC ${rfcNumber}, trying TXT format`); const txtResponse = await axios.get(txtUrl); const rfc = this.parseTxtRfc(txtResponse.data, rfcNumber, txtUrl); this.cache.set(rfcNumber, rfc); return rfc; } catch (txtError) { throw new Error(`Failed to fetch RFC ${rfcNumber}: ${txtError}`); } } }
- src/services/rfcService.ts:14-25 (schema)Type definition for RfcContent, which structures the parsed RFC data including sections array used in the tool handler.interface RfcContent { metadata: RfcMetadata; sections: { title: string; content: string; subsections?: { title: string; content: string; }[]; }[]; fullText: string; }