Skip to main content
Glama

visualizeDependencies

Generate visual diagrams of task dependencies in Mermaid, tree, or ASCII formats to clarify project relationships and planning structure.

Instructions

生成当前任务依赖关系的可视化图。

Args: format (str, optional): 输出的格式。可接受的值为 'mermaid' (生成流程图代码), 'tree' (生成树状图), 或 'ascii' (生成纯文本格式的列表)。 默认为 'ascii'。

Returns: str: 包含所选格式可视化内容的字符串。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoascii

Implementation Reference

  • Handler function for the 'visualizeDependencies' tool. Decorated with @mcp.tool() for registration in FastMCP. Accepts 'format' parameter and delegates to DependencyVisualizer for rendering.
    @mcp.tool()
    def visualizeDependencies(format: str = "ascii") -> str:
        """
        生成当前任务依赖关系的可视化图。
    
        Args:
            format (str, optional): 输出的格式。可接受的值为 'mermaid' (生成流程图代码), 
                                  'tree' (生成树状图), 或 'ascii' (生成纯文本格式的列表)。
                                  默认为 'ascii'。
        
        Returns:
            str: 包含所选格式可视化内容的字符串。
        """
        from .dependency_tools import DependencyVisualizer
        visualizer = DependencyVisualizer(plan_manager)
        if format == "ascii":
            visualization = visualizer.generate_ascii_graph()
        elif format == "tree":
            visualization = visualizer.generate_tree_view()
        elif format == "mermaid":
            visualization = visualizer.generate_mermaid_graph()
        else:
            visualization = visualizer.generate_ascii_graph()
        return visualization
  • The @mcp.tool() decorator registers the visualizeDependencies function as an MCP tool.
    @mcp.tool()
  • Function signature defining the tool schema: input 'format' as str (default 'ascii'), output str.
    def visualizeDependencies(format: str = "ascii") -> str:
  • Core helper class implementing the visualization logic for ASCII, tree, and Mermaid formats via methods generate_ascii_graph(), generate_tree_view(), and generate_mermaid_graph().
    class DependencyVisualizer:
        """依赖关系可视化工具"""
        
        def __init__(self, plan_manager: PlanManager):
            self.pm = plan_manager
        
        def generate_mermaid_graph(self) -> str:
            """生成Mermaid流程图代码"""
            graph_data = self.pm.getDependencyGraph()
            if not graph_data["success"]:
                return "Error: Could not get dependency graph"
            
            nodes = graph_data["data"]["nodes"]
            edges = graph_data["data"]["edges"]
            
            # 状态颜色映射
            status_colors = {
                "pending": "fill:#e1f5fe",
                "in_progress": "fill:#fff3e0", 
                "completed": "fill:#e8f5e8",
                "failed": "fill:#ffebee",
                "skipped": "fill:#f3e5f5"
            }
            
            mermaid_code = ["flowchart TD"]
            
            # 添加节点
            for node in nodes:
                node_id = f"T{node['id']}"
                node_name = node['name'].replace('"', "'")
                status = node['status']
                
                # 根据状态选择节点形状
                if status == "completed":
                    shape = f'{node_id}["{node_name}"]'
                elif status == "in_progress":
                    shape = f'{node_id}(("{node_name}"))'
                elif status == "failed":
                    shape = f'{node_id}["{node_name}"]'
                else:
                    shape = f'{node_id}["{node_name}"]'
                
                mermaid_code.append(f"    {shape}")
                
                # 添加样式
                if status in status_colors:
                    mermaid_code.append(f"    style {node_id} {status_colors[status]}")
            
            # 添加边
            for edge in edges:
                from_node = f"T{edge['from']}"
                to_node = f"T{edge['to']}"
                mermaid_code.append(f"    {from_node} --> {to_node}")
            
            return "\n".join(mermaid_code)
        
        def generate_ascii_graph(self) -> str:
            """生成ASCII文本图"""
            graph_data = self.pm.getDependencyGraph()
            if not graph_data["success"]:
                return "Error: Could not get dependency graph"
            
            nodes = {node["id"]: node for node in graph_data["data"]["nodes"]}
            edges = graph_data["data"]["edges"]
            
            # 构建邻接表
            dependencies = {}
            for edge in edges:
                to_id = edge["to"]
                from_id = edge["from"]
                if to_id not in dependencies:
                    dependencies[to_id] = []
                dependencies[to_id].append(from_id)
            
            # 状态符号
            status_symbols = {
                "pending": "⏳",
                "in_progress": "🔄", 
                "completed": "✅",
                "failed": "❌",
                "skipped": "⏭️"
            }
            
            ascii_lines = ["📋 任务依赖关系图", "=" * 50]
            
            # 按ID排序显示任务
            for task_id in sorted(nodes.keys()):
                node = nodes[task_id]
                symbol = status_symbols.get(node["status"], "❓")
                
                line = f"{symbol} [{task_id}] {node['name']}"
                
                # 显示依赖关系
                if task_id in dependencies:
                    deps = dependencies[task_id]
                    dep_names = [f"[{dep_id}]" for dep_id in sorted(deps)]
                    line += f" (依赖: {', '.join(dep_names)})"
                
                ascii_lines.append(line)
            
            # 添加图例
            ascii_lines.extend([
                "",
                "📝 状态图例:",
                "⏳ 待处理  🔄 进行中  ✅ 已完成  ❌ 失败  ⏭️ 跳过"
            ])
            
            return "\n".join(ascii_lines)
        
        def generate_tree_view(self) -> str:
            """生成树状视图"""
            graph_data = self.pm.getDependencyGraph()
            if not graph_data["success"]:
                return "Error: Could not get dependency graph"
            
            nodes = {node["id"]: node for node in graph_data["data"]["nodes"]}
            edges = graph_data["data"]["edges"]
            
            # 构建父子关系
            children = {}
            parents = {}
            
            for edge in edges:
                parent_id = edge["from"]
                child_id = edge["to"]
                
                if parent_id not in children:
                    children[parent_id] = []
                children[parent_id].append(child_id)
                
                if child_id not in parents:
                    parents[child_id] = []
                parents[child_id].append(parent_id)
            
            # 找到根节点(没有父节点的节点)
            all_nodes = set(nodes.keys())
            root_nodes = all_nodes - set(parents.keys())
            
            def build_tree(node_id: int, prefix: str = "", is_last: bool = True) -> List[str]:
                node = nodes[node_id]
                symbol = "✅" if node["status"] == "completed" else "⏳" if node["status"] == "pending" else "🔄"
                
                connector = "└── " if is_last else "├── "
                lines = [f"{prefix}{connector}{symbol} [{node_id}] {node['name']}"]
                
                if node_id in children:
                    child_nodes = sorted(children[node_id])
                    for i, child_id in enumerate(child_nodes):
                        is_last_child = (i == len(child_nodes) - 1)
                        extension = "    " if is_last else "│   "
                        lines.extend(build_tree(child_id, prefix + extension, is_last_child))
                
                return lines
            
            tree_lines = ["🌳 任务依赖树状图", "=" * 30]
            
            for root_id in sorted(root_nodes):
                tree_lines.extend(build_tree(root_id))
                tree_lines.append("")
            
            return "\n".join(tree_lines)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It describes what the tool does (generates visualization) and the return type (string), but doesn't address important behavioral aspects: whether this is a read-only operation, what '当前任务' (current task) refers to in context, whether it requires specific state or permissions, or any performance characteristics. The description is functional but lacks behavioral context needed for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized. It leads with the core purpose, then provides clear parameter documentation in an 'Args' section, and concludes with return information. Every sentence earns its place, though the Chinese-to-English code values might create minor cognitive friction for English-speaking agents.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (visualization generation with format options), no annotations, and no output schema, the description is minimally adequate. It covers the purpose and parameters well, but lacks context about what 'current task dependencies' means, how the visualization is structured, or any limitations. The absence of behavioral context and sibling tool differentiation leaves gaps for an agent trying to use this effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant value beyond the input schema. With 0% schema description coverage and only one parameter, the description fully documents the 'format' parameter: it explains the optional nature, acceptable values ('mermaid', 'tree', 'ascii'), what each format produces, and the default value ('ascii'). This completely compensates for the lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '生成当前任务依赖关系的可视化图' (generate a visualization of current task dependencies). It specifies the verb ('生成' - generate) and resource ('当前任务依赖关系的可视化图' - visualization of current task dependencies). However, it doesn't explicitly distinguish this from sibling tools like 'dumpPlan' or 'getTaskList' which might also provide task information in different formats.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'dumpPlan' (which might output plan data), 'getTaskList' (which might list tasks), or 'editDependencies' (which modifies dependencies). There's no context about when visualization is preferred over other representations of task dependencies.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/donway19/MCPlanManager'

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