ferritex-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.
@@ -0,0 +1,37 @@
1
+ # Rust
2
+ /target/
3
+ **/*.rs.bk
4
+ *.pdb
5
+
6
+ # Python
7
+ __pycache__/
8
+ *.py[cod]
9
+ *.so
10
+ *.dylib
11
+ *.dll
12
+ .venv/
13
+ venv/
14
+ *.egg-info/
15
+ dist/
16
+ build/
17
+ .pytest_cache/
18
+ .mypy_cache/
19
+ .ruff_cache/
20
+ .hypothesis/
21
+ .coverage
22
+ htmlcov/
23
+ coverage.xml
24
+
25
+ # Editors
26
+ .vscode/
27
+ .idea/
28
+ *.swp
29
+ .DS_Store
30
+
31
+ # Benchmark and visual artefacts
32
+ /digest.txt
33
+ benchmarks/results.json
34
+ tests/visual/golden/*.tmp.png
35
+
36
+ # OS
37
+ Thumbs.db
@@ -0,0 +1,5 @@
1
+ # MCP server
2
+
3
+ Preserve the stdio transport and structured tool responses. Keep diagnostics
4
+ off protocol stdout. Respect the configured output root and don't describe
5
+ path checks as a sandbox. Test tools and registration in `tests/integration/test_mcp.py`.
@@ -0,0 +1 @@
1
+ @AGENTS.md
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rauhan Ahmed Siddiqui
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,122 @@
1
+ Metadata-Version: 2.5
2
+ Name: ferritex-mcp
3
+ Version: 0.1.0
4
+ Summary: Model Context Protocol server exposing FerriTeX LaTeX-to-PDF compilation to AI agents.
5
+ Project-URL: Homepage, https://github.com/RauhanAhmed/FerriTeX
6
+ Project-URL: Repository, https://github.com/RauhanAhmed/FerriTeX
7
+ Project-URL: Issues, https://github.com/RauhanAhmed/FerriTeX/issues
8
+ Author-email: Rauhan Ahmed Siddiqui <hello@rauhanahmed.in>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,ai,latex,mcp,pdf,typesetting
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
+ Classifier: Topic :: Text Processing :: Markup :: LaTeX
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: ferritex<0.2,>=0.1.0
23
+ Requires-Dist: mcp<3,>=1.2
24
+ Description-Content-Type: text/markdown
25
+
26
+ # ferritex-mcp
27
+
28
+ A [Model Context Protocol](https://modelcontextprotocol.io) server that exposes
29
+ [FerriTeX](https://github.com/RauhanAhmed/FerriTeX) to AI agents. An agent can turn LaTeX into a PDF
30
+ and validate LaTeX in a self-correction loop — without a TeX Live install and
31
+ without spawning subprocesses.
32
+
33
+ ## Install
34
+
35
+ ```bash
36
+ pip install ferritex-mcp
37
+ ```
38
+
39
+ This pulls in `ferritex`, the in-memory LaTeX-to-PDF engine.
40
+
41
+ ## Run
42
+
43
+ ```bash
44
+ ferritex-mcp
45
+ ```
46
+
47
+ Set `FERRITEX_MCP_OUTPUT_DIR` to a dedicated output directory. Relative
48
+ `output_path` values resolve under it; paths that resolve outside it return
49
+ `invalid_path`. If unset, paths are relative to the server's working directory
50
+ unless absolute. This is not a sandbox or an overwrite safeguard; use trusted
51
+ clients and restrict the server's filesystem permissions.
52
+
53
+ The server speaks MCP over stdio. Register it with your client, for example
54
+ Claude Desktop:
55
+
56
+ ```json
57
+ {
58
+ "mcpServers": {
59
+ "ferritex": {
60
+ "command": "ferritex-mcp"
61
+ }
62
+ }
63
+ }
64
+ ```
65
+
66
+ ## Tools
67
+
68
+ ### `compile_latex_to_pdf`
69
+
70
+ Compiles a LaTeX document and writes the PDF to disk.
71
+
72
+ | Argument | Type | Description |
73
+ | --- | --- | --- |
74
+ | `latex` | string | A complete LaTeX document |
75
+ | `output_path` | string | Where to write the PDF |
76
+ | `engine` | string | `"fast"`, `"full"`, or `"auto"` (default) |
77
+ | `margin` | string? | Uniform margin override, e.g. `"1in"` |
78
+ | `font_size` | string? | Base font size override, e.g. `"11pt"` |
79
+
80
+ Returns:
81
+
82
+ ```json
83
+ {
84
+ "success": true,
85
+ "output_path": "paper.pdf",
86
+ "engine_used": "fast",
87
+ "compile_time_ms": 6.2,
88
+ "page_count": 2,
89
+ "bytes": 18234,
90
+ "warnings": []
91
+ }
92
+ ```
93
+
94
+ On failure, `success` is `false` and `error` is one of `syntax`, `unsupported`,
95
+ `full_engine_missing`, `asset`, `compilation`, or `invalid_path`, with a human-readable message
96
+ and, for syntax errors, `line`, `column`, and `snippet`.
97
+
98
+ ### `validate_latex`
99
+
100
+ Dry-run validation: no PDF is written. Returns structured diagnostics so an
101
+ agent can fix and retry.
102
+
103
+ ```json
104
+ {
105
+ "valid": false,
106
+ "error": "syntax",
107
+ "message": "unclosed brace `{` (line 3, column 45)",
108
+ "line": 3,
109
+ "column": 45,
110
+ "snippet": "\\textbf{bold text"
111
+ }
112
+ ```
113
+
114
+ ## Why it matters
115
+
116
+ The fast engine lets agents validate and render supported documents without
117
+ starting a TeX executable on each revision. Validation checks fast-mode
118
+ compilation, not compatibility with every LaTeX package.
119
+
120
+ ## License
121
+
122
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,97 @@
1
+ # ferritex-mcp
2
+
3
+ A [Model Context Protocol](https://modelcontextprotocol.io) server that exposes
4
+ [FerriTeX](https://github.com/RauhanAhmed/FerriTeX) to AI agents. An agent can turn LaTeX into a PDF
5
+ and validate LaTeX in a self-correction loop — without a TeX Live install and
6
+ without spawning subprocesses.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ pip install ferritex-mcp
12
+ ```
13
+
14
+ This pulls in `ferritex`, the in-memory LaTeX-to-PDF engine.
15
+
16
+ ## Run
17
+
18
+ ```bash
19
+ ferritex-mcp
20
+ ```
21
+
22
+ Set `FERRITEX_MCP_OUTPUT_DIR` to a dedicated output directory. Relative
23
+ `output_path` values resolve under it; paths that resolve outside it return
24
+ `invalid_path`. If unset, paths are relative to the server's working directory
25
+ unless absolute. This is not a sandbox or an overwrite safeguard; use trusted
26
+ clients and restrict the server's filesystem permissions.
27
+
28
+ The server speaks MCP over stdio. Register it with your client, for example
29
+ Claude Desktop:
30
+
31
+ ```json
32
+ {
33
+ "mcpServers": {
34
+ "ferritex": {
35
+ "command": "ferritex-mcp"
36
+ }
37
+ }
38
+ }
39
+ ```
40
+
41
+ ## Tools
42
+
43
+ ### `compile_latex_to_pdf`
44
+
45
+ Compiles a LaTeX document and writes the PDF to disk.
46
+
47
+ | Argument | Type | Description |
48
+ | --- | --- | --- |
49
+ | `latex` | string | A complete LaTeX document |
50
+ | `output_path` | string | Where to write the PDF |
51
+ | `engine` | string | `"fast"`, `"full"`, or `"auto"` (default) |
52
+ | `margin` | string? | Uniform margin override, e.g. `"1in"` |
53
+ | `font_size` | string? | Base font size override, e.g. `"11pt"` |
54
+
55
+ Returns:
56
+
57
+ ```json
58
+ {
59
+ "success": true,
60
+ "output_path": "paper.pdf",
61
+ "engine_used": "fast",
62
+ "compile_time_ms": 6.2,
63
+ "page_count": 2,
64
+ "bytes": 18234,
65
+ "warnings": []
66
+ }
67
+ ```
68
+
69
+ On failure, `success` is `false` and `error` is one of `syntax`, `unsupported`,
70
+ `full_engine_missing`, `asset`, `compilation`, or `invalid_path`, with a human-readable message
71
+ and, for syntax errors, `line`, `column`, and `snippet`.
72
+
73
+ ### `validate_latex`
74
+
75
+ Dry-run validation: no PDF is written. Returns structured diagnostics so an
76
+ agent can fix and retry.
77
+
78
+ ```json
79
+ {
80
+ "valid": false,
81
+ "error": "syntax",
82
+ "message": "unclosed brace `{` (line 3, column 45)",
83
+ "line": 3,
84
+ "column": 45,
85
+ "snippet": "\\textbf{bold text"
86
+ }
87
+ ```
88
+
89
+ ## Why it matters
90
+
91
+ The fast engine lets agents validate and render supported documents without
92
+ starting a TeX executable on each revision. Validation checks fast-mode
93
+ compilation, not compatibility with every LaTeX package.
94
+
95
+ ## License
96
+
97
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "ferritex-mcp"
7
+ version = "0.1.0"
8
+ description = "Model Context Protocol server exposing FerriTeX LaTeX-to-PDF compilation to AI agents."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Rauhan Ahmed Siddiqui", email = "hello@rauhanahmed.in" }]
14
+ keywords = ["mcp", "latex", "pdf", "ai", "agents", "typesetting"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Programming Language :: Python :: 3.15",
24
+ "Topic :: Text Processing :: Markup :: LaTeX",
25
+ ]
26
+ dependencies = ["ferritex>=0.1.0,<0.2", "mcp>=1.2,<3"]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/RauhanAhmed/FerriTeX"
30
+ Repository = "https://github.com/RauhanAhmed/FerriTeX"
31
+ Issues = "https://github.com/RauhanAhmed/FerriTeX/issues"
32
+
33
+ [project.scripts]
34
+ ferritex-mcp = "ferritex_mcp.server:main"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/ferritex_mcp"]
@@ -0,0 +1,14 @@
1
+ """FerriTeX MCP server package."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .server import compile_latex_to_pdf, mcp, validate_latex
6
+
7
+ __all__ = ["compile_latex_to_pdf", "main", "mcp", "validate_latex"]
8
+
9
+
10
+ def main() -> None:
11
+ """Start the MCP server over stdio."""
12
+ from .server import main as run
13
+
14
+ run()
@@ -0,0 +1,151 @@
1
+ """FerriTeX MCP server.
2
+
3
+ Exposes FerriTeX as two deterministic Model Context Protocol tools so an AI
4
+ agent can produce a PDF from LaTeX without a TeX toolchain, and can validate
5
+ LaTeX in a tight self-correction loop.
6
+
7
+ Run over stdio:
8
+
9
+ ferritex-mcp
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import os
15
+ from pathlib import Path
16
+ from typing import Any
17
+
18
+ import ferritex
19
+
20
+
21
+ def _output_target(output_path: str) -> Path:
22
+ """Resolve output paths under the optional MCP output root."""
23
+ requested = Path(output_path)
24
+ configured = os.environ.get("FERRITEX_MCP_OUTPUT_DIR")
25
+ if not configured:
26
+ return requested
27
+ root = Path(configured).expanduser().resolve()
28
+ target = (root / requested).resolve() if not requested.is_absolute() else requested.resolve()
29
+ if not target.is_relative_to(root) or target == root:
30
+ raise ValueError("output_path must identify a file under FERRITEX_MCP_OUTPUT_DIR")
31
+ return target
32
+
33
+
34
+ try: # MCP SDK v2 (MCPServer) and v1 (FastMCP) expose the same decorator API.
35
+ from mcp.server.mcpserver import MCPServer as _Server
36
+ except ImportError: # pragma: no cover - older SDK
37
+ from mcp.server.fastmcp import FastMCP as _Server # type: ignore[no-redef]
38
+
39
+ SERVER_NAME = "ferritex"
40
+ SERVER_VERSION = ferritex.__version__
41
+
42
+ mcp = _Server(SERVER_NAME)
43
+
44
+
45
+ @mcp.tool()
46
+ def compile_latex_to_pdf(
47
+ latex: str,
48
+ output_path: str,
49
+ engine: str = "auto",
50
+ margin: str | None = None,
51
+ font_size: str | None = None,
52
+ ) -> dict[str, Any]:
53
+ """Compile LaTeX source to a PDF file on disk.
54
+
55
+ Args:
56
+ latex: A complete LaTeX document, from ``\\documentclass`` to
57
+ ``\\end{document}``.
58
+ output_path: Where to write the PDF, e.g. ``./paper.pdf``.
59
+ engine: ``"fast"``, ``"full"`` or ``"auto"`` (default). ``"auto"`` tries
60
+ the in-memory fast engine and falls back to the full engine when it
61
+ is installed.
62
+ margin: Optional uniform margin override, e.g. ``"1in"``.
63
+ font_size: Optional base font size override, e.g. ``"11pt"``.
64
+
65
+ Returns:
66
+ A JSON-serialisable payload with ``success``, ``output_path``,
67
+ ``engine_used``, ``compile_time_ms``, ``page_count`` and ``warnings``.
68
+ On failure, ``success`` is false and ``error`` describes the problem,
69
+ including line and column for syntax errors.
70
+ """
71
+ try:
72
+ target = _output_target(output_path)
73
+ except (ValueError, OSError, RuntimeError) as exc:
74
+ return {"success": False, "error": "invalid_path", "message": str(exc)}
75
+
76
+ try:
77
+ result = ferritex.compile_detailed(
78
+ latex,
79
+ engine, # type: ignore[arg-type]
80
+ margin=margin,
81
+ font_size=font_size,
82
+ debug=False,
83
+ )
84
+ except ferritex.LaTeXSyntaxError as exc:
85
+ return {
86
+ "success": False,
87
+ "error": "syntax",
88
+ "message": str(exc),
89
+ "line": getattr(exc, "line", None),
90
+ "column": getattr(exc, "column", None),
91
+ "snippet": getattr(exc, "snippet", None),
92
+ }
93
+ except ferritex.UnsupportedFeatureError as exc:
94
+ return {
95
+ "success": False,
96
+ "error": "unsupported",
97
+ "message": str(exc),
98
+ "feature": getattr(exc, "feature", None),
99
+ "hint": getattr(exc, "hint", None),
100
+ }
101
+ except ferritex.FullEngineNotInstalledError as exc:
102
+ return {"success": False, "error": "full_engine_missing", "message": str(exc)}
103
+ except ferritex.AssetNotFoundError as exc:
104
+ return {"success": False, "error": "asset", "message": str(exc)}
105
+ except ferritex.FerriTeXError as exc:
106
+ return {"success": False, "error": "compilation", "message": str(exc)}
107
+
108
+ try:
109
+ target.parent.mkdir(parents=True, exist_ok=True)
110
+ target.write_bytes(result.pdf)
111
+ except (ValueError, OSError) as exc:
112
+ return {"success": False, "error": "invalid_path", "message": str(exc)}
113
+
114
+ return {
115
+ "success": True,
116
+ "output_path": str(target),
117
+ "engine_used": result.engine_used,
118
+ "compile_time_ms": round(result.compile_time_ms, 3),
119
+ "page_count": result.page_count,
120
+ "bytes": len(result.pdf),
121
+ "warnings": list(result.warnings),
122
+ }
123
+
124
+
125
+ @mcp.tool()
126
+ def validate_latex(latex: str) -> dict[str, Any]:
127
+ """Check LaTeX without producing a PDF.
128
+
129
+ Use this to diagnose a document before compiling, or to verify a fix. It
130
+ never writes to disk and returns structured line/column diagnostics so an
131
+ agent can self-correct in a tight loop.
132
+
133
+ Args:
134
+ latex: The LaTeX document to check.
135
+
136
+ Returns:
137
+ A JSON-serialisable payload. ``valid`` is true when the document would
138
+ compile; otherwise ``error`` names the failure category and ``message``
139
+ explains it, with ``line``, ``column``, ``snippet``, ``feature`` and
140
+ ``hint`` where applicable.
141
+ """
142
+ return ferritex.validate(latex)
143
+
144
+
145
+ def main() -> None:
146
+ """Entry point for the ``ferritex-mcp`` console script."""
147
+ mcp.run(transport="stdio")
148
+
149
+
150
+ if __name__ == "__main__":
151
+ main()