Skip to main content
Glama

get_skill_related_file

Read file content from AI skill directories by specifying a skill name and relative file path. Retrieve text content, file paths, or both for supporting files within skill packages.

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

TableJSON Schema
NameRequiredDescriptionDefault
skill_nameYes
relative_pathYes
return_typeNoboth

Implementation Reference

  • Handler function for the MCP tool 'get_skill_related_file'. Decorated with @mcp_server.tool() for automatic registration and schema inference. Delegates execution to SkillParser.get_skill_file.
    @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 method implementing the file retrieval logic: finds skill, resolves path safely (prevents traversal), reads content or path as requested.
    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")
  • Invocation of register_skill_tools during MCP server initialization, which defines and registers the 'get_skill_related_file' tool among others.
    from skill_to_mcp.tools._skills import register_skill_tools register_skill_tools(mcp_server, 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