lightpdf-aipdf-mcp 0.1.84__py3-none-any.whl → 0.1.85__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.
- lightpdf_aipdf_mcp/server.py +109 -36
- {lightpdf_aipdf_mcp-0.1.84.dist-info → lightpdf_aipdf_mcp-0.1.85.dist-info}/METADATA +1 -1
- {lightpdf_aipdf_mcp-0.1.84.dist-info → lightpdf_aipdf_mcp-0.1.85.dist-info}/RECORD +5 -5
- {lightpdf_aipdf_mcp-0.1.84.dist-info → lightpdf_aipdf_mcp-0.1.85.dist-info}/WHEEL +0 -0
- {lightpdf_aipdf_mcp-0.1.84.dist-info → lightpdf_aipdf_mcp-0.1.85.dist-info}/entry_points.txt +0 -0
lightpdf_aipdf_mcp/server.py
CHANGED
@@ -265,11 +265,11 @@ async def process_tool_call(
|
|
265
265
|
types.TextContent: 包含处理结果的文本内容
|
266
266
|
"""
|
267
267
|
file_handler = FileHandler(logger)
|
268
|
+
editor = Editor(logger, file_handler)
|
268
269
|
|
269
270
|
# 根据操作类型选择不同的处理逻辑
|
270
271
|
if operation_config.get("is_edit_operation"):
|
271
272
|
# 编辑操作
|
272
|
-
editor = Editor(logger, file_handler)
|
273
273
|
edit_type = operation_config.get("edit_type", "")
|
274
274
|
extra_params = operation_config.get("extra_params")
|
275
275
|
|
@@ -305,35 +305,67 @@ async def process_tool_call(
|
|
305
305
|
converter = Converter(logger, file_handler)
|
306
306
|
format = operation_config.get("format", "")
|
307
307
|
extra_params = operation_config.get("extra_params")
|
308
|
-
|
309
|
-
#
|
310
|
-
if format == "
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
308
|
+
|
309
|
+
# 新增:特殊处理PDF转Markdown和TXT转PDF
|
310
|
+
if format == "md":
|
311
|
+
# PDF转Markdown,调用Editor.edit_pdf,传递oss://pdf2md
|
312
|
+
results = await process_batch_files(
|
313
|
+
file_objects,
|
314
|
+
logger,
|
315
|
+
lambda file_path, password, original_name: editor.edit_pdf(
|
316
|
+
file_path,
|
317
|
+
edit_type="edit",
|
318
|
+
extra_params={"pages": [{"url": "oss://pdf2md", "oss_file": ""}]},
|
319
|
+
password=password,
|
320
|
+
original_name=original_name
|
321
|
+
),
|
322
|
+
"PDF转Markdown"
|
323
|
+
)
|
324
|
+
report_msg = generate_result_report(results)
|
325
|
+
elif format == "pdf":
|
326
|
+
# 只调用一次process_batch_files,在lambda里分流
|
327
|
+
results = await process_batch_files(
|
328
|
+
file_objects,
|
329
|
+
logger,
|
330
|
+
lambda file_path, password, original_name: (
|
331
|
+
editor.edit_pdf(
|
332
|
+
file_path,
|
333
|
+
edit_type="edit",
|
334
|
+
extra_params={"pages": [{"url": "oss://txt2pdf", "oss_file": ""}]},
|
335
|
+
password=password,
|
336
|
+
original_name=original_name
|
337
|
+
) if file_handler.get_file_extension(file_path) == ".txt" else process_conversion_file(
|
338
|
+
file_path, format, converter, extra_params, password, original_name
|
339
|
+
)
|
340
|
+
),
|
341
|
+
f"转换为 {format} 格式"
|
342
|
+
)
|
343
|
+
report_msg = generate_result_report(results)
|
319
344
|
else:
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
345
|
+
# 获取操作描述
|
346
|
+
if format == "doc-repair":
|
347
|
+
operation_desc = "去除水印"
|
348
|
+
elif format == "number-pdf":
|
349
|
+
operation_desc = "添加页码"
|
350
|
+
elif format == "flatten-pdf":
|
351
|
+
operation_desc = "展平PDF"
|
352
|
+
else:
|
353
|
+
operation_desc = f"转换为 {format} 格式"
|
354
|
+
|
355
|
+
# 处理文件
|
356
|
+
results = await process_batch_files(
|
357
|
+
file_objects,
|
358
|
+
logger,
|
359
|
+
lambda file_path, password, original_name: process_conversion_file(
|
360
|
+
file_path, format, converter, extra_params, password, original_name
|
361
|
+
),
|
362
|
+
operation_desc
|
363
|
+
)
|
364
|
+
|
365
|
+
# 生成报告
|
366
|
+
report_msg = generate_result_report(
|
367
|
+
results
|
368
|
+
)
|
337
369
|
|
338
370
|
# 如果全部失败,记录错误
|
339
371
|
if not any(r.success for r in results):
|
@@ -381,8 +413,8 @@ async def handle_list_tools() -> list[types.Tool]:
|
|
381
413
|
},
|
382
414
|
"format": {
|
383
415
|
"type": "string",
|
384
|
-
"description": "Target format",
|
385
|
-
"enum": ["pdf", "docx", "xlsx", "pptx", "jpg", "jpeg", "png", "html", "txt", "csv"]
|
416
|
+
"description": "Target format. PDF can be converted to DOCX, XLSX, PPTX, images (including long images), HTML, TXT (text extraction), CSV, or Markdown (md). Other formats (DOCX, XLSX, PPTX, images, TXT) can be converted to PDF.",
|
417
|
+
"enum": ["pdf", "docx", "xlsx", "pptx", "jpg", "jpeg", "png", "html", "txt", "csv", "md"]
|
386
418
|
},
|
387
419
|
"merge_all": {
|
388
420
|
"type": "integer",
|
@@ -889,6 +921,38 @@ async def handle_list_tools() -> list[types.Tool]:
|
|
889
921
|
},
|
890
922
|
"required": ["files"]
|
891
923
|
}
|
924
|
+
),
|
925
|
+
types.Tool(
|
926
|
+
name="restrict_printing",
|
927
|
+
description="Restrict PDF printing permission. This tool will set the PDF so that printing is not allowed.",
|
928
|
+
inputSchema={
|
929
|
+
"type": "object",
|
930
|
+
"properties": {
|
931
|
+
"files": {
|
932
|
+
"type": "array",
|
933
|
+
"items": {
|
934
|
+
"type": "object",
|
935
|
+
"properties": {
|
936
|
+
"path": {
|
937
|
+
"type": "string",
|
938
|
+
"description": "PDF file URL to restrict printing, must include protocol, supports http/https/oss"
|
939
|
+
},
|
940
|
+
"password": {
|
941
|
+
"type": "string",
|
942
|
+
"description": "PDF document password, required if the document is password-protected"
|
943
|
+
},
|
944
|
+
"name": {
|
945
|
+
"type": "string",
|
946
|
+
"description": "Original filename of the document"
|
947
|
+
}
|
948
|
+
},
|
949
|
+
"required": ["path"]
|
950
|
+
},
|
951
|
+
"description": "List of PDF files to restrict printing, each containing path and optional password"
|
952
|
+
}
|
953
|
+
},
|
954
|
+
"required": ["files"]
|
955
|
+
}
|
892
956
|
)
|
893
957
|
]
|
894
958
|
|
@@ -958,7 +1022,12 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
|
|
958
1022
|
"edit_type": "extract_image", # 编辑类型
|
959
1023
|
"is_edit_operation": True, # 标记为编辑操作
|
960
1024
|
"param_keys": ["format"] # 需要从arguments获取的参数
|
961
|
-
}
|
1025
|
+
},
|
1026
|
+
"restrict_printing": {
|
1027
|
+
"edit_type": "encrypt", # 或protect,和protect_pdf一致
|
1028
|
+
"is_edit_operation": True,
|
1029
|
+
"param_keys": [] # 不暴露provider
|
1030
|
+
},
|
962
1031
|
}
|
963
1032
|
|
964
1033
|
DEFAULTS = {
|
@@ -1019,6 +1088,10 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
|
|
1019
1088
|
# 对于protect_pdf工具,需要处理新密码
|
1020
1089
|
if name == "protect_pdf" and "password" in arguments:
|
1021
1090
|
operation_config["extra_params"]["password"] = arguments.get("password")
|
1091
|
+
|
1092
|
+
# restrict_printing工具自动加provider参数
|
1093
|
+
if name == "restrict_printing":
|
1094
|
+
operation_config["extra_params"]["provider"] = "printpermission"
|
1022
1095
|
|
1023
1096
|
# 特殊处理merge_pdfs工具
|
1024
1097
|
if name == "merge_pdfs":
|
@@ -1063,10 +1136,10 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
|
|
1063
1136
|
# 调用通用处理函数
|
1064
1137
|
result = await process_tool_call(logger, file_objects, operation_config)
|
1065
1138
|
return [result]
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1139
|
+
else:
|
1140
|
+
error_msg = f"未知工具: {name}"
|
1141
|
+
await logger.error(error_msg, ValueError)
|
1142
|
+
return [types.TextContent(type="text", text=error_msg)]
|
1070
1143
|
|
1071
1144
|
async def main():
|
1072
1145
|
"""应用主入口"""
|
@@ -2,8 +2,8 @@ lightpdf_aipdf_mcp/__init__.py,sha256=PPnAgpvJLYLVOTxnHDmJAulFnHJD6wuTwS6tRGjqq6
|
|
2
2
|
lightpdf_aipdf_mcp/common.py,sha256=_UO1f6S9Qr_3k6u5iBpdVDpvTK5U-tHEpu9KsDGqV8Y,6635
|
3
3
|
lightpdf_aipdf_mcp/converter.py,sha256=f9YuDtOmXBGlMmS3O4Xn3rdWljY9XcNxu0CjftH4s0o,14726
|
4
4
|
lightpdf_aipdf_mcp/editor.py,sha256=O7wF_HWs5l-IiXLbZYLNYjj1ygo2v4yGJEYMJtn7jpo,26916
|
5
|
-
lightpdf_aipdf_mcp/server.py,sha256=
|
6
|
-
lightpdf_aipdf_mcp-0.1.
|
7
|
-
lightpdf_aipdf_mcp-0.1.
|
8
|
-
lightpdf_aipdf_mcp-0.1.
|
9
|
-
lightpdf_aipdf_mcp-0.1.
|
5
|
+
lightpdf_aipdf_mcp/server.py,sha256=sHFc2c7gLM6qh5sqbZREynoT53QZDvoXKCNEzWfnC6o,52200
|
6
|
+
lightpdf_aipdf_mcp-0.1.85.dist-info/METADATA,sha256=Ib-0va5128UPeUT7QLNekFkGmTnylT8GXk5j1cVlmZg,8119
|
7
|
+
lightpdf_aipdf_mcp-0.1.85.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
8
|
+
lightpdf_aipdf_mcp-0.1.85.dist-info/entry_points.txt,sha256=X7TGUe52N4sYH-tYt0YUGApeJgw-efQlZA6uAZmlmr4,63
|
9
|
+
lightpdf_aipdf_mcp-0.1.85.dist-info/RECORD,,
|
File without changes
|
{lightpdf_aipdf_mcp-0.1.84.dist-info → lightpdf_aipdf_mcp-0.1.85.dist-info}/entry_points.txt
RENAMED
File without changes
|