Skip to main content
Glama

get_skill_related_file

Retrieve file content or paths from skill directories to access supporting scripts, documentation, and resources for AI skill implementation.

Instructions

Read the content of a specific file within a skill directory.

This tool returns the requested file based on a path relative to the skill's SKILL.md location. Use get_skill_details() first to see the list of available files.

Parameters

skill_name : str The name of the skill. relative_path : str Path to the file relative to the skill directory (e.g., "scripts/qc_core.py"). return_type : str Type of data to return: "content" (default), "file_path", or "both". - "content": Returns only the file content as text - "file_path": Returns only the absolute path to the file - "both": Returns both content and file path in a dict

Returns

str | dict[str, str] If return_type is "content": The content of the requested file. If return_type is "file_path": The absolute path to the file. If return_type is "both": Dictionary with "content" and "file_path" keys.

Raises

ValueError If the skill or file is not found, if the path is invalid, or if return_type is invalid.

Examples

content = get_skill_related_file("single-cell-rna-qc", "scripts/qc_core.py", return_type="content") print(len(content) > 0) True

Input Schema

NameRequiredDescriptionDefault
skill_nameYes
relative_pathYes
return_typeNoboth

Input Schema (JSON Schema)

{ "properties": { "relative_path": { "type": "string" }, "return_type": { "default": "both", "type": "string" }, "skill_name": { "type": "string" } }, "required": [ "skill_name", "relative_path" ], "type": "object" }

Implementation Reference

  • The handler function for the 'get_skill_related_file' MCP tool. It defines the input parameters, docstring schema, and delegates the core logic to SkillParser.get_skill_file. Registered via @mcp_server.tool() decorator.
    @mcp_server.tool() def get_skill_related_file(skill_name: str, relative_path: str, return_type: str = "both") -> "str | dict[str, str]": """Read the content of a specific file within a skill directory. This tool returns the requested file based on a path relative to the skill's SKILL.md location. Use get_skill_details() first to see the list of available files. Parameters ---------- skill_name : str The name of the skill. relative_path : str Path to the file relative to the skill directory (e.g., "scripts/qc_core.py"). return_type : str Type of data to return: "content" (default), "file_path", or "both". - "content": Returns only the file content as text - "file_path": Returns only the absolute path to the file - "both": Returns both content and file path in a dict Returns ------- str | dict[str, str] If return_type is "content": The content of the requested file. If return_type is "file_path": The absolute path to the file. If return_type is "both": Dictionary with "content" and "file_path" keys. Raises ------ ValueError If the skill or file is not found, if the path is invalid, or if return_type is invalid. Examples -------- >>> content = get_skill_related_file("single-cell-rna-qc", "scripts/qc_core.py", return_type="content") >>> print(len(content) > 0) True """ try: return skill_parser.get_skill_file(skill_name, relative_path, return_type=return_type) except ValueError as e: raise ValueError(f"Error reading skill file: {e}") from e
  • Core helper function implementing the file retrieval logic, including security checks against directory traversal, file existence validation, and content reading.
    def get_skill_file( self, skill_name: str, relative_path: str, return_type: str = "both" ) -> "str | dict[str, str]": """Get content of a specific file within a skill directory. Parameters ---------- skill_name : str Name of the skill. relative_path : str Path relative to the skill directory. return_type : str Type of data to return: "content", "file_path", or "both" (default). Returns ------- str | dict[str, str] If return_type is "content": Content of the requested file. If return_type is "file_path": Absolute path to the file. If return_type is "both": Dictionary with "content" and "file_path" keys. Raises ------ ValueError If skill or file is not found, if path is invalid, or if return_type is invalid. """ if return_type not in ("content", "file_path", "both"): raise ValueError(f"Invalid return_type: {return_type}. Must be 'content', 'file_path', or 'both'") skills = self.find_all_skills() for skill in skills: if skill.name == skill_name: # Validate path to prevent directory traversal file_path = (skill.skill_path / relative_path).resolve() if not file_path.is_relative_to(skill.skill_path.resolve()): raise ValueError("Invalid path: attempting to access files outside skill directory") if not file_path.exists(): raise ValueError(f"File not found: {relative_path}") if not file_path.is_file(): raise ValueError(f"Path is not a file: {relative_path}") if return_type == "content": return file_path.read_text(encoding="utf-8") elif return_type == "file_path": return str(file_path) else: # both return { "content": file_path.read_text(encoding="utf-8"), "file_path": str(file_path), } raise ValueError(f"Skill '{skill_name}' not found")
  • Calls register_skill_tools to register the 'get_skill_related_file' tool (among others) with the FastMCP server instance.
    # Register tools with the configured skills directory from skill_to_mcp.tools._skills import register_skill_tools register_skill_tools(mcp_server, skills_dir) return mcp_server
  • The register_skill_tools function defines and registers all skill-related MCP tools, including get_skill_related_file via @mcp_server.tool() decorators.
    def register_skill_tools(mcp_server: FastMCP, skills_dir: str | Path) -> None: """Register skill tools with the MCP server. Parameters ---------- mcp_server : FastMCP The FastMCP server instance to register tools with. skills_dir : str | Path Path to the directory containing skill subdirectories. """ # Initialize the skill parser with the provided skills directory skill_parser = SkillParser(skills_dir)

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/biocontext-ai/skill-to-mcp'

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