GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: MCP render_page_png 도구 추가 (8 도구) + ImageContent 출고 · DanMeon/rhwp-python@d9880d9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/roadmap/v0.6.0
    • png-vlm-render.md
  • python/rhwp/mcp
    • server.py
    • tools.py
  • uv.lock
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/roadmap/v0.6.0/png-vlm-render.md‎

Copy file name to clipboardExpand all lines: docs/roadmap/v0.6.0/png-vlm-render.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ v0.4.0 view 렌더러 (Markdown / HTML) 와 v0.5.0 MCP server 는 *텍스트*
3636
- **AC-2** — 동일 fixture 의 `Document.render_all_png()` 결과 길이 == `Document.page_count` (페이지 수 invariant)
3737
- **AC-3** — `Document.render_png(0, scale=2.0)` 결과의 픽셀 너비 ≈ `Document.render_png(0, scale=1.0)` 결과의 2배 (image lib 디코드 후 검증 — 상류 raster_dimension 의 `value * scale` 산식 회귀 가드)
3838
- **AC-4** — `Document.render_png(0, max_pixels=1)` 호출이 `ValueError` (메시지에 `"pixel count out of range"` 포함) 로 fail — 상류 raster_dimension 의 max_pixels 가드 wire-through 검증
39-
- **AC-5** — MCP `render_page_png(path, 0)` 도구 호출이 fastmcp `ImageContent` 인스턴스 반환 (속성 `mime_type == "image/png"`, `data` 가 base64-decoded PNG magic 일치). `outputSchema` 에 `ImageContent` `$ref` 노출
39+
- **AC-5** — MCP `render_page_png(path, 0)` 도구 호출이 fastmcp `ImageContent` 인스턴스 반환 (속성 `mimeType == "image/png"`, `data` 가 base64-decoded PNG magic 일치). `outputSchema` 에 `ImageContent` `$ref` 노출
4040
- **AC-6** — `arender_png(path, 0)` async 호출이 정상 PNG bytes 반환. `_Document` 인스턴스가 thread 경계를 넘지 않음 — `aparse` + sync `render_png` 구성 검증 (panic 미발생)
4141
- **AC-7** — `Document.export_png(out_dir)` 가 `Document.page_count` 만큼 파일 생성, 각 파일 첫 8 byte PNG magic 일치, 반환 경로 리스트 길이 == 파일 수
4242
- **AC-8** — `Document.render_pdf` / `render_svg` / `to_ir` 등 v0.5.x 표면의 모든 기존 회귀 가드가 그대로 통과 (additive 보장)
Collapse file

‎python/rhwp/mcp/server.py‎

Copy file name to clipboardExpand all lines: python/rhwp/mcp/server.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919

2020
def build_server() -> FastMCP:
21-
"""새 ``FastMCP`` 인스턴스를 만들고 도구 7 종을 등록해 반환.
21+
"""새 ``FastMCP`` 인스턴스를 만들고 도구 8 종을 등록해 반환.
2222
2323
테스트가 ``mcp.list_tools()`` / ``mcp.call_tool(name, args)`` 를 in-process
2424
호출할 수 있도록 build 단계를 함수로 분리 — 모듈 import 부수 효과 없이
2525
fresh 인스턴스 획득.
2626
"""
2727
server = FastMCP("rhwp-mcp")
28-
# ^ S1 코어 4 + S2 view 2 + S3 chunks 1 = 7. mcp.md AC-2 의 GA 기준 도구 수.
28+
# ^ S1 코어 4 + S2 view 2 + S3 chunks 1 + v0.6.0 PNG 1 = 8.
2929
# fastmcp v3 의 ``server.tool(fn)`` 은 데코레이터 호출 형태 — 동일 인스턴스에
3030
# 여러 도구를 program 적으로 등록할 때 같은 클로저 충돌 없이 안전.
3131
server.tool(tools.parse_hwp_summary)
@@ -37,6 +37,8 @@ def build_server() -> FastMCP:
3737
# ^ chunks 는 langchain-text-splitters 런타임 extras gate — 등록은 무조건,
3838
# 호출 시점에 ImportError → fastmcp ToolError → MCP isError=True (AC-7).
3939
server.tool(tools.chunks)
40+
# ^ v0.6.0: VLM 시각 입력 — fastmcp ImageContent 반환 (base64 + image/png).
41+
server.tool(tools.render_page_png)
4042
return server
4143

4244

Collapse file

‎python/rhwp/mcp/tools.py‎

Copy file name to clipboardExpand all lines: python/rhwp/mcp/tools.py
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
- S1 — `parse_hwp_summary` / `extract_text` / `get_ir` / `iter_blocks` (코어 4)
99
- S2 — `to_markdown` / `to_html` (v0.4.0 view API thin wrapper)
1010
- S3 — `chunks` (RAG 청킹 — langchain-text-splitters 런타임 extras gate)
11+
- v0.6.0 — `render_page_png` (페이지 PNG → fastmcp ImageContent — VLM 입력)
1112
"""
1213

14+
import base64
1315
from typing import Any, Literal
1416

17+
from mcp.types import ImageContent
1518
from pydantic import BaseModel, ConfigDict, Field
1619

1720
import rhwp
@@ -232,3 +235,40 @@ def chunks(
232235
splitter = RecursiveCharacterTextSplitter(chunk_size=size, chunk_overlap=overlap)
233236
split_docs = splitter.split_documents(docs)
234237
return [ChunkRecord(page_content=d.page_content, metadata=d.metadata) for d in split_docs]
238+
239+
240+
def render_page_png(
241+
path: str,
242+
page: int,
243+
scale: float = 1.0,
244+
max_pixels: int | None = None,
245+
) -> ImageContent:
246+
"""HWP 또는 HWPX 의 특정 페이지를 PNG 로 렌더해 fastmcp ``ImageContent`` 반환.
247+
248+
VLM (Vision-Language Model — Claude / GPT-4V / Gemini 등) 의 시각 입력 1차
249+
시민. fastmcp v3 의 ``ImageContent`` 표준 (base64 + ``mimeType="image/png"``)
250+
으로 출고 → MCP client (Claude Desktop / Cline / Cursor) 가 LLM 메시지의
251+
``image`` content block 으로 자동 wire — bytes 반환 후 클라이언트 측 base64
252+
변환은 비결정 dict 가 되므로 거부.
253+
254+
A4 페이지 PNG 가 약 100-500 KB → base64 약 130-660 KB. stdio MCP transport
255+
의 JSON-RPC 메시지 크기 제한과 충돌 가능성 — 큰 페이지 / 다수 페이지는
256+
``--transport streamable-http`` 권장.
257+
258+
Args:
259+
path: HWP 또는 HWPX 파일 경로.
260+
page: 0-based 페이지 인덱스.
261+
scale: 페이지 크기 배율 (기본 1.0). VLM 입력 권장 값은 1.0-2.0 — 너무
262+
크면 LLM context 비용이 급증.
263+
max_pixels: DoS 방어용 픽셀 상한. 미지정 시 상류 default
264+
67_108_864 (= 8192 × 8192).
265+
266+
Returns:
267+
``ImageContent(type="image", data=base64-encoded PNG, mimeType="image/png")``.
268+
"""
269+
png_bytes = rhwp.parse(path).render_png(page, scale=scale, max_pixels=max_pixels)
270+
return ImageContent(
271+
type="image",
272+
data=base64.b64encode(png_bytes).decode("ascii"),
273+
mimeType="image/png",
274+
)
Collapse file

‎uv.lock‎

Copy file name to clipboardExpand all lines: uv.lock
+1-5Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.