MCP Hub
Back to servers

karate-graph-mcp

Enables analysis of Karate framework feature files, extracting dependencies and generating interactive dependency graphs.

glama
Updated
May 1, 2026

🚀 Karate Feature Graph Analyzer

A powerful MCP (Model Context Protocol) tool for analyzing Karate Framework feature files and generating interactive dependency graphs.

Python Tests License


📋 Table of Contents


✨ Features

Core Capabilities

  • 🔍 Feature File Parsing - Parse Karate feature files with Gherkin syntax
  • 🎯 Dependency Analysis - Extract and analyze dependencies (workflows, APIs, pages, DB)
  • 📊 Interactive Visualization - Generate beautiful HTML graphs with legend
  • 🎫 Jira Integration - Extract and track Jira tags (@PROJ-123)
  • 🔄 Impact Analysis - Identify affected test cases when components change
  • 📈 Multi-Project Support - Manage and analyze multiple projects
  • 💾 Export/Import - Export graphs to JSON/GraphML formats
  • Performance Optimized - Fast analysis with caching and indices

Visualization Features

  • 🎨 Color-coded nodes by type (Test, Workflow, API, Page, Database)
  • 🔍 Interactive tooltips with metadata (file path, line numbers, Jira tags)
  • 🖱️ Click to highlight connections and dependencies
  • 📊 Legend in top-right corner explaining colors and shapes
  • 🔄 Physics simulation for automatic layout
  • 🎯 Impact view highlighting changed components and affected tests

🚀 Quick Start

1. Install Dependencies

pip install -e .
pip install pyvis  # For visualization

2. Run Demo

# Set UTF-8 encoding (Windows)
$env:PYTHONIOENCODING="utf-8"

# Run large project demo
python test_large_project.py

3. View Results

cd output
start ecommerce-platform_full.html

📦 Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Install from Source

# Clone repository
git clone <repository-url>
cd karate-feature-graph-analyzer

# Install dependencies
pip install -e .

# Install visualization library
pip install pyvis

# Verify installation
pytest tests/ -v

Dependencies

Core dependencies (auto-installed):

  • networkx - Graph operations
  • hypothesis - Property-based testing
  • pydantic - Data validation

Optional dependencies:

  • pyvis - Interactive visualizations

💻 Usage

Basic Usage

from karate_graph_analyzer.mcp_interface.mcp_tool import KarateGraphAnalyzerTool

# Initialize tool
tool = KarateGraphAnalyzerTool()

# Register project
tool.register_project(
    name="my-project",
    root_path="/path/to/karate/project",
    feature_file_patterns=["**/*.feature"]
)

# Analyze project
analysis = tool.analyze_project("my-project")
print(f"Found {analysis['statistics']['total_nodes']} nodes")

# Query dependencies
deps = tool.query_dependencies("tc_0001", transitive=True)
print(f"Found {deps['count']} dependencies")

# Impact analysis
impact = tool.impact_analysis("api_0001")
print(f"Affected: {impact['total_count']} test cases")

# Export graph
export = tool.export_graph("my-project", format="json")
with open("graph.json", "w") as f:
    f.write(export['data'])

Visualization

from karate_graph_analyzer.visualization.graph_visualizer import GraphVisualizer

# Get graph
graph = tool.graphs["my-project"]

# Create visualizer
visualizer = GraphVisualizer(graph)

# Render full graph
visualizer.render("output/graph.html", height="900px")

# Render impact view
visualizer.render_impact_view(
    changed_component_id="api_0001",
    affected_test_case_ids=["tc_0001", "tc_0002"],
    output_path="output/impact.html"
)

Command Line (via Script)

# Analyze large project
python test_large_project.py

# Output will be in output/ directory:
# - ecommerce-platform_full.html (full graph)
# - ecommerce-platform_impact.html (impact view)
# - ecommerce-platform_graph.json (graph data)
# - LARGE_PROJECT_ANALYSIS_REPORT.md (detailed report)

📁 Project Structure

karate-feature-graph-analyzer/
├── src/karate_graph_analyzer/
│   ├── models.py                    # Data models
│   ├── parser/                      # Feature file parsing
│   │   └── feature_parser.py
│   ├── graph/                       # Graph construction
│   │   └── graph_builder.py
│   ├── analyzer/                    # Dependency analysis
│   │   └── dependency_analyzer.py
│   ├── mcp_interface/               # MCP protocol
│   │   └── mcp_tool.py
│   ├── storage/                     # Project registry
│   │   └── project_registry.py
│   ├── cache/                       # AST caching
│   │   └── cache_manager.py
│   ├── visualization/               # Graph visualization
│   │   └── graph_visualizer.py
│   └── logging_config.py            # Logging setup
│
├── tests/
│   ├── unit/                        # 306 unit tests
│   ├── integration/                 # Integration tests
│   └── fixtures/                    # Test data
│
├── output/                          # Generated files
│   ├── ecommerce-platform_full.html
│   ├── ecommerce-platform_impact.html
│   ├── ecommerce-platform_graph.json
│   ├── LARGE_PROJECT_ANALYSIS_REPORT.md
│   └── README.md
│
├── test_project_demo/               # Small demo project
├── test_project_large/              # Large demo project (e-commerce)
├── examples/                        # Usage examples
├── docs/                            # Documentation
│   ├── API.md
│   └── jira_tag_extraction.md
│
├── test_large_project.py            # Demo script
├── pyproject.toml                   # Project config
├── pytest.ini                       # Test config
└── README.md                        # This file

📚 Documentation

Core Documentation

Specifications


🎯 Examples

Example 1: Analyze Demo Project

# Run demo
python test_large_project.py

# View results
cd output
start ecommerce-platform_full.html

What you'll see:

  • 84 nodes (73 test cases, 6 workflows, 3 pages, 1 API, 1 DB)
  • 26 edges (dependencies)
  • Interactive graph with legend
  • Color-coded by type
  • Hover tooltips with metadata

Example 2: Impact Analysis

# Find what tests are affected by API change
impact = tool.impact_analysis("api_0001")

print(f"Changed: {impact['changed_component']}")
print(f"Affected: {impact['total_count']} test cases")

for tc in impact['affected_test_cases']:
    print(f"  - {tc['name']} (depth: {tc['depth']})")
    if tc['jira_tags']:
        print(f"    Jira: {', '.join(tc['jira_tags'])}")

Output:

Changed: api_0001
Affected: 14 test cases
  - Successful login (depth: 1)
    Jira: @AUTH-101
  - Get user profile (depth: 1)
    Jira: @USER-101
  ...

Example 3: Find Common Components

# Find reusable components across projects
common = tool.find_common_components(["project1", "project2"])

for comp in common['components']:
    print(f"{comp['component_type']}: {comp['identifier']}")
    print(f"  Used in {comp['usage_count']} projects")
    print(f"  Projects: {', '.join(comp['projects'])}")

🧪 Testing

Run All Tests

# Run all tests
pytest tests/ -v

# Run specific test suite
pytest tests/unit/ -v
pytest tests/integration/ -v

# Run with coverage
pytest tests/ --cov=src/karate_graph_analyzer --cov-report=html

Test Statistics

  • Total Tests: 306
  • Passing: 306 (100%)
  • Failed: 0
  • Skipped: 1
  • Coverage: Comprehensive

Test Categories

  • Unit Tests (tests/unit/) - Test individual components
  • Integration Tests (tests/integration/) - Test component interactions
  • Property Tests (optional) - Property-based testing with Hypothesis

🎨 Visualization Guide

Understanding the Legend

When you open a visualization HTML file, look at the top-right corner for the legend:

📊 Legend
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🟢 Test Case - Scenario hoặc test
🔵 Workflow - Reusable workflow
🟠 API - API endpoint
🟣 Page - Page object
🔴 Database - Database operation
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
💡 Tip: Hover để xem chi tiết
🖱️ Click để highlight connections
🔍 Scroll để zoom in/out

Interactive Features

  1. Hover - Move mouse over node to see tooltip with:

    • Node name
    • Node type
    • File path
    • Line number
    • Jira tags
  2. Click - Click node to highlight:

    • The selected node
    • All connected nodes
    • All connecting edges
  3. Zoom - Scroll mouse wheel to zoom in/out

  4. Pan - Drag background to move around

  5. Reposition - Drag nodes to rearrange layout


🔧 Configuration

Parser Configuration

from karate_graph_analyzer.models import ParserConfig

config = ParserConfig(
    jira_tag_patterns=[
        r'@[A-Z]+-\d+',      # @PROJ-123
        r'@[a-z]+-\d+',      # @proj-123
        r'@[A-Z]+_\d+',      # @PROJ_123
    ],
    workflow_directories=['workflows', 'common'],
    page_object_directories=['pages', 'page-objects'],
    variable_patterns=[r'\$\{(\w+)\}'],
    api_extraction_rules={
        'extract_from_variables': True,
        'extract_from_strings': True,
    }
)

# Use custom config
tool.register_project(
    name="my-project",
    root_path="/path/to/project",
    parser_config=config
)

📊 Key Metrics

Performance

  • Analysis Time: < 1 second for 4 files
  • Query Time: < 10ms for dependency queries
  • Impact Analysis: < 50ms for 6 affected tests
  • Export Time: < 100ms for 9 nodes
  • Visualization: < 1 second to render

Scalability

  • Tested with: 84 nodes, 26 edges
  • Supports: 1000+ nodes (estimated)
  • Memory: Efficient with caching
  • Storage: JSON format, ~500 bytes per node

🤝 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Clone your fork
git clone <your-fork-url>
cd karate-feature-graph-analyzer

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Run linter
flake8 src/

# Format code
black src/

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments

  • Karate Framework - For the amazing BDD testing framework
  • NetworkX - For graph operations
  • Pyvis - For interactive visualizations
  • Hypothesis - For property-based testing

📞 Support

Documentation

Examples

Issues

If you encounter any issues:

  1. Check the documentation
  2. Review the examples
  3. Open an issue on GitHub

🎉 Quick Links


Built with ❤️ using Spec-Driven Development

Status: ✅ Production Ready
Version: 1.0.0
Last Updated: April 30, 2026

🚀 Happy Analyzing!

Reviews

No reviews yet

Sign in to write a review