Skip to main content
Glama
owayo

MCP Source Relation Server

get_source_relation

Analyze dependencies between source files to identify relationships and manage project structure effectively.

Instructions

Analyze dependencies between source files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • The main handler function for the 'get_source_relation' tool. It is decorated with @mcp.tool() which registers it as an MCP tool. The function creates a SourceAnalyzer instance, analyzes the source file or directory for dependencies (recursively if file), and returns a JSON string with the dependencies graph.
    @mcp.tool()
    def get_source_relation(path: str) -> str:
        """Analyze dependencies between source files"""
        path_obj = Path(path)
        base_dir = str(path_obj.parent if path_obj.is_file() else path_obj)
        analyzer = SourceAnalyzer(base_dir)
    
        # ソースコードを解析
        if path_obj.is_file():
            analyzed_files: Set[str] = set()
            file_path = str(path_obj.absolute())
            dependencies = analyze_dependencies_recursively(
                analyzer, file_path, analyzed_files
            )
        else:
            dependencies = analyzer.analyze_directory()
    
        # 結果をまとめる
        result = {"dependencies": dependencies}
    
        return json.dumps(result, indent=2, ensure_ascii=False)
  • Helper function used by the handler to recursively analyze dependencies starting from a given file, building a full dependency dictionary by calling analyzer.analyze_single_file and recursing on direct dependencies.
    def analyze_dependencies_recursively(
        analyzer: SourceAnalyzer, file_path: str, analyzed_files: Set[str]
    ) -> Dict[str, List[str]]:
        """ファイルの依存関係を再帰的に解析する
    
        Args:
            analyzer (SourceAnalyzer): 解析を行うアナライザーインスタンス
            file_path (str): 解析対象のファイルパス
            analyzed_files (Set[str]): 解析済みファイルのセット
    
        Returns:
            Dict[str, List[str]]: 解析されたすべての依存関係の辞書
        """
        if file_path in analyzed_files:
            return {}
    
        analyzed_files.add(file_path)
        dependencies: Dict[str, List[str]] = {}
    
        # ファイルを解析
        try:
            current_deps = analyzer.analyze_single_file(Path(file_path))
            direct_dependencies = current_deps.get(file_path, [])
            dependencies[file_path] = direct_dependencies
    
            # 各依存ファイルについても再帰的に解析
            for dependency in direct_dependencies:
                if dependency not in analyzed_files:
                    nested_deps = analyze_dependencies_recursively(
                        analyzer, dependency, analyzed_files
                    )
                    dependencies.update(nested_deps)
        except Exception:
            pass
    
        return dependencies
  • Key method in SourceAnalyzer called by the recursive helper to analyze a single file's direct dependencies and compute recursive ones.
    def analyze_single_file(self, file_path: Path) -> Dict[str, List[str]]:
        """単一のファイルを解析する
    
        Args:
            file_path (Path): 解析対象のファイルパス
    
        Returns:
            Dict[str, List[str]]: ファイルの完全な依存関係(直接および間接的な依存関係を含む)
        """
        self.analyze_file(file_path)
        normalized_path = self.normalize_path(file_path)
        return {normalized_path: self.get_recursive_dependencies(normalized_path)}

Tool Description Quality Score

Score is being calculated. Check back soon.

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/owayo/mcp-source-relation'

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