Skip to main content
Glama
polarnego

md-to-pdf-with-mermaid-mcp

by polarnego

md-to-pdf-with-mermaid-mcp

Markdown 파일 내 mermaid 코드블록을 SVG로 렌더링한 뒤 이미지 링크로 치환하고, 결과 Markdown을 PDF로 변환하는 MCP 서버입니다. GitHub 저장소를 npx로 직접 실행해 MCP 클라이언트(예: Claude Desktop)에서 도구를 호출할 수 있습니다.

주요 기능

  • Mermaid 렌더링: mermaid 코드블록을 @mermaid-js/mermaid-cli로 SVG 생성

  • 이미지 치환: 원본 Markdown에서 Mermaid 블록을 이미지 링크로 대체

  • PDF 변환: md-to-pdf 사용, 실패 시 pandoc으로 폴백

  • MCP 도구 제공: stdio 기반 MCP 서버로 convert_markdown_to_pdf 도구 노출

요구 사항

  • Node.js 18 이상 (ESM 및 MCP SDK 호환)

  • 네트워크(최초 실행 시 md-to-pdf/mermaid-cli가 Chromium 다운로드 가능)

  • 선택 사항: pandoc 설치(폴백 경로) — macOS: brew install pandoc

저장소 구조

  • mcp-server.js: MCP 서버(표준 입출력) 엔트리. 도구 등록 및 입력 검증(zod)

  • md_mermaid_to_pdf.js: 변환 로직. 라이브러리 함수 convertMarkdownWithMermaidToPdf 노출 및 CLI 가드 포함

  • package.json: 패키지 메타 및 bin 설정 (md-to-pdf-with-mermaid-mcp)

Related MCP server: md2doc

사용 방법

1) MCP 클라이언트에 연결 (Claude Desktop 예시)

MCP 클라이언트 설정에 다음과 같이 등록합니다. GitHub 저장소/태그 정보를 실제 값으로 바꿔주세요.

{
  "mcpServers": {
    "md-to-pdf-with-mermaid": {
      "command": "npx",
      "args": [
        "-y",
        "github:polarnego/md-to-pdf-with-mermaid-mcp"
      ]
    }
  }
}
  • 권장: 릴리즈 태그(v0.1.0 등)를 사용하여 고정 버전 실행

  • npx 실행 시 -y를 넣어 비대화형으로 동의 처리

등록 후, MCP 클라이언트의 도구 패널에서 아래 도구를 사용할 수 있습니다.

  • 도구명: convert_markdown_to_pdf

  • 입력 파라미터:

    • inputPath (string): 입력 .md의 절대 경로

    • outputPath (string): 출력 .pdf의 절대 경로

실행 성공 시 다음과 같은 응답을 반환합니다.

{
  "content": [{ "type": "text", "text": "PDF written: /absolute/path/to/output.pdf" }]
}

참고: MCP 서버에서는 안전성을 위해 절대 경로만 허용합니다.

2) 직접 실행(비-MCP)

로컬에서 변환만 테스트하려면 다음 명령을 사용할 수 있습니다.

node md_mermaid_to_pdf.js ./example.md ./example.pdf

상대/절대 경로 모두 허용되며, 내부에서 자동으로 절대 경로로 변환됩니다.

동작 방식

  1. 입력 Markdown에서 ```mermaid 코드블록을 정규식으로 탐색합니다.

  2. 각 블록을 .out/diagram_<n>.mmd로 저장 후, npx -y @mermaid-js/mermaid-cli로 SVG 생성

  3. 원문 Markdown 내 Mermaid 블록을 해당 SVG의 이미지 링크로 치환

  4. 치환된 Markdown을 .out/<원본>.rendered.md로 저장

  5. npx -y md-to-pdf로 PDF 생성 시도 — 실패 시 pandoc으로 폴백

  6. 최종 PDF를 요청한 outputPath로 복사

중간 산출물은 입력 파일과 같은 디렉터리 하위의 .out/ 폴더에 생성됩니다.

샘플

example.md 파일(UTF-8)을 아래처럼 만들고 변환을 실행해보세요.

## Example

```mermaid
graph TD;
  A[Start] --> B{Is Mermaid Rendered?};
  B -- Yes --> C[Export to PDF];
  B -- No  --> D[Render via mmdc];
  D --> C;

## 문제 해결(트러블슈팅)
- **Chromium 다운로드 이슈**: `md-to-pdf`/`mermaid-cli`가 Puppeteer 기반으로 Chromium을 다운로드할 수 있습니다. 방화벽/프록시 환경에서는 네트워크 허용 필요.
  - 기존 설치된 브라우저 사용 시 `PUPPETEER_EXECUTABLE_PATH` 환경변수로 경로 지정 가능
- **`pandoc` 폴백 실패**: `pandoc`이 설치되어 있지 않거나 PATH에 없을 수 있습니다. macOS에서는 `brew install pandoc`으로 설치하세요.
- **권한 문제**: 출력 위치 디렉터리에 쓰기 권한이 필요합니다.

## 라이선스
MIT

Available Tools

1 tool
convert_markdown_to_pdfA

마크다운 파일(.md)을 PDF(.pdf)로 변환합니다. 마크다운 내부에 Mermaid 다이어그램이 포함되어 있어도 렌더링됩니다.

ParametersJSON Schema
NameRequiredDescriptionDefault
inputPathYesPDF로 변환할 원본 마크다운(.md) 파일의 전체 절대 경로. 예시: /Users/test/report.md
outputPathNo생성될 PDF 파일이 저장될 전체 절대 경로. 생략 시 원본 파일명에 .pdf 확장자를 붙여 같은 폴더에 저장됩니다.

TDQS

A3.5/5.0
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It mentions that Mermaid diagrams are rendered, which adds useful behavioral context beyond basic conversion. However, it doesn't disclose other traits like error handling, performance limits, or file size constraints, leaving gaps for a mutation tool.

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

Conciseness5/5

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

The description is concise and well-structured in two sentences: the first states the core function, and the second adds a key feature (Mermaid diagram support). Every sentence adds value without redundancy.

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?

For a tool with no annotations, no output schema, and 2 parameters, the description is minimal but covers the basic purpose and a notable feature. It's adequate for a simple conversion tool but lacks details on output behavior, error cases, or advanced usage, making it incomplete for full transparency.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema, such as format details or examples. Baseline 3 is appropriate when the schema handles the 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 function: converting Markdown files to PDF format. It specifies the input format (.md) and output format (.pdf), and mentions support for Mermaid diagrams. However, since there are no sibling tools, it doesn't need to differentiate from alternatives, so it doesn't reach the highest score.

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

Usage Guidelines3/5

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

The description implies usage when converting Markdown files with or without Mermaid diagrams to PDF, but it doesn't provide explicit guidance on when to use this tool versus alternatives or any prerequisites. With no sibling tools, this is adequate but lacks detailed context.

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

TDQS

A3.6/5.0
Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap between tools. The tool's purpose is clearly defined and distinct by default.

Naming Consistency5/5

Since there is only one tool, naming consistency is inherently perfect. The tool name 'convert_markdown_to_pdf' follows a clear verb_noun pattern, but consistency cannot be assessed across multiple tools.

Tool Count2/5

A single tool is generally too few for most server purposes, as it limits functionality and may indicate an incomplete surface. For a markdown-to-PDF conversion server, additional tools (e.g., for configuration, validation, or batch processing) would enhance coherence.

Completeness3/5

The tool covers the core conversion task well, including Mermaid diagram support. However, there are notable gaps, such as lack of tools for input validation, output customization (e.g., page settings), or handling multiple files, which could limit agent workflows.

Maintenance

ActivityInactive
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

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/polarnego/md-to-pdf-with-mermaid-mcp'

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