Skip to main content
Glama
YuChenSSR

Mindmap MCP Server

convert_markdown_to_mindmap

Transform Markdown content into interactive mindmaps to visualize hierarchical information through HTML output or saved files.

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
NameRequiredDescriptionDefault
markdown_contentYes

Implementation Reference

  • The main handler function for the 'convert_markdown_to_mindmap' tool, decorated with @mcp.tool() for registration. Converts Markdown to mindmap HTML using temporary files and markmap-cli subprocess. Includes inline schema via type hints and docstring.
    @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)}")
  • Helper function to execute markmap-cli via asyncio subprocess on the input Markdown file and generate the HTML mindmap output file.
    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)}")
  • Helper to create a temporary Markdown file from the input content for processing.
    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
  • 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()
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/YuChenSSR/mindmap-mcp-server'

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