Skip to main content
Glama

visualizeDependencies

Generate visual representations of task dependencies in formats like mermaid flowcharts, tree diagrams, or plain text lists to streamline task management and planning in MCPlanManager.

Instructions

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

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

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoascii

Implementation Reference

  • The main handler function for the 'visualizeDependencies' tool, decorated with @mcp.tool() which also serves as registration. It creates a DependencyVisualizer instance and dispatches to format-specific visualization methods.
    @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
  • Helper method in DependencyVisualizer class that generates Mermaid flowchart code for task dependencies, used when format='mermaid'.
    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)
  • Helper method in DependencyVisualizer class that generates ASCII art representation of task dependencies with status symbols, default format.
    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)
  • Helper method in DependencyVisualizer class that generates a tree view of task dependencies starting from root nodes.
    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)
  • The @mcp.tool() decorator registers the visualizeDependencies function as an MCP tool.
    @mcp.tool()

Other Tools

Related 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