typeset-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. typeset_mcp-0.1.0/.gitignore +23 -0
  2. typeset_mcp-0.1.0/LICENSE +21 -0
  3. typeset_mcp-0.1.0/PKG-INFO +160 -0
  4. typeset_mcp-0.1.0/README.md +129 -0
  5. typeset_mcp-0.1.0/pyproject.toml +59 -0
  6. typeset_mcp-0.1.0/src/typeset_mcp/__init__.py +3 -0
  7. typeset_mcp-0.1.0/src/typeset_mcp/__main__.py +87 -0
  8. typeset_mcp-0.1.0/src/typeset_mcp/audit.py +697 -0
  9. typeset_mcp-0.1.0/src/typeset_mcp/convertfigs.py +80 -0
  10. typeset_mcp-0.1.0/src/typeset_mcp/data/guides/authoring.md +119 -0
  11. typeset_mcp-0.1.0/src/typeset_mcp/data/guides/workflow.md +51 -0
  12. typeset_mcp-0.1.0/src/typeset_mcp/engine.py +140 -0
  13. typeset_mcp-0.1.0/src/typeset_mcp/errors.py +16 -0
  14. typeset_mcp-0.1.0/src/typeset_mcp/guides.py +35 -0
  15. typeset_mcp-0.1.0/src/typeset_mcp/imagefetch.py +157 -0
  16. typeset_mcp-0.1.0/src/typeset_mcp/imageinfo.py +79 -0
  17. typeset_mcp-0.1.0/src/typeset_mcp/imageresize.py +97 -0
  18. typeset_mcp-0.1.0/src/typeset_mcp/jsonio.py +13 -0
  19. typeset_mcp-0.1.0/src/typeset_mcp/layout.py +21 -0
  20. typeset_mcp-0.1.0/src/typeset_mcp/mdconvert.py +524 -0
  21. typeset_mcp-0.1.0/src/typeset_mcp/mdlint.py +548 -0
  22. typeset_mcp-0.1.0/src/typeset_mcp/measure.py +296 -0
  23. typeset_mcp-0.1.0/src/typeset_mcp/netguard.py +144 -0
  24. typeset_mcp-0.1.0/src/typeset_mcp/project.py +119 -0
  25. typeset_mcp-0.1.0/src/typeset_mcp/projectconfig.py +60 -0
  26. typeset_mcp-0.1.0/src/typeset_mcp/publish.py +61 -0
  27. typeset_mcp-0.1.0/src/typeset_mcp/render.py +77 -0
  28. typeset_mcp-0.1.0/src/typeset_mcp/server.py +233 -0
  29. typeset_mcp-0.1.0/src/typeset_mcp/template.py +106 -0
  30. typeset_mcp-0.1.0/src/typeset_mcp/workspace.py +39 -0
  31. typeset_mcp-0.1.0/tests/__init__.py +0 -0
  32. typeset_mcp-0.1.0/tests/cjkskip.py +48 -0
  33. typeset_mcp-0.1.0/tests/fixtures/beamer.md +21 -0
  34. typeset_mcp-0.1.0/tests/fixtures/broken.md +27 -0
  35. typeset_mcp-0.1.0/tests/fixtures/clean.md +29 -0
  36. typeset_mcp-0.1.0/tests/fixtures/report.md +22 -0
  37. typeset_mcp-0.1.0/tests/pngutil.py +25 -0
  38. typeset_mcp-0.1.0/tests/test_audit.py +162 -0
  39. typeset_mcp-0.1.0/tests/test_engine.py +119 -0
  40. typeset_mcp-0.1.0/tests/test_image_fit.py +46 -0
  41. typeset_mcp-0.1.0/tests/test_imagefetch.py +120 -0
  42. typeset_mcp-0.1.0/tests/test_imageinfo.py +52 -0
  43. typeset_mcp-0.1.0/tests/test_mdlint.py +64 -0
  44. typeset_mcp-0.1.0/tests/test_measure.py +82 -0
  45. typeset_mcp-0.1.0/tests/test_netguard.py +83 -0
  46. typeset_mcp-0.1.0/tests/test_phase5.py +119 -0
  47. typeset_mcp-0.1.0/tests/test_phase6.py +140 -0
  48. typeset_mcp-0.1.0/tests/test_publish.py +75 -0
  49. typeset_mcp-0.1.0/tests/test_render.py +80 -0
  50. typeset_mcp-0.1.0/tests/test_server.py +167 -0
  51. typeset_mcp-0.1.0/tests/test_settings.py +304 -0
  52. typeset_mcp-0.1.0/tests/test_theme.py +129 -0
@@ -0,0 +1,23 @@
1
+ # Python
2
+ .venv/
3
+ __pycache__/
4
+ *.pyc
5
+ dist/
6
+ *.egg-info/
7
+
8
+ # Build outputs and caches
9
+ out/
10
+ .tmp/
11
+ .typst/
12
+
13
+ # Generated intermediates
14
+ sample.typ
15
+ sample.body.typ
16
+
17
+ # typeset build artifacts and caches
18
+ *.build.typ
19
+ *.build.pdf
20
+ *.build.pages/
21
+ .typeset-cache/
22
+ .typeset-assets/
23
+ *.pages/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 typeset-mcp contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,160 @@
1
+ Metadata-Version: 2.5
2
+ Name: typeset-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server that typesets Markdown documents to PDF with the Typst engine (CJK-first)
5
+ Project-URL: Homepage, https://github.com/lhh010/typeset-mcp
6
+ Project-URL: Repository, https://github.com/lhh010/typeset-mcp
7
+ Project-URL: Issues, https://github.com/lhh010/typeset-mcp/issues
8
+ Project-URL: Changelog, https://github.com/lhh010/typeset-mcp/releases
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: chinese,cjk,markdown,mcp,model-context-protocol,pdf,typesetting,typst
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Text Processing :: Markup
21
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: mcp<3,>=2.3
24
+ Requires-Dist: md2typst>=0.3.7
25
+ Requires-Dist: pillow>=13.0.0
26
+ Requires-Dist: pypdf>=7.2.0
27
+ Requires-Dist: pypdfium2>=5.15.2
28
+ Requires-Dist: pyyaml>=6
29
+ Requires-Dist: typst>=0.15.2
30
+ Description-Content-Type: text/markdown
31
+
32
+ # typeset-mcp
33
+
34
+ A [Model Context Protocol](https://modelcontextprotocol.io) server that typesets Markdown documents into production-quality PDFs. Powered by the [Typst](https://typst.app) engine, with first-class CJK (Chinese, Japanese, Korean) support.
35
+
36
+ ```
37
+ Markdown → validate → measure → typeset → audit → render → publish → PDF
38
+ ```
39
+
40
+ ## Why
41
+
42
+ LLM agents can write Markdown, but \"make it look professional\" is where they fail: fonts don't embed, tables split awkwardly, math breaks, page numbers vanish. typeset-mcp gives agents (and you) a **structured pipeline** instead of a one-shot converter:
43
+
44
+ - **Validate before compiling** — catch broken links, unbalanced code fences, oversized images, and setext heading traps before wasting a compile
45
+ - **Measure before writing** — table widths, code line lengths, and image sizes compared against the text area, with a rough page count
46
+ - **Audit after building** — read the actual PDF content stream: embedded fonts (error), text layer (error), WCAG AA contrast, orphan headings, split tables, page-edge text
47
+ - **Render for visual review** — page PNGs returned inline so the agent (or a vision model) can inspect the output
48
+ - **Publish with fingerprint verification** — sha256-checked copy that fails loudly if the draft changed
49
+
50
+ ## Quick Start
51
+
52
+ ```bash
53
+ pip install typeset-mcp
54
+ ```
55
+
56
+ Add to your MCP client config (Claude Code, Cursor, Codex, etc.):
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "typeset": {
62
+ "command": "typeset-mcp",
63
+ "args": ["--root", "/path/to/your/workspace"]
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ Or with uv:
70
+
71
+ ```json
72
+ {
73
+ "mcpServers": {
74
+ "typeset": {
75
+ "command": "uv",
76
+ "args": ["run", "--with", "typeset-mcp", "typeset-mcp", "--root", "."]
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ ## Tools
83
+
84
+ | Tool | What it does |
85
+ |---|---|
86
+ | `validate_document` | Lint Markdown: frontmatter, headings, code fences, tables, images, links |
87
+ | `measure_document` | Pre-compile estimates: table/code/image widths vs text area |
88
+ | `typeset_document` | Compile one .md to a draft PDF (`.build.pdf`) |
89
+ | `typeset_project` | Build multi-chapter projects from a YAML manifest |
90
+ | `audit_document` | Read the built PDF's content stream for typography defects |
91
+ | `render_pages` | Render page PNGs for visual review |
92
+ | `publish_document` | Copy draft to final destination with fingerprint check |
93
+ | `inspect_document` | Report pages, fonts, metadata |
94
+ | `convert_figures` | Batch-convert PDF vector figures to PNG |
95
+ | `create_project` | Scaffold a project from a template (report / homework / slides) |
96
+ | `list_guides` / `read_guide` | Methodology guides for agents |
97
+
98
+ ## Themes
99
+
100
+ Four themes × six accent colors:
101
+
102
+ | Theme | Use case | Layout |
103
+ |---|---|---|
104
+ | `minimal` | Simple documents | A4, no cover |
105
+ | `report` | Reports, papers | Cover + outline + body |
106
+ | `homework` | Problem sets | Compact info header, no cover |
107
+ | `beamer` | Presentations | 16:9 slides, one `##` per slide |
108
+
109
+ ```yaml
110
+ ---
111
+ title: My Document
112
+ author: Your Name
113
+ theme: report
114
+ lang: zh
115
+ accent: blue
116
+ footer: Internal Draft
117
+ ---
118
+ ```
119
+
120
+ ## Features
121
+
122
+ - **CJK-first**: Chinese/Japanese/Korean text renders correctly out of the box (Microsoft YaHei + Times fallback)
123
+ - **Math**: LaTeX math via mitex — `$\sum_{i=1}^n x_i$`, `$$E = mc^2$$`, \boxed, align, matrices
124
+ - **Images**: PNG/JPG/GIF/WebP, absolute or relative paths, remote URLs (with SSRF sandbox), auto-constrained to page, auto-optimized (downsampled + JPEG when oversized)
125
+ - **Footnotes**: `[^label]` renders as page-bottom notes
126
+ - **Author notes**: `authorNotes` frontmatter key renders \\thanks-style footnotes on the cover
127
+ - **Mermaid diagrams**: rendered via the mmdr package
128
+ - **Multi-chapter books**: `typeset_project` joins chapters with one cover and outline
129
+ - **Stylesheets**: custom `.typ` files injected after the theme
130
+ - **Project config**: `typeset.yaml` for workspace-wide defaults
131
+ - **SSRF protection**: remote image fetching runs through a network sandbox (scheme allowlist, private IP blocking, connection pinning, redirect validation)
132
+
133
+ ## Guides
134
+
135
+ The server ships two methodology guides that MCP agents read before typesetting:
136
+
137
+ - **workflow** — the calibration philosophy: validate → measure → typeset → audit → render → publish, when to fix vs accept advisories
138
+ - **authoring** — writing habits: frontmatter keys, footnote syntax, image path rules, heading numbering, common pitfalls
139
+
140
+ ## Requirements
141
+
142
+ - Python ≥ 3.12
143
+ - Windows / macOS / Linux
144
+ - Fonts: Microsoft YaHei or any CJK font (for Chinese), Times New Roman (Latin)
145
+ - First compile downloads Typst packages (mitex for math, mmdr for mermaid) — subsequent compiles are offline
146
+
147
+ ## Development
148
+
149
+ ```bash
150
+ git clone https://github.com/lhh010/typeset-mcp
151
+ cd typeset-mcp
152
+ uv sync
153
+ uv run python -X utf8 -m unittest discover -s tests
154
+ ```
155
+
156
+ 93 tests, no network required (except first-time package downloads).
157
+
158
+ ## License
159
+
160
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,129 @@
1
+ # typeset-mcp
2
+
3
+ A [Model Context Protocol](https://modelcontextprotocol.io) server that typesets Markdown documents into production-quality PDFs. Powered by the [Typst](https://typst.app) engine, with first-class CJK (Chinese, Japanese, Korean) support.
4
+
5
+ ```
6
+ Markdown → validate → measure → typeset → audit → render → publish → PDF
7
+ ```
8
+
9
+ ## Why
10
+
11
+ LLM agents can write Markdown, but \"make it look professional\" is where they fail: fonts don't embed, tables split awkwardly, math breaks, page numbers vanish. typeset-mcp gives agents (and you) a **structured pipeline** instead of a one-shot converter:
12
+
13
+ - **Validate before compiling** — catch broken links, unbalanced code fences, oversized images, and setext heading traps before wasting a compile
14
+ - **Measure before writing** — table widths, code line lengths, and image sizes compared against the text area, with a rough page count
15
+ - **Audit after building** — read the actual PDF content stream: embedded fonts (error), text layer (error), WCAG AA contrast, orphan headings, split tables, page-edge text
16
+ - **Render for visual review** — page PNGs returned inline so the agent (or a vision model) can inspect the output
17
+ - **Publish with fingerprint verification** — sha256-checked copy that fails loudly if the draft changed
18
+
19
+ ## Quick Start
20
+
21
+ ```bash
22
+ pip install typeset-mcp
23
+ ```
24
+
25
+ Add to your MCP client config (Claude Code, Cursor, Codex, etc.):
26
+
27
+ ```json
28
+ {
29
+ "mcpServers": {
30
+ "typeset": {
31
+ "command": "typeset-mcp",
32
+ "args": ["--root", "/path/to/your/workspace"]
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ Or with uv:
39
+
40
+ ```json
41
+ {
42
+ "mcpServers": {
43
+ "typeset": {
44
+ "command": "uv",
45
+ "args": ["run", "--with", "typeset-mcp", "typeset-mcp", "--root", "."]
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ ## Tools
52
+
53
+ | Tool | What it does |
54
+ |---|---|
55
+ | `validate_document` | Lint Markdown: frontmatter, headings, code fences, tables, images, links |
56
+ | `measure_document` | Pre-compile estimates: table/code/image widths vs text area |
57
+ | `typeset_document` | Compile one .md to a draft PDF (`.build.pdf`) |
58
+ | `typeset_project` | Build multi-chapter projects from a YAML manifest |
59
+ | `audit_document` | Read the built PDF's content stream for typography defects |
60
+ | `render_pages` | Render page PNGs for visual review |
61
+ | `publish_document` | Copy draft to final destination with fingerprint check |
62
+ | `inspect_document` | Report pages, fonts, metadata |
63
+ | `convert_figures` | Batch-convert PDF vector figures to PNG |
64
+ | `create_project` | Scaffold a project from a template (report / homework / slides) |
65
+ | `list_guides` / `read_guide` | Methodology guides for agents |
66
+
67
+ ## Themes
68
+
69
+ Four themes × six accent colors:
70
+
71
+ | Theme | Use case | Layout |
72
+ |---|---|---|
73
+ | `minimal` | Simple documents | A4, no cover |
74
+ | `report` | Reports, papers | Cover + outline + body |
75
+ | `homework` | Problem sets | Compact info header, no cover |
76
+ | `beamer` | Presentations | 16:9 slides, one `##` per slide |
77
+
78
+ ```yaml
79
+ ---
80
+ title: My Document
81
+ author: Your Name
82
+ theme: report
83
+ lang: zh
84
+ accent: blue
85
+ footer: Internal Draft
86
+ ---
87
+ ```
88
+
89
+ ## Features
90
+
91
+ - **CJK-first**: Chinese/Japanese/Korean text renders correctly out of the box (Microsoft YaHei + Times fallback)
92
+ - **Math**: LaTeX math via mitex — `$\sum_{i=1}^n x_i$`, `$$E = mc^2$$`, \boxed, align, matrices
93
+ - **Images**: PNG/JPG/GIF/WebP, absolute or relative paths, remote URLs (with SSRF sandbox), auto-constrained to page, auto-optimized (downsampled + JPEG when oversized)
94
+ - **Footnotes**: `[^label]` renders as page-bottom notes
95
+ - **Author notes**: `authorNotes` frontmatter key renders \\thanks-style footnotes on the cover
96
+ - **Mermaid diagrams**: rendered via the mmdr package
97
+ - **Multi-chapter books**: `typeset_project` joins chapters with one cover and outline
98
+ - **Stylesheets**: custom `.typ` files injected after the theme
99
+ - **Project config**: `typeset.yaml` for workspace-wide defaults
100
+ - **SSRF protection**: remote image fetching runs through a network sandbox (scheme allowlist, private IP blocking, connection pinning, redirect validation)
101
+
102
+ ## Guides
103
+
104
+ The server ships two methodology guides that MCP agents read before typesetting:
105
+
106
+ - **workflow** — the calibration philosophy: validate → measure → typeset → audit → render → publish, when to fix vs accept advisories
107
+ - **authoring** — writing habits: frontmatter keys, footnote syntax, image path rules, heading numbering, common pitfalls
108
+
109
+ ## Requirements
110
+
111
+ - Python ≥ 3.12
112
+ - Windows / macOS / Linux
113
+ - Fonts: Microsoft YaHei or any CJK font (for Chinese), Times New Roman (Latin)
114
+ - First compile downloads Typst packages (mitex for math, mmdr for mermaid) — subsequent compiles are offline
115
+
116
+ ## Development
117
+
118
+ ```bash
119
+ git clone https://github.com/lhh010/typeset-mcp
120
+ cd typeset-mcp
121
+ uv sync
122
+ uv run python -X utf8 -m unittest discover -s tests
123
+ ```
124
+
125
+ 93 tests, no network required (except first-time package downloads).
126
+
127
+ ## License
128
+
129
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,59 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "typeset-mcp"
7
+ version = "0.1.0"
8
+ description = "MCP server that typesets Markdown documents to PDF with the Typst engine (CJK-first)"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.12"
13
+ keywords = [
14
+ "mcp",
15
+ "model-context-protocol",
16
+ "markdown",
17
+ "pdf",
18
+ "typst",
19
+ "typesetting",
20
+ "cjk",
21
+ "chinese",
22
+ ]
23
+ classifiers = [
24
+ "Development Status :: 4 - Beta",
25
+ "Intended Audience :: Developers",
26
+ "Intended Audience :: Education",
27
+ "License :: OSI Approved :: MIT License",
28
+ "Operating System :: OS Independent",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Programming Language :: Python :: 3.13",
32
+ "Topic :: Text Processing :: Markup",
33
+ "Topic :: Text Processing :: Markup :: Markdown",
34
+ ]
35
+ dependencies = [
36
+ "mcp>=2.3,<3",
37
+ "md2typst>=0.3.7",
38
+ "pyyaml>=6",
39
+ "pypdf>=7.2.0",
40
+ "typst>=0.15.2",
41
+ "pypdfium2>=5.15.2",
42
+ "pillow>=13.0.0",
43
+ ]
44
+
45
+ [project.urls]
46
+ Homepage = "https://github.com/lhh010/typeset-mcp"
47
+ Repository = "https://github.com/lhh010/typeset-mcp"
48
+ Issues = "https://github.com/lhh010/typeset-mcp/issues"
49
+ Changelog = "https://github.com/lhh010/typeset-mcp/releases"
50
+
51
+ [project.scripts]
52
+ typeset-mcp = "typeset_mcp.__main__:main"
53
+
54
+ [tool.hatch.build.targets.wheel]
55
+ packages = ["src/typeset_mcp"]
56
+ artifacts = ["LICENSE"]
57
+
58
+ [tool.hatch.build.targets.sdist]
59
+ include = ["/src", "/tests", "/README.md", "/LICENSE", "/pyproject.toml"]
@@ -0,0 +1,3 @@
1
+ """typeset-mcp: Markdown to PDF typesetting MCP server (Typst engine, CJK-first)."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,87 @@
1
+ """Console entry point for the typeset MCP server."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import os
7
+ from pathlib import Path
8
+
9
+ from . import __version__
10
+ from .workspace import configure
11
+
12
+
13
+ def parser() -> argparse.ArgumentParser:
14
+ root = argparse.ArgumentParser(
15
+ prog="typeset-mcp",
16
+ description="MCP server that typesets Markdown documents to PDF (Typst engine).",
17
+ )
18
+ root.add_argument(
19
+ "--transport",
20
+ choices=("stdio", "http"),
21
+ default="stdio",
22
+ help="stdio is the default local transport; http serves Streamable HTTP on 127.0.0.1.",
23
+ )
24
+ root.add_argument("--host", default="127.0.0.1", help="HTTP bind address; keep the loopback default.")
25
+ root.add_argument("--port", type=int, default=8766, help="HTTP port.")
26
+ root.add_argument(
27
+ "--root",
28
+ action="append",
29
+ default=[],
30
+ metavar="PATH",
31
+ help="Workspace root for relative paths. Repeatable.",
32
+ )
33
+ root.add_argument(
34
+ "--restrict-paths",
35
+ action="store_true",
36
+ help="Reject paths outside the workspace roots. Always enabled for HTTP.",
37
+ )
38
+ root.add_argument(
39
+ "--cache-dir",
40
+ metavar="PATH",
41
+ default=None,
42
+ help="Typst package cache (default: <first root>/.typeset-cache).",
43
+ )
44
+ root.add_argument(
45
+ "--allow-private-images",
46
+ action="store_true",
47
+ help="Let image localization fetch private/link-local addresses (trusted intranet). Blocked by default.",
48
+ )
49
+ root.add_argument("--version", action="version", version=f"typeset-mcp {__version__}")
50
+ return root
51
+
52
+
53
+ def main(argv: list[str] | None = None) -> int:
54
+ arguments = parser().parse_args(argv)
55
+ roots = tuple(
56
+ Path(value).expanduser()
57
+ for value in (
58
+ arguments.root
59
+ or [os.environ.get("CLAUDE_PROJECT_DIR") or Path.cwd()]
60
+ )
61
+ )
62
+ configure(roots, restrict=arguments.restrict_paths or arguments.transport == "http")
63
+
64
+ from .engine import set_cache_dir
65
+
66
+ cache = (
67
+ Path(arguments.cache_dir).expanduser()
68
+ if arguments.cache_dir
69
+ else roots[0] / ".typeset-cache"
70
+ )
71
+ set_cache_dir(cache)
72
+
73
+ from .imagefetch import configure_fetch
74
+
75
+ configure_fetch(arguments.allow_private_images)
76
+
77
+ from .server import mcp
78
+
79
+ if arguments.transport == "http":
80
+ mcp.run(transport="streamable-http", host=arguments.host, port=arguments.port)
81
+ else:
82
+ mcp.run()
83
+ return 0
84
+
85
+
86
+ if __name__ == "__main__":
87
+ raise SystemExit(main())