Skip to main content
Glama

ContextSave

Read-only

Save project context by capturing descriptions and file contents from specified paths into a single text file for reference.

Instructions

Saves provided description and file contents of all the relevant file paths or globs in a single text file.

  • Provide random 3 word unique id or whatever user provided.

  • Leave project path as empty string if no project path

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
project_root_pathYes
descriptionYes
relevant_file_globsYes

Implementation Reference

  • Handler logic for ContextSave tool within the get_tool_output dispatcher function. Globs and reads relevant files, saves memory using save_memory helper, and returns the path to the saved context file.
    elif isinstance(arg, ContextSave):
        context.console.print("Calling task memory tool")
        relevant_files = []
        warnings = ""
        # Expand user in project root path
        arg.project_root_path = os.path.expanduser(arg.project_root_path)
        for fglob in arg.relevant_file_globs:
            # Expand user in glob pattern before checking if it's absolute
            fglob = expand_user(fglob)
            # If not absolute after expansion, join with project root path
            if not os.path.isabs(fglob) and arg.project_root_path:
                fglob = os.path.join(arg.project_root_path, fglob)
            globs = glob.glob(fglob, recursive=True)
            relevant_files.extend(globs[:1000])
            if not globs:
                warnings += f"Warning: No files found for the glob: {fglob}\n"
        relevant_files_data, _, _ = read_files(
            relevant_files[:10_000], None, None, context
        )
        save_path = save_memory(
            arg, relevant_files_data, context.bash_state.serialize()
        )
        if not relevant_files and arg.relevant_file_globs:
            output_ = f'Error: No files found for the given globs. Context file successfully saved at "{save_path}", but please fix the error.'
        elif warnings:
            output_ = warnings + "\nContext file successfully saved at " + save_path
        else:
            output_ = save_path
        # Try to open the saved file
        try_open_file(save_path)
        output = output_, 0.0
    else:
  • Pydantic BaseModel defining the input schema for ContextSave tool: id, project_root_path, description, relevant_file_globs.
    class ContextSave(BaseModel):
        id: str
        project_root_path: str
        description: str
        relevant_file_globs: list[str]
  • MCP Tool registration for ContextSave, including schema reference, name, description, and annotations.
        Tool(
            inputSchema=remove_titles_from_schema(ContextSave.model_json_schema()),
            name="ContextSave",
            description="""
    Saves provided description and file contents of all the relevant file paths or globs in a single text file.
    - Provide random 3 word unique id or whatever user provided.
    - Leave project path as empty string if no project path""",
            annotations=ToolAnnotations(readOnlyHint=True, openWorldHint=False),
        ),
  • Helper function save_memory that formats and persists the task context to a file using the ContextSave model data and relevant files content.
    def save_memory(
        task_memory: ContextSave,
        relevant_files: str,
        bash_state_dict: Optional[dict[str, Any]] = None,
    ) -> str:
        app_dir = get_app_dir_xdg()
        memory_dir = os.path.join(app_dir, "memory")
        os.makedirs(memory_dir, exist_ok=True)
    
        task_id = task_memory.id
        if not task_id:
            raise Exception("Task id can not be empty")
        memory_data = format_memory(task_memory, relevant_files)
    
        memory_file_full = os.path.join(memory_dir, f"{task_id}.txt")
    
        with open(memory_file_full, "w") as f:
            f.write(memory_data)
    
        # Save bash state if provided
        if bash_state_dict is not None:
            state_file = os.path.join(memory_dir, f"{task_id}_bash_state.json")
            with open(state_file, "w") as f:
                json.dump(bash_state_dict, f, indent=2)
    
        return memory_file_full
  • Helper function format_memory that structures the task description, relevant globs, and file contents into a memory string.
    def format_memory(task_memory: ContextSave, relevant_files: str) -> str:
        memory_data = ""
        if task_memory.project_root_path:
            memory_data += (
                f"# PROJECT ROOT = {shlex.quote(task_memory.project_root_path)}\n"
            )
        memory_data += task_memory.description
    
        memory_data += (
            "\n\n"
            + "# Relevant file paths\n"
            + ", ".join(map(shlex.quote, task_memory.relevant_file_globs))
        )
    
        memory_data += "\n\n# Relevant Files:\n" + relevant_files
    
        return memory_data
Behavior3/5

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

Annotations indicate readOnlyHint=true and openWorldHint=false, which the description doesn't contradict. The description adds some behavioral context beyond annotations: it specifies that the output is a 'single text file' and mentions handling of project paths. However, it lacks details on file format, error handling, or what happens if globs match no files. With annotations covering safety, this earns a baseline score.

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

Conciseness3/5

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

The description is relatively concise with two sentences and bullet points, but it's not optimally structured. The first sentence states the purpose clearly, but the bullet points mix implementation details (e.g., 'Leave project path as empty string') with parameter guidance, making it somewhat cluttered. It could be more front-loaded and streamlined.

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 4 parameters with 0% schema coverage, no output schema, and annotations only covering read-only and closed-world aspects, the description is incomplete. It lacks details on return values, error conditions, file format specifics, and how globs are processed. For a tool that saves file contents, more context is needed to ensure proper usage.

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. It partially explains parameters: 'id' is implied by the bullet point about unique IDs, 'project_root_path' is mentioned in the second bullet point, 'description' is referenced in the first sentence, and 'relevant_file_globs' is explained as 'file paths or globs'. However, it doesn't fully clarify semantics (e.g., what 'relevant' means, glob syntax, or path handling), leaving significant gaps.

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: 'Saves provided description and file contents of all the relevant file paths or globs in a single text file.' This specifies the verb (saves), resources (description and file contents), and output format (single text file). However, it doesn't explicitly differentiate from sibling tools like FileWriteOrEdit or ReadFiles, which prevents a score of 5.

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 minimal usage guidance. The bullet points offer some implementation details (e.g., 'Provide random 3 word unique id or whatever user provided'), but there's no explicit guidance on when to use this tool versus alternatives like FileWriteOrEdit or ReadFiles. No context about prerequisites or exclusions is provided.

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/rusiaaman/wcgw'

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