lightpdf-aipdf-mcp 0.1.97__py3-none-any.whl → 0.1.99__py3-none-any.whl

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.
@@ -11,8 +11,8 @@ import httpx
11
11
  @dataclass
12
12
  class BaseResult:
13
13
  """基础结果数据类"""
14
- success: bool
15
- file_path: str
14
+ success: bool = False
15
+ file_path: Optional[str] = None
16
16
  error_message: Optional[str] = None
17
17
  download_url: Optional[str] = None
18
18
  original_name: Optional[str] = None
@@ -0,0 +1,56 @@
1
+ """根据LaTeX内容创建PDF文件的接口(未实现具体逻辑)"""
2
+ from typing import Optional
3
+ import os
4
+ import uuid
5
+ from .common import Logger, FileHandler
6
+ from .editor import Editor, EditResult, EditType
7
+
8
+ async def create_pdf_from_latex(latex_content: str, output_path: Optional[str] = None, logger: Optional[Logger] = None):
9
+ """
10
+ 根据LaTeX内容创建PDF文件。
11
+
12
+ 参数:
13
+ latex_content (str): LaTeX源内容。
14
+ output_path (Optional[str]): 可选,输出PDF文件路径。
15
+ logger (Optional[Logger]): 日志对象。
16
+ 返回:
17
+ dict: 包含生成结果的信息(如成功与否、PDF路径、错误信息等)。
18
+ """
19
+ tex_path = None
20
+ try:
21
+ # 1. 保存latex_content为本地.tex文件
22
+ try:
23
+ temp_dir = "./tmp"
24
+ os.makedirs(temp_dir, exist_ok=True)
25
+ tex_filename = f"latex_{uuid.uuid4().hex}.tex"
26
+ tex_path = os.path.join(temp_dir, tex_filename)
27
+ with open(tex_path, "w", encoding="utf-8") as f:
28
+ f.write(latex_content)
29
+ except Exception as e:
30
+ return EditResult(
31
+ error_message=f"保存LaTeX内容失败: {e}"
32
+ )
33
+
34
+ # 2. 调用Editor.edit_pdf并传递oss://tex2pdf参数生成PDF
35
+ try:
36
+ # 构造Logger和FileHandler
37
+ file_handler = FileHandler(logger)
38
+ editor = Editor(logger, file_handler)
39
+
40
+ # extra_params按txt转pdf方式
41
+ extra_params = {"pages": '[{"url": "oss://tex2pdf", "oss_file": ""}]'}
42
+
43
+ # 这里original_name可用tex_filename
44
+ result: EditResult = await editor.edit_pdf(tex_path, edit_type=EditType.EDIT, extra_params=extra_params, original_name=tex_filename)
45
+ # 3. 返回结果
46
+ return result
47
+ except Exception as e:
48
+ return EditResult(
49
+ error_message=f"PDF生成失败: {e}"
50
+ )
51
+ finally:
52
+ if tex_path and os.path.exists(tex_path):
53
+ try:
54
+ os.remove(tex_path)
55
+ except Exception:
56
+ pass
@@ -19,8 +19,8 @@ class EditType(str, Enum):
19
19
  ENCRYPT = "protect" # 加密PDF
20
20
  DECRYPT = "unlock" # 解密PDF
21
21
  ADD_WATERMARK = "watermark" # 添加水印
22
- REMOVE_MARGIN = "edit" # 去除白边
23
22
  EXTRACT_IMAGE = "extract" # 提取图片
23
+ EDIT = "edit" # 编辑操作
24
24
 
25
25
  @dataclass
26
26
  class EditResult(BaseResult):
@@ -430,7 +430,7 @@ class Editor(BaseApiClient):
430
430
  }
431
431
 
432
432
  # 调用edit_pdf方法处理API请求
433
- return await self.edit_pdf(file_path, EditType.REMOVE_MARGIN, extra_params, password, original_name)
433
+ return await self.edit_pdf(file_path, EditType.EDIT, extra_params, password, original_name)
434
434
 
435
435
  async def extract_images(self, file_path: str, format: str = "png", password: Optional[str] = None, original_name: Optional[str] = None) -> EditResult:
436
436
  """从PDF文件中提取图片
@@ -18,7 +18,7 @@ import mcp.types as types
18
18
  # 本地导入
19
19
  from .common import BaseResult, Logger, FileHandler
20
20
  from .converter import Converter, ConversionResult
21
- from .editor import Editor, EditResult
21
+ from .editor import Editor, EditResult, EditType
22
22
  from .translator import Translator, TranslateResult
23
23
 
24
24
  # 加载环境变量
@@ -347,7 +347,7 @@ async def process_tool_call(
347
347
  logger,
348
348
  lambda file_path, password, original_name: editor.edit_pdf(
349
349
  file_path,
350
- edit_type="edit",
350
+ edit_type=EditType.EDIT,
351
351
  extra_params={"pages": [{"url": "oss://pdf2md", "oss_file": ""}]},
352
352
  password=password,
353
353
  original_name=original_name
@@ -363,7 +363,7 @@ async def process_tool_call(
363
363
  lambda file_path, password, original_name: (
364
364
  editor.edit_pdf(
365
365
  file_path,
366
- edit_type="edit",
366
+ edit_type=EditType.EDIT,
367
367
  extra_params={"pages": [{"url": "oss://txt2pdf", "oss_file": ""}]},
368
368
  password=password,
369
369
  original_name=original_name
@@ -1140,6 +1140,20 @@ async def handle_list_tools() -> list[types.Tool]:
1140
1140
  "required": ["files"]
1141
1141
  }
1142
1142
  ),
1143
+ types.Tool(
1144
+ name="create_pdf",
1145
+ description="Create a PDF file from LaTeX content. Provide LaTeX source code and get a compiled PDF file as output.",
1146
+ inputSchema={
1147
+ "type": "object",
1148
+ "properties": {
1149
+ "latex_content": {
1150
+ "type": "string",
1151
+ "description": "The LaTeX source content to be compiled into a PDF file."
1152
+ }
1153
+ },
1154
+ "required": ["latex_content"]
1155
+ }
1156
+ ),
1143
1157
  ]
1144
1158
 
1145
1159
  @app.call_tool()
@@ -1341,6 +1355,27 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
1341
1355
  # 调用通用处理函数
1342
1356
  result = await process_tool_call(logger, file_objects, operation_config)
1343
1357
  return [result]
1358
+
1359
+ elif name == "create_pdf":
1360
+ from .create_pdf import create_pdf_from_latex
1361
+ latex_content = arguments.get("latex_content")
1362
+ if not latex_content:
1363
+ error_msg = "latex_content参数不能为空"
1364
+ await logger.error(error_msg)
1365
+ return [types.TextContent(type="text", text=error_msg)]
1366
+
1367
+ # 调用create_pdf_from_latex接口(未实现具体逻辑)
1368
+ result = await create_pdf_from_latex(latex_content, logger=logger)
1369
+ # 构建结果报告
1370
+ report_msg = generate_result_report(
1371
+ [result]
1372
+ )
1373
+ # 如果失败,记录错误
1374
+ if not result.success:
1375
+ await logger.error(report_msg)
1376
+
1377
+ return [types.TextContent(type="text", text=report_msg)]
1378
+
1344
1379
  else:
1345
1380
  error_msg = f"未知工具: {name}"
1346
1381
  await logger.error(error_msg, ValueError)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lightpdf-aipdf-mcp
3
- Version: 0.1.97
3
+ Version: 0.1.99
4
4
  Summary: MCP Server for LightPDF AI-PDF
5
5
  Author: LightPDF Team
6
6
  License: Proprietary
@@ -0,0 +1,11 @@
1
+ lightpdf_aipdf_mcp/__init__.py,sha256=PPnAgpvJLYLVOTxnHDmJAulFnHJD6wuTwS6tRGjqq6s,141
2
+ lightpdf_aipdf_mcp/common.py,sha256=PhTf7Zg6mEgn1rTmJDHotXp-4xb2gWFf-Dy_t25qNdY,6660
3
+ lightpdf_aipdf_mcp/converter.py,sha256=Q_4vXcysqcJ7w6bUKY9JhoBDlCRcAJSpW7p0jh5qekU,16120
4
+ lightpdf_aipdf_mcp/create_pdf.py,sha256=SULJRKFghbQy7VP9GPxS6auy5nMxBN61SxgDr-Wr_lA,2120
5
+ lightpdf_aipdf_mcp/editor.py,sha256=vPaahaAV6pDZi_eheRGSgHzfZxc6ZqQyxHDgsNfdgjQ,29899
6
+ lightpdf_aipdf_mcp/server.py,sha256=LVzQoDvliyvAQVISIoypc8PYyK4oQZU6IhaSRbk7jA8,64112
7
+ lightpdf_aipdf_mcp/translator.py,sha256=NbFDz-mZSD4qCNQVyV0W_0x6xXwbqs_7FiBU13JAxZs,4243
8
+ lightpdf_aipdf_mcp-0.1.99.dist-info/METADATA,sha256=OKX3x6wiU3S5IkRd03x2z-r5sZFkBZIV2GbYRYbHz8A,8119
9
+ lightpdf_aipdf_mcp-0.1.99.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ lightpdf_aipdf_mcp-0.1.99.dist-info/entry_points.txt,sha256=X7TGUe52N4sYH-tYt0YUGApeJgw-efQlZA6uAZmlmr4,63
11
+ lightpdf_aipdf_mcp-0.1.99.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- lightpdf_aipdf_mcp/__init__.py,sha256=PPnAgpvJLYLVOTxnHDmJAulFnHJD6wuTwS6tRGjqq6s,141
2
- lightpdf_aipdf_mcp/common.py,sha256=_UO1f6S9Qr_3k6u5iBpdVDpvTK5U-tHEpu9KsDGqV8Y,6635
3
- lightpdf_aipdf_mcp/converter.py,sha256=Q_4vXcysqcJ7w6bUKY9JhoBDlCRcAJSpW7p0jh5qekU,16120
4
- lightpdf_aipdf_mcp/editor.py,sha256=CjxcZh-zDmb9UjHYj5spfx9HK8j-_voZ3_nmdwWGM8c,29908
5
- lightpdf_aipdf_mcp/server.py,sha256=40rntJFuBdTj1KMzTYzBL-FuZabmTOpb1_RC-ccJ_k0,62746
6
- lightpdf_aipdf_mcp/translator.py,sha256=NbFDz-mZSD4qCNQVyV0W_0x6xXwbqs_7FiBU13JAxZs,4243
7
- lightpdf_aipdf_mcp-0.1.97.dist-info/METADATA,sha256=QN959AXqlGsLIzKv_m60Q6-msz9Twzpgcf7daTs3cHU,8119
8
- lightpdf_aipdf_mcp-0.1.97.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
- lightpdf_aipdf_mcp-0.1.97.dist-info/entry_points.txt,sha256=X7TGUe52N4sYH-tYt0YUGApeJgw-efQlZA6uAZmlmr4,63
10
- lightpdf_aipdf_mcp-0.1.97.dist-info/RECORD,,