convert_markdown_to_mindmap
Transform Markdown content into interactive mindmaps for visualizing hierarchical information. Generates HTML output or saves files for easy integration and AI-assisted analysis.
Instructions
Convert Markdown content to a mindmap mind map.
Args:
markdown_content: The Markdown content to convert
Returns:
Either the HTML content or the file path to the generated HTML,
depending on the --return-type server argument
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| markdown_content | Yes |
Implementation Reference
- mindmap_mcp_server/server.py:69-100 (handler)The core handler function for 'convert_markdown_to_mindmap', decorated with @mcp.tool() for registration. It creates a temp Markdown file, runs markmap-cli to generate HTML mindmap, and returns either the HTML content or file path based on configuration.@mcp.tool() async def convert_markdown_to_mindmap( markdown_content: str, # The Markdown content to convert ) -> str: """Convert Markdown content to a mindmap mind map. Args: markdown_content: The Markdown content to convert Returns: Either the HTML content or the file path to the generated HTML, depending on the --return-type server argument """ try: # Create a temporary markdown file input_file = await create_temp_file(markdown_content, '.md') # Run mindmap on it output_file = await run_mindmap(input_file) # Check if the output file exists if not os.path.exists(output_file): raise RuntimeError(f"Output file was not created: {output_file}") # Return either the HTML content or the file path based on command line arg if RETURN_TYPE == 'html': html_content = await get_html_content(output_file) return html_content else: return output_file except Exception as e: raise RuntimeError(f"Error converting Markdown to mindmap: {str(e)}")
- mindmap_mcp_server/server.py:38-62 (helper)Helper function that executes markmap-cli to convert Markdown file to HTML mindmap.async def run_mindmap(input_file: str, output_file: str = None) -> str: """Run markmap-cli on the input file and return the path to the output file.""" args = ['npx', '-y', 'markmap-cli', input_file, '--no-open'] if output_file: args.extend(['-o', output_file]) else: output_file = os.path.splitext(input_file)[0] + '.html' try: process = await asyncio.create_subprocess_exec( *args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) stdout, stderr = await process.communicate() if process.returncode != 0: error_msg = stderr.decode() if stderr else "Unknown error" raise RuntimeError(f"markmap-cli exited with code {process.returncode}: {error_msg}") return output_file except Exception as e: raise RuntimeError(f"Failed to run markmap-cli: {str(e)}")
- mindmap_mcp_server/server.py:28-36 (helper)Helper to create a temporary Markdown file from provided content.async def create_temp_file(content: str, extension: str) -> str: """Create a temporary file with the given content and extension.""" temp_dir = tempfile.mkdtemp(prefix='mindmap-') file_path = os.path.join(temp_dir, f"input{extension}") with open(file_path, mode='w') as f: f.write(content) return file_path
- mindmap_mcp_server/server.py:64-67 (helper)Helper to read the generated HTML mindmap file content.async def get_html_content(file_path: str) -> str: """Read the HTML content from the given file.""" with open(file_path, 'r', encoding='utf-8') as f: return f.read()
- mindmap_mcp_server/server.py:70-81 (schema)Schema definition via function signature type hints and docstring describing input (markdown_content: str) and output (str: HTML or file path).async def convert_markdown_to_mindmap( markdown_content: str, # The Markdown content to convert ) -> str: """Convert Markdown content to a mindmap mind map. Args: markdown_content: The Markdown content to convert Returns: Either the HTML content or the file path to the generated HTML, depending on the --return-type server argument """