Files
Lin Manhui 1e5aa0ad31 [Feat] Refactor MCP server to use Python SDK (#18098)
* refactor(mcp): add Executor base class and module structure

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(code quality): rename TimeoutError and remove unnecessary pass statements

- Rename TimeoutError to ExecutionTimeoutError to avoid shadowing built-in exception
- Remove unnecessary pass statements from exception classes and abstract methods

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(mcp): add HTTPExecutor base class for synchronous HTTP APIs

* feat(mcp): add AIStudioExecutor using AsyncPaddleOCRClient

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(mcp): add LocalExecutor for local inference

- Add LocalExecutor class for local PaddleOCR inference
- Add _EngineWrapper to run synchronous engine in async context
- Support all pipeline types: OCR, PP-StructureV3, PaddleOCR-VL series
- Handle file path, URL, and Base64 input formats

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(mcp): add QianfanExecutor and SelfHostedExecutor

- QianfanExecutor: Bearer token authentication, "paddleocr" endpoint
- SelfHostedExecutor: No authentication, "ocr"/"layout-parsing" endpoints
- Both inherit HTTPExecutor with unified response parsing

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(mcp): add executor factory function

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(mcp): add capabilities module with OCR and layout parsing

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(mcp): fix type hints and remove pass statements in capabilities

* refactor(mcp): update __main__.py to use new architecture

* refactor(mcp): update copyright year to 2026

* refactor(mcp): add type hint to main() function

* chore(mcp): bump version to 0.7.0

* refactor(mcp): remove old pipelines.py

* docs(mcp): update docs for v0.7.0 SDK-based architecture

- Remove PADDLEOCR_MCP_SERVER_URL for aistudio mode (SDK has built-in default)
- Add optional PADDLEOCR_MCP_BASE_URL for custom AI Studio base URL
- Update parameter reference table

* Update code

* fix(mcp): fix AIStudioExecutor SDK integration

- Use PPStructureV3Options for PP-StructureV3 pipeline
- Use PaddleOCRVLOptions for PaddleOCR-VL series
- Fix DocParsingPage attribute names (markdown_text, markdown_images)

* refactor(mcp): rename layout to doc_parsing

- Rename layout.py to doc_parsing.py
- Rename LayoutParsingCapability to DocParsingCapability
- Rename _parse_layout_response_http to _parse_doc_parsing_response_http
- Rename _parse_layout_result to _parse_doc_parsing_result
- Remove file path comments from all Python files

* docs(mcp): make DocParsingCapability docstring more generic

- Change from listing specific pipelines to "e.g." style
- Make tool_name description more generic for future extensibility

* remove unused files

* docs(mcp): update terminology and remove obsolete URL configuration

- Change '工作模式' to '推理方式' / 'Inference methods'
- Unify with SDK docs: use '官方 API' / 'Official API'
- Update options: 本地推理、官方API、千帆API、自建API
- Remove obsolete manual URL configuration (SDK has built-in defaults)
- Update token acquisition instructions

* docs(mcp): unify English doc terminology - working modes/mode → inference methods/method/API

- Update TOC: 'Working Modes Explained' → 'Inference Methods'
- Change 'Mode 1: Local Python Library' → 'Method 1: Local Inference'
- Update parameter table: 'mode' → 'source', 'service' → 'API'
  - 'local Python library' → 'local inference'
  - 'PaddleOCR official service' → 'Official API'
  - 'Qianfan platform service' → 'Qianfan API'
  - 'self-hosted service' → 'Self-hosted API'
- Update example command comments
- Update 'Local mode' → 'Local Inference' in uvx section
- Update Known Limitations section

* fix(mcp): correct inaccuracies and unify terminology in docs and code

- Remove incorrect Qianfan pipeline validation (OCR is supported)
- Fix broken anchor link in Chinese doc 2.4 section
- Unify Chinese doc terminology:
  - 千帆平台服务/自托管服务 → 千帆 API/自建 API
  - PaddleOCR 官方服务 → 官方 API
  - 本地 Python 库模式 → 本地推理
  - 模式/方式 → 推理方式
- Fix Chinese doc numbered list error (5 → 4)
- Remove incorrect Qianfan pipeline limitation note from English doc
- Update example command comments to use consistent terminology

* docs(mcp): simplify pipeline documentation and remove hardcoded lists

- Replace Chinese docstrings with English in base.py
- Remove hardcoded pipeline enumeration from AIStudioExecutor docstring
- Simplify pipeline table: merge PaddleOCR-VL series into single entry
- Add 'etc.' to parameter options to indicate extensibility

* Fix bugs

* refactor(mcp): let SDK use service-side defaults

- Remove hardcoded parameter defaults (use_doc_orientation_classify=False, etc.)
- Only set visualize=False (MCP tool never returns visualizations)
- Pass-through all optional parameters from user options dict
- This allows server-side optimizations and better future compatibility

* feat(mcp): add reasonable default options

- All pipelines: use_doc_orientation_classify=False, use_doc_unwarping=False
- PP-StructureV3: use_chart_recognition=True
- PaddleOCR-VL series: use_chart_recognition=True, use_seal_recognition=True
- Users can override these defaults via options dict

* refactor(mcp): move default options to MCPCapability

- Move default options from AIStudioExecutor to MCPCapability._process
- All executors now receive same default behavior via capability layer
- User options override defaults
- Add pipeline parameter to MCPCapability and subclasses

* refactor(mcp): redesign capabilities as pipeline-level classes

- MCPCapability: add PIPELINE class attribute, remove constructor param
- BaseDocParsingCapability: new base class for doc parsing pipelines
- PPStructureV3Capability: dedicated class for PP-StructureV3
- PaddleOCRVLCapability: handles PaddleOCR-VL series with pipeline param
- OCRCapability: define PIPELINE as class attribute
- Remove old DocParsingCapability (replaced by specific classes)
- Factory simplified: no need to pass pipeline to constructors

* refactor(mcp): use method for default options instead of hardcoded logic

- MCPCapability: add DEFAULT_OPTIONS constant and get_default_options method
- BaseDocParsingCapability: override get_default_options for chart recognition
- PaddleOCRVLCapability: override get_default_options for seal recognition
- Move default logic from hardcoded if/else to method inheritance
- PaddleOCRVLCapability: set PIPELINE dynamically in __init__

* Big refactor

* Fix bugs

* Remove tests

* Remove unused comments

* Fix doc bugs

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-05 02:20:24 +08:00
..
2026-02-03 09:40:06 +08:00