get_section_content
Extracts specific section content from a LaTeX file in an Overleaf project, enabling targeted analysis and retrieval of document segments using file path and section title.
Instructions
Get content of a specific section
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the LaTeX file | |
| gitToken | No | Git token (optional, uses env var) | |
| projectId | No | Project ID (optional, uses env var) | |
| projectName | No | Project name (default, project2, etc.) | |
| sectionTitle | Yes | Title of the section |
Implementation Reference
- overleaf-mcp-server.js:95-109 (handler)Core handler function in OverleafGitClient that implements get_section_content logic: reads file, finds sections, extracts content between target section and next.async getSectionContent(filePath, sectionTitle) { const content = await this.readFile(filePath); const sections = await this.getSections(filePath); const targetSection = sections.find(s => s.title === sectionTitle); if (!targetSection) { throw new Error(`Section "${sectionTitle}" not found`); } const nextSection = sections.find(s => s.index > targetSection.index); const startIdx = targetSection.index; const endIdx = nextSection ? nextSection.index : content.length; return content.substring(startIdx, endIdx); }
- overleaf-mcp-server.js:202-219 (schema)Input schema definition for the get_section_content tool, specifying required filePath and sectionTitle parameters.inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the LaTeX file', }, sectionTitle: { type: 'string', description: 'Title of the section', }, projectName: { type: 'string', description: 'Project identifier (optional)', }, }, required: ['filePath', 'sectionTitle'], },
- overleaf-mcp-server.js:299-310 (registration)Registration and dispatch logic in the CallToolRequestSchema handler switch statement.case 'get_section_content': { const client = getProject(args.projectName); const content = await client.getSectionContent(args.filePath, args.sectionTitle); return { content: [ { type: 'text', text: content, }, ], }; }
- overleaf-mcp-server.js:78-93 (helper)Helper method getSections used by getSectionContent to parse LaTeX sections and their positions.async getSections(filePath) { const content = await this.readFile(filePath); const sections = []; const sectionRegex = /\\(?:section|subsection|subsubsection)\{([^}]+)\}/g; let match; while ((match = sectionRegex.exec(content)) !== null) { sections.push({ title: match[1], type: match[0].split('{')[0].replace('\\', ''), index: match.index }); } return sections; }
- overleaf-mcp-server.js:199-220 (registration)Tool registration in the ListToolsRequestSchema response, including name, description, and schema.{ name: 'get_section_content', description: 'Get content of a specific section', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the LaTeX file', }, sectionTitle: { type: 'string', description: 'Title of the section', }, projectName: { type: 'string', description: 'Project identifier (optional)', }, }, required: ['filePath', 'sectionTitle'], }, },