Skip to main content
Glama

get_instruction

Retrieve raw content from VS Code instruction files to access predefined guidance or commands for development workflows.

Instructions

Get the raw content of a VS Code .instructions.md file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instruction_nameYesName of the instruction (without extension)

Implementation Reference

  • The handler function for the 'get_instruction' MCP tool. It ensures the correct file extension, calls instruction_manager.get_raw_instruction to fetch the raw content, and returns it or an error message.
    def get_instruction(
        instruction_name: Annotated[str, "Name of the instruction (without extension)"],
    ) -> str:
        """Get the raw content of a VS Code .instructions.md file."""
        try:
            # Ensure correct extension
            if not instruction_name.endswith(INSTRUCTION_FILE_EXTENSION):
                instruction_name += INSTRUCTION_FILE_EXTENSION
            raw_content = instruction_manager.get_raw_instruction(instruction_name)
            return raw_content
        except Exception as e:
            return f"Error getting VS Code instruction '{instruction_name}': {str(e)}"
  • Registration of the 'get_instruction' tool using @app.tool decorator, including name, description, tags, schema annotations for parameters and returns, and metadata.
    @app.tool(
        name="get_instruction",
        description="Get the raw content of a VS Code .instructions.md file.",
        tags={"public", "instruction"},
        annotations={
            "idempotentHint": True,
            "readOnlyHint": True,
            "title": "Get Instruction",
            "parameters": {
                "instruction_name": "The name of the instruction (without extension). If a full filename is provided, it will be used as-is. Otherwise, .instructions.md will be appended automatically. This tool is flexible: you can provide just the name (e.g. <instruction_name>) or the full filename (e.g. <instruction_name>.instructions.md). If the extension is missing, it will be added automatically."
            },
            "returns": "Returns the raw markdown content of the specified instruction file, or an error message if not found. Display recommendation: If the file is longer than 40 lines, show the first 10 lines, then '........', then the last 10 lines.",
        },
        meta={
            "category": "instruction",
        },
    )
  • Supporting helper method in InstructionManager class that reads and returns the raw content of the instruction file from the file system, used by the tool handler.
    def get_raw_instruction(self, instruction_name: str, scope: MemoryScope = MemoryScope.user) -> str:
        """
        Get the raw file content of a specific instruction file without any processing.
    
        Args:
            instruction_name: Name of the .instructions.md file
            scope: "user" or "workspace" to determine which directory to use
    
        Returns:
            Raw file content as string
    
        Raises:
            FileOperationError: If file cannot be read
        """
    
        # Ensure filename has correct extension
        instruction_name = self._ensure_instruction_extension(instruction_name)
    
        prompts_dir = self._get_prompts_dir(scope)
        file_path = prompts_dir / instruction_name
    
        if not file_path.exists():
            raise FileOperationError(f"Instruction file not found: {instruction_name}")
    
        try:
            with open(file_path, "r", encoding="utf-8") as f:
                return f.read()
    
        except Exception as e:
            raise FileOperationError(f"Error reading raw instruction file {instruction_name}: {e}")

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/NiclasOlofsson/mode-manager-mcp'

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