Skip to main content
Glama
aindreyway

MCP Server Neurolorap

by aindreyway

code_collector

Collect code from multiple files and directories into a single markdown document for documentation and reference purposes.

Instructions

Collect code from files into a markdown document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
input_pathNo.
titleNoCode Collection
subproject_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The asynchronous handler function that executes the code_collector tool. It instantiates CodeCollector and calls its collect_code method to perform the actual code collection.
    async def code_collector(
        input_path: str | list[str] = ".",
        title: str = "Code Collection",
        subproject_id: str | None = None,
    ) -> str:
        """Collect code from files into a markdown document."""
        logger.debug("Tool call: code_collector")
        logger.debug(
            "Arguments: input=%s, title=%s, subproject_id=%s",
            input_path,
            title,
            subproject_id,
        )
    
        try:
            root_path = get_project_root()
            collector = CodeCollector(
                project_root=root_path, subproject_id=subproject_id
            )
    
            logger.info("Starting code collection")
            logger.debug("Input: %s", input_path)
            logger.debug("Title: %s", title)
            logger.debug("Subproject ID: %s", subproject_id)
    
            output_file = collector.collect_code(input_path, title)
            if not output_file:
                msg = "No files found to process or error occurred"
                return msg
    
            return f"Code collection complete!\nOutput file: {output_file}"
    
        except Exception as e:
            error_msg = f"Unexpected error collecting code: {e}"
            logger.error(error_msg, exc_info=True)
            return "No files found to process or error occurred"
  • Registration of the code_collector tool with the FastMCP server instance, including name and description which define the tool schema.
        name="code_collector",
        description="Collect code from files into a markdown document",
    )(code_collector)
  • The core helper method in CodeCollector class that implements the logic to collect files, generate markdown with code blocks, table of contents, and also creates an analysis prompt file. This is the main implementation delegated to by the handler.
    def collect_code(
        self,
        input_paths: Union[str, List[str]],
        title: str = "Code Collection",
    ) -> Optional[Path]:
        """Process all files and generate markdown documentation.
    
        Args:
            input_paths: Path(s) to process.
            title: Title for the collection.
    
        Returns:
            Optional[Path]: Path to generated markdown file or None if failed.
            The path is returned as a Path object if successful,
            None if failed.
        """
        try:
            all_files = self.collect_files(input_paths)
            if not all_files:
                logger.warning("No files found to process")
                return None
    
            # Create output files with timestamp and path info
            from datetime import datetime
    
            timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    
            # Convert input paths to string
            if isinstance(input_paths, str):
                path_str = input_paths
            else:
                path_str = "_".join(input_paths)
            # Clean up path string
            path_str = path_str.replace("/", "_").replace(".", "_")
    
            code_output_path = self.storage.get_output_path(
                f"FULL_CODE_{timestamp}_{path_str}_{title}.md"
            )
    
            # Create parent directory if it doesn't exist
            code_output_path.parent.mkdir(parents=True, exist_ok=True)
    
            # Write code collection file
            with open(code_output_path, "w", encoding="utf-8") as output_file:
                # Write header
                output_file.write(f"# {title}\n\n")
                output_file.write(
                    "This file contains code from the specified paths, "
                    "organized by file path.\n\n"
                )
    
                # Write table of contents
                output_file.write("## Table of Contents\n\n")
                for file_path in all_files:
                    try:
                        relative_path = file_path.relative_to(
                            self.project_root
                        )
                    except ValueError:
                        relative_path = file_path
                    anchor = self.make_anchor(relative_path)
                    output_file.write(f"- [{relative_path}](#{anchor})\n")
    
                # Write file contents
                output_file.write("\n## Files\n\n")
                for file_path in all_files:
                    try:
                        relative_path = file_path.relative_to(
                            self.project_root
                        )
                    except ValueError:
                        relative_path = file_path
    
                    content = self.read_file_content(file_path)
                    anchor = self.make_anchor(relative_path)
                    lang = LanguageMap.get_language(file_path)
    
                    output_file.write(f"### {relative_path} {{{anchor}}}\n")
                    output_file.write(f"```{lang}\n{content}\n```\n\n")
                    logger.debug(f"Processed: {relative_path}")
    
                # Force flush and sync
                output_file.flush()
                os.fsync(output_file.fileno())
    
            # Force sync to ensure file is visible
            os.sync()
    
            # Wait a bit for filesystem to update
            import time
    
            time.sleep(0.1)
    
            # Create analysis prompt file with timestamp
            analyze_output_path = self.storage.get_output_path(
                f"PROMPT_ANALYZE_{timestamp}_{path_str}_{title}.md"
            )
            prompt_path = (
                Path(__file__).parent / "prompts" / "analyze.prompt.md"
            )
    
            # Read code content first
            code_content = self.read_file_content(code_output_path)
            prompt_content = self.read_file_content(prompt_path)
    
            # Write analysis file
            with open(
                analyze_output_path, "w", encoding="utf-8"
            ) as analyze_file:
                analyze_file.write(prompt_content)
                analyze_file.write("\n")
                analyze_file.write(code_content)
                # Force flush and sync
                analyze_file.flush()
                os.fsync(analyze_file.fileno())
    
            # Force sync to ensure file is visible
            os.sync()
    
            # Wait a bit for filesystem to update
            time.sleep(0.1)
    
            # Touch files and all parent directories
            # to trigger VSCode file watcher
            try:
                # Touch output files
                os.utime(code_output_path, None)
                os.utime(analyze_output_path, None)
    
                # Touch all parent directories up to project root
                current = code_output_path.parent
                while (
                    current != self.project_root and current != current.parent
                ):
                    os.utime(current, None)
                    current = current.parent
    
                os.utime(self.project_root, None)
            except Exception as e:
                logger.debug(
                    f"Failed to touch project root: {str(e)}"
                )  # nosec B110
                # Intentionally catching all exceptions for
                # filesystem operations
    
            # Verify files exist and are accessible
            if not code_output_path.exists():
                raise RuntimeError(
                    f"Failed to create code file: {code_output_path}"
                )
            if not analyze_output_path.exists():
                raise RuntimeError(
                    f"Failed to create analysis file: {analyze_output_path}"
                )
    
            logger.debug(f"Analysis prompt created: {analyze_output_path}")
            logger.info("Code collection complete!")
            logger.debug(f"Output file: {code_output_path}")
            return Path(code_output_path)
    
        except FileNotFoundError as e:
            logger.error(f"File not found error: {str(e)}")
            return None
        except PermissionError as e:
            logger.error(f"Permission denied error: {str(e)}")
            return None
        except OSError as e:
            logger.error(f"OS error during code collection: {str(e)}")
            return None
        except RuntimeError as e:
            logger.error(f"Runtime error during code collection: {str(e)}")
            return None
        except Exception as e:
            logger.error(f"Unexpected error during code collection: {str(e)}")
            logger.debug("Stack trace:", exc_info=True)
            return None
  • The CodeCollector class initialization, setting up project root, storage, and ignore patterns.
    class CodeCollector:
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but only states the basic action. It does not cover critical aspects like whether this is a read-only operation, if it modifies files, error handling, performance implications, or output details. The description is insufficient for a tool with 3 parameters and an output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It is front-loaded with the core purpose, making it easy to parse quickly. Every word earns its place, though this conciseness comes at the cost of completeness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 3 parameters with 0% schema coverage, an output schema, and no annotations, the description is inadequate. It does not explain parameter roles, behavioral traits, or how the output schema relates to the markdown document. The presence of an output schema reduces the need to describe return values, but other gaps remain significant.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but adds no parameter information. It does not explain what 'input_path', 'title', or 'subproject_id' mean, their formats, or how they affect the collection process. The description fails to provide any semantic context beyond the tool's name.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('collect') and resource ('code from files'), specifying the output format ('into a markdown document'). It distinguishes from the sibling 'project_structure_reporter' by focusing on code content rather than structure, though the distinction could be more explicit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, such as the sibling 'project_structure_reporter'. It lacks context about appropriate scenarios, prerequisites, or exclusions, leaving the agent to infer usage based solely on the purpose statement.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/aindreyway/mcp-server-neurolora-p'

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