Skip to content

XJTLUmedia/MCP_Markdown_Formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

58 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Answer Copier β€” MCP-Powered Multi-Format Exporter

Turn "AI Noise" into "Classroom Ready" in 5 Seconds.

npm version License: MIT MCP Registry Glama GitHub

A Model Context Protocol (MCP) server that gives your AI assistant the power to convert Markdown into 23+ professional document formats, analyze documents, repair broken Markdown, and convert across platforms β€” all without leaving your AI chat.

image

npm: https://www.npmjs.com/package/@xjtlumedia/markdown-mcp-server


Why This Exists

You asked an AI to write 20 questions. It delivered. But now you're stuck:

Pain Point Manual Workflow With AI Answer Copier
Extracting Q&A 10–15 min copying each line 2 seconds (auto-detect)
Formatting Math 20 min fixing broken symbols Instant (KaTeX support)
LMS Upload 15 min manual CSV entry 1-click export
Total Prep Time ~45–60 minutes < 1 minute

Generating content takes seconds. Formatting it for the real world takes an hour. This MCP server eliminates that gap entirely.


Live Demo

Online web version (no install needed): ai-answer-copier.vercel.app

live_demo1 live_demo2

Test MCP tool in inspector:

MCP server

Use actual MCP instance:

MCP1 MCP2

All 33 MCP Tools

Document Conversion Tools (15)

# Tool Output Description
1 harmonize_markdown .md Standardize and normalize Markdown syntax (ATX headers, - list markers, fenced code blocks) without changing meaning
2 convert_to_txt .txt Strip all formatting to produce plain text
3 convert_to_html .html Full styled HTML document with GFM tables, KaTeX math, and embedded stylesheet
4 generate_html HTML string Generate self-contained HTML with all styles inlined (read-only, no file I/O)
5 convert_to_pdf .pdf Print-ready PDF via headless Chromium with full KaTeX math and syntax highlighting
6 convert_to_docx .docx Microsoft Word document with styled headings, lists, and code formatting
7 convert_to_latex .tex LaTeX source code with \section, list environments, and native math pass-through
8 convert_to_rtf .rtf Rich Text Format for legacy word processors and email clients
9 convert_to_csv .csv Extract GFM pipe-tables to comma-separated values
10 convert_to_json .json Structured JSON representation with sections, headings, lists, code blocks, and tables
11 convert_to_xml .xml Well-formed XML with <?xml?> declaration and structured elements
12 convert_to_xlsx .xlsx Excel spreadsheet β€” each Markdown table becomes a sheet
13 convert_to_image .png Full-page PNG screenshot via headless Chromium
14 convert_to_md .md Export Markdown to file, optionally harmonizing formatting first (harmonize=true)
15 convert_to_email_html .html Email-optimized HTML with all styles inlined, compatible with Outlook, Gmail, Apple Mail

Platform Converter Tools (10)

# Tool Target Platform Description
16 convert_to_slack Slack mrkdwn format β€” bold as *, links as <url|text>, headers as bold text
17 convert_to_discord Discord Styled bold/underline headers, preserved code blocks
18 convert_to_jira JIRA Wiki markup β€” h1./h2., {code} blocks, [text|url] links
19 convert_to_confluence Confluence Wiki markup with {info}, {note} panels and {code:language=x} syntax
20 convert_to_asciidoc AsciiDoc = headers, ---- code blocks, url[text] links, image:: directives
21 convert_to_rst reStructuredText Underlined headers, .. code-block:: directives, RST reference syntax
22 convert_to_mediawiki MediaWiki == headers, '''bold''', <syntaxhighlight> tags, {\ wikitable
23 convert_to_bbcode BBCode [b], [i], [code], [url], [img] tags for phpBB/vBulletin forums
24 convert_to_textile Textile Markup for Redmine, Basecamp, and CMS platforms
25 convert_to_orgmode Emacs Org Mode * headers, #+BEGIN_SRC/#+END_SRC code, [[url][text]] links

Import Tools (1)

# Tool Description
26 html_to_markdown Convert HTML content (full document or fragment) back to Markdown

Repair & Lint Tools (2)

# Tool Description
27 repair_markdown Fix broken Markdown from LLM output or copy-paste β€” unclosed code fences, broken tables, stray emphasis markers, missing heading spaces, broken links
28 lint_markdown Lint and report issues as JSON array with line number, severity, rule name, message, and fixable flag

Document Analysis Tools (5)

# Tool Description
29 extract_code_blocks Extract all code blocks with language, content, and start/end line numbers
30 extract_links Extract all links and images with text, URL, line number, and type (inline, reference, image, autolink)
31 generate_toc Generate Markdown Table of Contents from headings with configurable max_depth (1–6)
32 analyze_document Comprehensive statistics β€” line/word/character/paragraph/sentence counts, heading/code/table/link/image counts, estimated reading time
33 extract_structure Bird's-eye document architecture β€” statistics, heading outline, code block summary, link summary

6 Built-in Prompts

Pre-configured prompt templates that orchestrate multiple tools:

Prompt Description
convert-document Convert Markdown to any supported format (PDF, DOCX, HTML, LaTeX, CSV, JSON, XML, XLSX, RTF, PNG, TXT, MD)
extract-tables Extract all tables from Markdown and export as CSV or XLSX
format-for-sharing Harmonize formatting, then convert to both PDF and HTML for distribution
analyze-and-repair Lint β†’ Repair β†’ Re-lint to confirm all issues resolved
convert-for-platform Convert Markdown to any platform format (Slack, Discord, JIRA, Confluence, AsciiDoc, RST, MediaWiki, BBCode, Textile, Org Mode)
document-overview Full overview β€” statistics, TOC, code blocks, and links in one report

2 Resources

Resource URI Description
markdown-formatter://supported-formats Complete JSON list of all 23+ output formats with tool names and types
markdown-formatter://conversion-guide Guide for choosing the right output format based on your use case

Quick Start

Install via npx (Recommended)

No installation needed β€” just configure your MCP client:

{
  "mcpServers": {
    "ai-answer-copier": {
      "command": "npx",
      "args": ["-y", "@xjtlumedia/markdown-mcp-server"]
    }
  }
}

Install Globally

npm install -g @xjtlumedia/markdown-mcp-server

Then configure:

{
  "mcpServers": {
    "ai-answer-copier": {
      "command": "markdown-mcp-server"
    }
  }
}

Configuration by AI Client

πŸ”Œ Claude Desktop

image

Edit %APPDATA%\Claude\claude_desktop_config.json (Windows) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "ai-answer-copier": {
      "command": "npx",
      "args": ["-y", "@xjtlumedia/markdown-mcp-server"]
    }
  }
}

Restart Claude Desktop. You'll see a πŸ”Œ icon β€” all 33 tools are now available.

VS Code (GitHub Copilot)

Add to .vscode/mcp.json or VS Code settings:

{
  "servers": {
    "ai-answer-copier": {
      "command": "npx",
      "args": ["-y", "@xjtlumedia/markdown-mcp-server"]
    }
  }
}

Cursor / Windsurf / Any MCP Client

Use the same npx command pattern above in your client's MCP configuration.

DIY version (local build)

{
  "mcpServers": {
    "markdown-formatter": {
      "command": "node",
      "args": [
        "YOUR_PATH_TO_PROJECT/mcp-server/dist/mcp-server/src/index.js"
      ]
    }
  }
}

Replace YOUR_PATH_TO_PROJECT with the absolute path to this folder.

HTTP Mode (Vercel)

A hosted HTTP endpoint is available for browser-based and remote integrations:

https://ai-answer-copier.vercel.app/api/mcp

Test with MCP Inspector:

npx @modelcontextprotocol/inspector https://ai-answer-copier.vercel.app/api/mcp

Usage Examples

Once connected, just talk to your AI naturally:

"Generate 10 physics questions about Newton's Laws and export them as a Kahoot CSV." β†’ AI uses convert_to_csv

"Convert this markdown into a Word document and save it to my Desktop." β†’ AI calls convert_to_docx with output_path

"Take these lecture notes and produce a print-ready PDF." β†’ AI calls convert_to_pdf with Puppeteer rendering, KaTeX math, and syntax highlighting

"Turn this into a Moodle-compatible XML quiz bank." β†’ AI calls convert_to_xml

"Format this for Slack and send it to the team channel." β†’ AI calls convert_to_slack

"Check this Markdown for issues and fix them." β†’ AI calls lint_markdown then repair_markdown

"Give me an overview of this document β€” word count, structure, all links." β†’ AI chains analyze_document + generate_toc + extract_links


Features

23+ Output Formats

Export to PDF, DOCX, HTML, LaTeX, CSV, JSON, XML, XLSX, RTF, PNG, TXT, Markdown β€” plus Slack, Discord, JIRA, Confluence, AsciiDoc, RST, MediaWiki, BBCode, Textile, Org Mode, and Email HTML.

Math & Code as First-Class Citizens

Full support for KaTeX math expressions and syntax-highlighted code blocks. Your $\sqrt{x^2 + y^2}$ and Python snippets survive every conversion perfectly.

Smart Binary Handling

Binary formats (PDF, DOCX, XLSX, PNG) don't dump raw base64 into chat. The server returns actionable guidance so the AI knows to save to a file path.

Document Analysis & Repair

Lint Markdown, auto-repair broken formatting, extract code blocks and links, generate Table of Contents, and get comprehensive document statistics β€” all without leaving the chat.

GFM (GitHub Flavored Markdown)

Tables, task lists, strikethrough, autolinks β€” all parsed correctly via remark-gfm.

Puppeteer-Powered PDF & PNG

PDF and image exports use headless Chromium for pixel-perfect rendering with full CSS styling, KaTeX math, syntax highlighting, and print-optimized layouts.

Self-Contained

Zero runtime dependencies on external APIs. Everything runs locally. Your data never leaves your computer.


Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  AI Client               β”‚
β”‚  (Claude, Copilot,      β”‚
β”‚   Cursor, Windsurf)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ MCP Protocol (stdio / HTTP)
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  AI Answer Copier        β”‚
β”‚  MCP Server (33 tools)   β”‚
β”‚                          β”‚
β”‚  β”Œβ”€β”€ Conversion ────────┐│
β”‚  β”‚ remark/rehype, docx, β”‚β”‚
β”‚  β”‚ puppeteer, xlsx,     β”‚β”‚
β”‚  β”‚ CSV/JSON/XML/RTF/    β”‚β”‚
β”‚  β”‚ LaTeX/TXT parsers    β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚  β”Œβ”€β”€ Platform ──────────┐│
β”‚  β”‚ Slack, Discord, JIRA,β”‚β”‚
β”‚  β”‚ Confluence, AsciiDoc,β”‚β”‚
β”‚  β”‚ RST, MediaWiki,      β”‚β”‚
β”‚  β”‚ BBCode, Textile, Org β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚  β”Œβ”€β”€ Analysis ──────────┐│
β”‚  β”‚ Code blocks, links,  β”‚β”‚
β”‚  β”‚ TOC, stats, structureβ”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚  β”Œβ”€β”€ Repair ────────────┐│
β”‚  β”‚ Lint, auto-repair    β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚  β”Œβ”€β”€ Import ────────────┐│
β”‚  β”‚ HTML β†’ Markdown      β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

What's New in v2.1.0

This release hardens both the local (npx) and remote Vercel MCP transports with 8 logic fixes:

# Fix Area
1 Browser not closed on error β€” try/finally around browser.close() so Chromium never leaks on PDF/PNG failures Both transports
2 generate_html missing KaTeX CSS β€” restored viewport meta, KaTeX stylesheet (SRI hash), and full inline styles so math renders correctly Vercel /api/mcp
3 convert_to_html incomplete styles β€” added SRI integrity hash, table borders, and blockquote styling to match local output Vercel /api/mcp
4 Session map memory leak β€” instances Map now evicts stale sessions after 30 minutes (SESSION_TTL_MS); McpInstance tracks lastUsed Vercel /api/mcp
5 keepAlive interval not cleared on normal SSE stream end β€” added inner try/finally that always calls clearInterval(keepAlive) Vercel /api/mcp
6 _initialized SDK-internal access β€” replaced bare @ts-ignore with a typeof guard so the server fails gracefully after SDK upgrades Vercel /api/mcp
7 No input size validation β€” added 1 GB hard limit (MAX_INPUT_BYTES) to all tool calls to prevent runaway CPU/memory on oversized payloads Both transports
8 DELETE method creates new session β€” handler now returns 200 immediately on DELETE, preventing phantom session creation Vercel /api/mcp

Known Limitations

  • PDF / PNG require local Chromium β€” convert_to_pdf and convert_to_image launch a headless browser. This works fine with npx but is unavailable on Vercel's free tier (no bundled Chromium). Set the PUPPETEER_EXECUTABLE_PATH environment variable to point to your local Chrome if auto-detection fails.
  • Chromium version on Vercel β€” the remote endpoint uses @sparticuz/chromium-min with a pinned tar at v131.0.1. If Vercel bumps the Lambda runtime you may need to update the CHROMIUM_TAR_URL env var.
  • 1 MB input limit β€” all tool calls reject inputs larger than 1 MB. Split large documents into sections before converting.
  • Session TTL (remote only) β€” sessions on the Vercel endpoint expire after 30 minutes of inactivity. Long-running stateful workflows should issue periodic keep-alive calls.

Development

# Clone the repository
git clone https://github.com/XJTLUmedia/AI_answer_copier.git

# Web app
npm install
npm run dev

# MCP server
cd mcp-server
npm install
npm run dev     # hot reload
npm run build   # production build
npm run inspector  # test with MCP Inspector

Tech Stack

Component Technology
MCP SDK @modelcontextprotocol/sdk
Markdown Parser unified + remark + rehype
Math Rendering remark-math + rehype-katex
Word Export docx
Excel Export xlsx
PDF/PNG Export puppeteer
Schema Validation zod
Runtime Node.js (ESM)

Contributing

We welcome contributions! Whether it's a new export format, a bug fix, or documentation improvement β€” please consider making a pull request.

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License

MIT Β© XJTLUmedia


Built by educators, for educators.
Reclaim 5 hours of your week. Let the AI handle the formatting.

About

Copy your formatted answer from any AI chat

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors