kreuzberg 4.0.8 → 4.1.0

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 (308) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +1 -1
  4. data/ext/kreuzberg_rb/native/Cargo.lock +94 -98
  5. data/ext/kreuzberg_rb/native/Cargo.toml +4 -2
  6. data/ext/kreuzberg_rb/native/src/batch.rs +139 -0
  7. data/ext/kreuzberg_rb/native/src/config/mod.rs +10 -0
  8. data/ext/kreuzberg_rb/native/src/config/types.rs +1058 -0
  9. data/ext/kreuzberg_rb/native/src/error_handling.rs +125 -0
  10. data/ext/kreuzberg_rb/native/src/extraction.rs +79 -0
  11. data/ext/kreuzberg_rb/native/src/gc_guarded_value.rs +35 -0
  12. data/ext/kreuzberg_rb/native/src/helpers.rs +176 -0
  13. data/ext/kreuzberg_rb/native/src/lib.rs +342 -3622
  14. data/ext/kreuzberg_rb/native/src/metadata.rs +34 -0
  15. data/ext/kreuzberg_rb/native/src/plugins/mod.rs +92 -0
  16. data/ext/kreuzberg_rb/native/src/plugins/ocr_backend.rs +159 -0
  17. data/ext/kreuzberg_rb/native/src/plugins/post_processor.rs +126 -0
  18. data/ext/kreuzberg_rb/native/src/plugins/validator.rs +99 -0
  19. data/ext/kreuzberg_rb/native/src/result.rs +326 -0
  20. data/ext/kreuzberg_rb/native/src/validation.rs +4 -0
  21. data/lib/kreuzberg/config.rb +66 -0
  22. data/lib/kreuzberg/result.rb +107 -2
  23. data/lib/kreuzberg/types.rb +104 -0
  24. data/lib/kreuzberg/version.rb +1 -1
  25. data/lib/kreuzberg.rb +0 -4
  26. data/sig/kreuzberg.rbs +105 -1
  27. data/vendor/Cargo.toml +3 -3
  28. data/vendor/kreuzberg/Cargo.toml +4 -3
  29. data/vendor/kreuzberg/README.md +1 -1
  30. data/vendor/kreuzberg/src/api/config.rs +69 -0
  31. data/vendor/kreuzberg/src/api/handlers.rs +99 -2
  32. data/vendor/kreuzberg/src/api/mod.rs +14 -7
  33. data/vendor/kreuzberg/src/api/router.rs +214 -0
  34. data/vendor/kreuzberg/src/api/startup.rs +243 -0
  35. data/vendor/kreuzberg/src/api/types.rs +78 -0
  36. data/vendor/kreuzberg/src/cache/cleanup.rs +277 -0
  37. data/vendor/kreuzberg/src/cache/core.rs +428 -0
  38. data/vendor/kreuzberg/src/cache/mod.rs +21 -843
  39. data/vendor/kreuzberg/src/cache/utilities.rs +156 -0
  40. data/vendor/kreuzberg/src/chunking/boundaries.rs +301 -0
  41. data/vendor/kreuzberg/src/chunking/builder.rs +294 -0
  42. data/vendor/kreuzberg/src/chunking/config.rs +52 -0
  43. data/vendor/kreuzberg/src/chunking/core.rs +1017 -0
  44. data/vendor/kreuzberg/src/chunking/mod.rs +14 -2211
  45. data/vendor/kreuzberg/src/chunking/processor.rs +10 -0
  46. data/vendor/kreuzberg/src/chunking/validation.rs +686 -0
  47. data/vendor/kreuzberg/src/core/config/extraction/core.rs +169 -0
  48. data/vendor/kreuzberg/src/core/config/extraction/env.rs +179 -0
  49. data/vendor/kreuzberg/src/core/config/extraction/loaders.rs +204 -0
  50. data/vendor/kreuzberg/src/core/config/extraction/mod.rs +42 -0
  51. data/vendor/kreuzberg/src/core/config/extraction/types.rs +93 -0
  52. data/vendor/kreuzberg/src/core/config/formats.rs +135 -0
  53. data/vendor/kreuzberg/src/core/config/mod.rs +20 -0
  54. data/vendor/kreuzberg/src/core/config/ocr.rs +73 -0
  55. data/vendor/kreuzberg/src/core/config/page.rs +57 -0
  56. data/vendor/kreuzberg/src/core/config/pdf.rs +111 -0
  57. data/vendor/kreuzberg/src/core/config/processing.rs +312 -0
  58. data/vendor/kreuzberg/src/core/config_validation/dependencies.rs +187 -0
  59. data/vendor/kreuzberg/src/core/config_validation/mod.rs +386 -0
  60. data/vendor/kreuzberg/src/core/config_validation/sections.rs +401 -0
  61. data/vendor/kreuzberg/src/core/extractor/batch.rs +246 -0
  62. data/vendor/kreuzberg/src/core/extractor/bytes.rs +116 -0
  63. data/vendor/kreuzberg/src/core/extractor/file.rs +240 -0
  64. data/vendor/kreuzberg/src/core/extractor/helpers.rs +71 -0
  65. data/vendor/kreuzberg/src/core/extractor/legacy.rs +62 -0
  66. data/vendor/kreuzberg/src/core/extractor/mod.rs +490 -0
  67. data/vendor/kreuzberg/src/core/extractor/sync.rs +208 -0
  68. data/vendor/kreuzberg/src/core/mod.rs +4 -1
  69. data/vendor/kreuzberg/src/core/pipeline/cache.rs +60 -0
  70. data/vendor/kreuzberg/src/core/pipeline/execution.rs +89 -0
  71. data/vendor/kreuzberg/src/core/pipeline/features.rs +108 -0
  72. data/vendor/kreuzberg/src/core/pipeline/format.rs +392 -0
  73. data/vendor/kreuzberg/src/core/pipeline/initialization.rs +67 -0
  74. data/vendor/kreuzberg/src/core/pipeline/mod.rs +135 -0
  75. data/vendor/kreuzberg/src/core/pipeline/tests.rs +975 -0
  76. data/vendor/kreuzberg/src/core/server_config/env.rs +90 -0
  77. data/vendor/kreuzberg/src/core/server_config/loader.rs +202 -0
  78. data/vendor/kreuzberg/src/core/server_config/mod.rs +380 -0
  79. data/vendor/kreuzberg/src/core/server_config/tests/basic_tests.rs +124 -0
  80. data/vendor/kreuzberg/src/core/server_config/tests/env_tests.rs +216 -0
  81. data/vendor/kreuzberg/src/core/server_config/tests/file_loading_tests.rs +341 -0
  82. data/vendor/kreuzberg/src/core/server_config/tests/mod.rs +5 -0
  83. data/vendor/kreuzberg/src/core/server_config/validation.rs +17 -0
  84. data/vendor/kreuzberg/src/embeddings.rs +136 -13
  85. data/vendor/kreuzberg/src/extraction/{archive.rs → archive/mod.rs} +45 -239
  86. data/vendor/kreuzberg/src/extraction/archive/sevenz.rs +98 -0
  87. data/vendor/kreuzberg/src/extraction/archive/tar.rs +118 -0
  88. data/vendor/kreuzberg/src/extraction/archive/zip.rs +101 -0
  89. data/vendor/kreuzberg/src/extraction/html/converter.rs +592 -0
  90. data/vendor/kreuzberg/src/extraction/html/image_handling.rs +95 -0
  91. data/vendor/kreuzberg/src/extraction/html/mod.rs +53 -0
  92. data/vendor/kreuzberg/src/extraction/html/processor.rs +659 -0
  93. data/vendor/kreuzberg/src/extraction/html/stack_management.rs +103 -0
  94. data/vendor/kreuzberg/src/extraction/html/types.rs +28 -0
  95. data/vendor/kreuzberg/src/extraction/mod.rs +6 -2
  96. data/vendor/kreuzberg/src/extraction/pptx/container.rs +159 -0
  97. data/vendor/kreuzberg/src/extraction/pptx/content_builder.rs +168 -0
  98. data/vendor/kreuzberg/src/extraction/pptx/elements.rs +132 -0
  99. data/vendor/kreuzberg/src/extraction/pptx/image_handling.rs +57 -0
  100. data/vendor/kreuzberg/src/extraction/pptx/metadata.rs +160 -0
  101. data/vendor/kreuzberg/src/extraction/pptx/mod.rs +558 -0
  102. data/vendor/kreuzberg/src/extraction/pptx/parser.rs +379 -0
  103. data/vendor/kreuzberg/src/extraction/transform/content.rs +205 -0
  104. data/vendor/kreuzberg/src/extraction/transform/elements.rs +211 -0
  105. data/vendor/kreuzberg/src/extraction/transform/mod.rs +480 -0
  106. data/vendor/kreuzberg/src/extraction/transform/types.rs +27 -0
  107. data/vendor/kreuzberg/src/extractors/archive.rs +2 -0
  108. data/vendor/kreuzberg/src/extractors/bibtex.rs +2 -0
  109. data/vendor/kreuzberg/src/extractors/djot_format/attributes.rs +134 -0
  110. data/vendor/kreuzberg/src/extractors/djot_format/conversion.rs +223 -0
  111. data/vendor/kreuzberg/src/extractors/djot_format/extractor.rs +172 -0
  112. data/vendor/kreuzberg/src/extractors/djot_format/mod.rs +24 -0
  113. data/vendor/kreuzberg/src/extractors/djot_format/parsing/block_handlers.rs +271 -0
  114. data/vendor/kreuzberg/src/extractors/djot_format/parsing/content_extraction.rs +257 -0
  115. data/vendor/kreuzberg/src/extractors/djot_format/parsing/event_handlers.rs +101 -0
  116. data/vendor/kreuzberg/src/extractors/djot_format/parsing/inline_handlers.rs +201 -0
  117. data/vendor/kreuzberg/src/extractors/djot_format/parsing/mod.rs +16 -0
  118. data/vendor/kreuzberg/src/extractors/djot_format/parsing/state.rs +78 -0
  119. data/vendor/kreuzberg/src/extractors/djot_format/parsing/table_extraction.rs +68 -0
  120. data/vendor/kreuzberg/src/extractors/djot_format/parsing/text_extraction.rs +61 -0
  121. data/vendor/kreuzberg/src/extractors/djot_format/rendering.rs +452 -0
  122. data/vendor/kreuzberg/src/extractors/docbook.rs +2 -0
  123. data/vendor/kreuzberg/src/extractors/docx.rs +12 -1
  124. data/vendor/kreuzberg/src/extractors/email.rs +2 -0
  125. data/vendor/kreuzberg/src/extractors/epub/content.rs +333 -0
  126. data/vendor/kreuzberg/src/extractors/epub/metadata.rs +137 -0
  127. data/vendor/kreuzberg/src/extractors/epub/mod.rs +186 -0
  128. data/vendor/kreuzberg/src/extractors/epub/parsing.rs +86 -0
  129. data/vendor/kreuzberg/src/extractors/excel.rs +4 -0
  130. data/vendor/kreuzberg/src/extractors/fictionbook.rs +2 -0
  131. data/vendor/kreuzberg/src/extractors/frontmatter_utils.rs +466 -0
  132. data/vendor/kreuzberg/src/extractors/html.rs +80 -8
  133. data/vendor/kreuzberg/src/extractors/image.rs +8 -1
  134. data/vendor/kreuzberg/src/extractors/jats/elements.rs +350 -0
  135. data/vendor/kreuzberg/src/extractors/jats/metadata.rs +21 -0
  136. data/vendor/kreuzberg/src/extractors/{jats.rs → jats/mod.rs} +10 -412
  137. data/vendor/kreuzberg/src/extractors/jats/parser.rs +52 -0
  138. data/vendor/kreuzberg/src/extractors/jupyter.rs +2 -0
  139. data/vendor/kreuzberg/src/extractors/latex/commands.rs +93 -0
  140. data/vendor/kreuzberg/src/extractors/latex/environments.rs +157 -0
  141. data/vendor/kreuzberg/src/extractors/latex/metadata.rs +27 -0
  142. data/vendor/kreuzberg/src/extractors/latex/mod.rs +146 -0
  143. data/vendor/kreuzberg/src/extractors/latex/parser.rs +231 -0
  144. data/vendor/kreuzberg/src/extractors/latex/utilities.rs +126 -0
  145. data/vendor/kreuzberg/src/extractors/markdown.rs +39 -162
  146. data/vendor/kreuzberg/src/extractors/mod.rs +9 -1
  147. data/vendor/kreuzberg/src/extractors/odt.rs +2 -0
  148. data/vendor/kreuzberg/src/extractors/opml/core.rs +165 -0
  149. data/vendor/kreuzberg/src/extractors/opml/mod.rs +31 -0
  150. data/vendor/kreuzberg/src/extractors/opml/parser.rs +479 -0
  151. data/vendor/kreuzberg/src/extractors/orgmode.rs +2 -0
  152. data/vendor/kreuzberg/src/extractors/pdf/extraction.rs +106 -0
  153. data/vendor/kreuzberg/src/extractors/{pdf.rs → pdf/mod.rs} +25 -324
  154. data/vendor/kreuzberg/src/extractors/pdf/ocr.rs +214 -0
  155. data/vendor/kreuzberg/src/extractors/pdf/pages.rs +51 -0
  156. data/vendor/kreuzberg/src/extractors/pptx.rs +9 -2
  157. data/vendor/kreuzberg/src/extractors/rst.rs +2 -0
  158. data/vendor/kreuzberg/src/extractors/rtf/encoding.rs +116 -0
  159. data/vendor/kreuzberg/src/extractors/rtf/formatting.rs +24 -0
  160. data/vendor/kreuzberg/src/extractors/rtf/images.rs +72 -0
  161. data/vendor/kreuzberg/src/extractors/rtf/metadata.rs +216 -0
  162. data/vendor/kreuzberg/src/extractors/rtf/mod.rs +142 -0
  163. data/vendor/kreuzberg/src/extractors/rtf/parser.rs +259 -0
  164. data/vendor/kreuzberg/src/extractors/rtf/tables.rs +83 -0
  165. data/vendor/kreuzberg/src/extractors/structured.rs +2 -0
  166. data/vendor/kreuzberg/src/extractors/text.rs +4 -0
  167. data/vendor/kreuzberg/src/extractors/typst.rs +2 -0
  168. data/vendor/kreuzberg/src/extractors/xml.rs +2 -0
  169. data/vendor/kreuzberg/src/keywords/processor.rs +14 -0
  170. data/vendor/kreuzberg/src/language_detection/processor.rs +10 -0
  171. data/vendor/kreuzberg/src/lib.rs +2 -2
  172. data/vendor/kreuzberg/src/mcp/errors.rs +312 -0
  173. data/vendor/kreuzberg/src/mcp/format.rs +211 -0
  174. data/vendor/kreuzberg/src/mcp/mod.rs +9 -3
  175. data/vendor/kreuzberg/src/mcp/params.rs +196 -0
  176. data/vendor/kreuzberg/src/mcp/server.rs +39 -1438
  177. data/vendor/kreuzberg/src/mcp/tools/cache.rs +179 -0
  178. data/vendor/kreuzberg/src/mcp/tools/extraction.rs +403 -0
  179. data/vendor/kreuzberg/src/mcp/tools/mime.rs +150 -0
  180. data/vendor/kreuzberg/src/mcp/tools/mod.rs +11 -0
  181. data/vendor/kreuzberg/src/ocr/backends/easyocr.rs +96 -0
  182. data/vendor/kreuzberg/src/ocr/backends/mod.rs +7 -0
  183. data/vendor/kreuzberg/src/ocr/backends/paddleocr.rs +27 -0
  184. data/vendor/kreuzberg/src/ocr/backends/tesseract.rs +134 -0
  185. data/vendor/kreuzberg/src/ocr/hocr.rs +60 -16
  186. data/vendor/kreuzberg/src/ocr/language_registry.rs +11 -235
  187. data/vendor/kreuzberg/src/ocr/mod.rs +1 -0
  188. data/vendor/kreuzberg/src/ocr/processor/config.rs +203 -0
  189. data/vendor/kreuzberg/src/ocr/processor/execution.rs +494 -0
  190. data/vendor/kreuzberg/src/ocr/processor/mod.rs +265 -0
  191. data/vendor/kreuzberg/src/ocr/processor/validation.rs +145 -0
  192. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +41 -24
  193. data/vendor/kreuzberg/src/pdf/bindings.rs +21 -8
  194. data/vendor/kreuzberg/src/pdf/hierarchy/bounding_box.rs +289 -0
  195. data/vendor/kreuzberg/src/pdf/hierarchy/clustering.rs +199 -0
  196. data/vendor/kreuzberg/src/pdf/{hierarchy.rs → hierarchy/extraction.rs} +6 -346
  197. data/vendor/kreuzberg/src/pdf/hierarchy/mod.rs +18 -0
  198. data/vendor/kreuzberg/src/plugins/extractor/mod.rs +319 -0
  199. data/vendor/kreuzberg/src/plugins/extractor/registry.rs +434 -0
  200. data/vendor/kreuzberg/src/plugins/extractor/trait.rs +391 -0
  201. data/vendor/kreuzberg/src/plugins/mod.rs +13 -0
  202. data/vendor/kreuzberg/src/plugins/ocr.rs +11 -0
  203. data/vendor/kreuzberg/src/plugins/processor/mod.rs +365 -0
  204. data/vendor/kreuzberg/src/plugins/processor/registry.rs +37 -0
  205. data/vendor/kreuzberg/src/plugins/processor/trait.rs +284 -0
  206. data/vendor/kreuzberg/src/plugins/registry/extractor.rs +416 -0
  207. data/vendor/kreuzberg/src/plugins/registry/mod.rs +116 -0
  208. data/vendor/kreuzberg/src/plugins/registry/ocr.rs +293 -0
  209. data/vendor/kreuzberg/src/plugins/registry/processor.rs +304 -0
  210. data/vendor/kreuzberg/src/plugins/registry/validator.rs +238 -0
  211. data/vendor/kreuzberg/src/plugins/validator/mod.rs +424 -0
  212. data/vendor/kreuzberg/src/plugins/validator/registry.rs +355 -0
  213. data/vendor/kreuzberg/src/plugins/validator/trait.rs +276 -0
  214. data/vendor/kreuzberg/src/stopwords/languages/asian.rs +40 -0
  215. data/vendor/kreuzberg/src/stopwords/languages/germanic.rs +36 -0
  216. data/vendor/kreuzberg/src/stopwords/languages/mod.rs +10 -0
  217. data/vendor/kreuzberg/src/stopwords/languages/other.rs +44 -0
  218. data/vendor/kreuzberg/src/stopwords/languages/romance.rs +36 -0
  219. data/vendor/kreuzberg/src/stopwords/languages/slavic.rs +36 -0
  220. data/vendor/kreuzberg/src/stopwords/mod.rs +7 -33
  221. data/vendor/kreuzberg/src/text/quality.rs +1 -1
  222. data/vendor/kreuzberg/src/text/quality_processor.rs +10 -0
  223. data/vendor/kreuzberg/src/text/token_reduction/core/analysis.rs +238 -0
  224. data/vendor/kreuzberg/src/text/token_reduction/core/mod.rs +8 -0
  225. data/vendor/kreuzberg/src/text/token_reduction/core/punctuation.rs +54 -0
  226. data/vendor/kreuzberg/src/text/token_reduction/core/reducer.rs +384 -0
  227. data/vendor/kreuzberg/src/text/token_reduction/core/sentence_selection.rs +68 -0
  228. data/vendor/kreuzberg/src/text/token_reduction/core/word_filtering.rs +156 -0
  229. data/vendor/kreuzberg/src/text/token_reduction/filters/general.rs +377 -0
  230. data/vendor/kreuzberg/src/text/token_reduction/filters/html.rs +51 -0
  231. data/vendor/kreuzberg/src/text/token_reduction/filters/markdown.rs +285 -0
  232. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +131 -246
  233. data/vendor/kreuzberg/src/types/djot.rs +209 -0
  234. data/vendor/kreuzberg/src/types/extraction.rs +301 -0
  235. data/vendor/kreuzberg/src/types/formats.rs +443 -0
  236. data/vendor/kreuzberg/src/types/metadata.rs +560 -0
  237. data/vendor/kreuzberg/src/types/mod.rs +281 -0
  238. data/vendor/kreuzberg/src/types/page.rs +182 -0
  239. data/vendor/kreuzberg/src/types/serde_helpers.rs +132 -0
  240. data/vendor/kreuzberg/src/types/tables.rs +39 -0
  241. data/vendor/kreuzberg/src/utils/quality/heuristics.rs +58 -0
  242. data/vendor/kreuzberg/src/utils/{quality.rs → quality/mod.rs} +168 -489
  243. data/vendor/kreuzberg/src/utils/quality/patterns.rs +117 -0
  244. data/vendor/kreuzberg/src/utils/quality/scoring.rs +178 -0
  245. data/vendor/kreuzberg/src/utils/string_pool/buffer_pool.rs +325 -0
  246. data/vendor/kreuzberg/src/utils/string_pool/interned.rs +102 -0
  247. data/vendor/kreuzberg/src/utils/string_pool/language_pool.rs +119 -0
  248. data/vendor/kreuzberg/src/utils/string_pool/mime_pool.rs +235 -0
  249. data/vendor/kreuzberg/src/utils/string_pool/mod.rs +41 -0
  250. data/vendor/kreuzberg/tests/api_chunk.rs +313 -0
  251. data/vendor/kreuzberg/tests/api_embed.rs +6 -9
  252. data/vendor/kreuzberg/tests/batch_orchestration.rs +1 -0
  253. data/vendor/kreuzberg/tests/concurrency_stress.rs +7 -0
  254. data/vendor/kreuzberg/tests/core_integration.rs +1 -0
  255. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +130 -0
  256. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +5 -14
  257. data/vendor/kreuzberg/tests/format_integration.rs +2 -0
  258. data/vendor/kreuzberg/tests/helpers/mod.rs +1 -0
  259. data/vendor/kreuzberg/tests/html_table_test.rs +11 -11
  260. data/vendor/kreuzberg/tests/ocr_configuration.rs +16 -0
  261. data/vendor/kreuzberg/tests/ocr_errors.rs +18 -0
  262. data/vendor/kreuzberg/tests/ocr_quality.rs +9 -0
  263. data/vendor/kreuzberg/tests/ocr_stress.rs +1 -0
  264. data/vendor/kreuzberg/tests/pipeline_integration.rs +50 -0
  265. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +13 -0
  266. data/vendor/kreuzberg/tests/plugin_system.rs +12 -0
  267. data/vendor/kreuzberg/tests/registry_integration_tests.rs +2 -0
  268. data/vendor/kreuzberg-ffi/Cargo.toml +2 -1
  269. data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +2 -0
  270. data/vendor/kreuzberg-ffi/kreuzberg.h +347 -178
  271. data/vendor/kreuzberg-ffi/src/config/html.rs +318 -0
  272. data/vendor/kreuzberg-ffi/src/config/loader.rs +154 -0
  273. data/vendor/kreuzberg-ffi/src/config/merge.rs +104 -0
  274. data/vendor/kreuzberg-ffi/src/config/mod.rs +385 -0
  275. data/vendor/kreuzberg-ffi/src/config/parse.rs +91 -0
  276. data/vendor/kreuzberg-ffi/src/config/serialize.rs +118 -0
  277. data/vendor/kreuzberg-ffi/src/config_builder.rs +598 -0
  278. data/vendor/kreuzberg-ffi/src/error.rs +46 -14
  279. data/vendor/kreuzberg-ffi/src/helpers.rs +10 -0
  280. data/vendor/kreuzberg-ffi/src/html_options.rs +421 -0
  281. data/vendor/kreuzberg-ffi/src/lib.rs +16 -0
  282. data/vendor/kreuzberg-ffi/src/panic_shield.rs +11 -0
  283. data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +2 -0
  284. data/vendor/kreuzberg-ffi/src/result.rs +148 -122
  285. data/vendor/kreuzberg-ffi/src/result_view.rs +4 -0
  286. data/vendor/kreuzberg-tesseract/Cargo.toml +2 -2
  287. metadata +200 -28
  288. data/vendor/kreuzberg/src/api/server.rs +0 -518
  289. data/vendor/kreuzberg/src/core/config.rs +0 -1914
  290. data/vendor/kreuzberg/src/core/config_validation.rs +0 -949
  291. data/vendor/kreuzberg/src/core/extractor.rs +0 -1200
  292. data/vendor/kreuzberg/src/core/pipeline.rs +0 -1223
  293. data/vendor/kreuzberg/src/core/server_config.rs +0 -1220
  294. data/vendor/kreuzberg/src/extraction/html.rs +0 -1830
  295. data/vendor/kreuzberg/src/extraction/pptx.rs +0 -3102
  296. data/vendor/kreuzberg/src/extractors/epub.rs +0 -696
  297. data/vendor/kreuzberg/src/extractors/latex.rs +0 -653
  298. data/vendor/kreuzberg/src/extractors/opml.rs +0 -635
  299. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -809
  300. data/vendor/kreuzberg/src/ocr/processor.rs +0 -858
  301. data/vendor/kreuzberg/src/plugins/extractor.rs +0 -1042
  302. data/vendor/kreuzberg/src/plugins/processor.rs +0 -650
  303. data/vendor/kreuzberg/src/plugins/registry.rs +0 -1339
  304. data/vendor/kreuzberg/src/plugins/validator.rs +0 -967
  305. data/vendor/kreuzberg/src/text/token_reduction/core.rs +0 -832
  306. data/vendor/kreuzberg/src/types.rs +0 -1713
  307. data/vendor/kreuzberg/src/utils/string_pool.rs +0 -762
  308. data/vendor/kreuzberg-ffi/src/config.rs +0 -1341
@@ -1,179 +1,19 @@
1
- //! MCP server implementation for Kreuzberg.
1
+ //! Kreuzberg MCP server implementation.
2
2
  //!
3
- //! This module provides the core MCP server that exposes document extraction
4
- //! as tools for AI assistants via the Model Context Protocol.
3
+ //! This module provides the main MCP server struct and startup functions.
5
4
 
6
- use base64::prelude::*;
5
+ use crate::ExtractionConfig;
7
6
  use rmcp::{
8
- ErrorData as McpError, ServerHandler, ServiceExt,
7
+ ServerHandler, ServiceExt,
9
8
  handler::server::{router::tool::ToolRouter, wrapper::Parameters},
10
9
  model::*,
11
- schemars, tool, tool_handler, tool_router,
10
+ tool, tool_handler, tool_router,
12
11
  transport::stdio,
13
12
  };
14
13
 
15
14
  #[cfg(feature = "mcp-http")]
16
15
  use rmcp::transport::streamable_http_server::{StreamableHttpService, session::local::LocalSessionManager};
17
16
 
18
- use crate::{
19
- ExtractionConfig, ExtractionResult as KreuzbergResult, KreuzbergError, batch_extract_file, batch_extract_file_sync,
20
- cache, detect_mime_type, extract_bytes, extract_bytes_sync, extract_file, extract_file_sync,
21
- };
22
-
23
- /// Request parameters for file extraction.
24
- #[derive(Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
25
- pub struct ExtractFileParams {
26
- /// Path to the file to extract
27
- pub path: String,
28
- /// Optional MIME type hint (auto-detected if not provided)
29
- #[serde(skip_serializing_if = "Option::is_none")]
30
- pub mime_type: Option<String>,
31
- /// Enable OCR for scanned documents
32
- #[serde(default)]
33
- pub enable_ocr: bool,
34
- /// Force OCR even if text extraction succeeds
35
- #[serde(default)]
36
- pub force_ocr: bool,
37
- /// Use async extraction (default: false for sync)
38
- #[serde(default)]
39
- pub r#async: bool,
40
- }
41
-
42
- /// Request parameters for bytes extraction.
43
- #[derive(Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
44
- pub struct ExtractBytesParams {
45
- /// Base64-encoded file content
46
- pub data: String,
47
- /// Optional MIME type hint (auto-detected if not provided)
48
- #[serde(skip_serializing_if = "Option::is_none")]
49
- pub mime_type: Option<String>,
50
- /// Enable OCR for scanned documents
51
- #[serde(default)]
52
- pub enable_ocr: bool,
53
- /// Force OCR even if text extraction succeeds
54
- #[serde(default)]
55
- pub force_ocr: bool,
56
- /// Use async extraction (default: false for sync)
57
- #[serde(default)]
58
- pub r#async: bool,
59
- }
60
-
61
- /// Request parameters for batch file extraction.
62
- #[derive(Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
63
- pub struct BatchExtractFilesParams {
64
- /// Paths to files to extract
65
- pub paths: Vec<String>,
66
- /// Enable OCR for scanned documents
67
- #[serde(default)]
68
- pub enable_ocr: bool,
69
- /// Force OCR even if text extraction succeeds
70
- #[serde(default)]
71
- pub force_ocr: bool,
72
- /// Use async extraction (default: false for sync)
73
- #[serde(default)]
74
- pub r#async: bool,
75
- }
76
-
77
- /// Request parameters for MIME type detection.
78
- #[derive(Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
79
- pub struct DetectMimeTypeParams {
80
- /// Path to the file
81
- pub path: String,
82
- /// Use content-based detection (default: true)
83
- #[serde(default = "default_use_content")]
84
- pub use_content: bool,
85
- }
86
-
87
- fn default_use_content() -> bool {
88
- true
89
- }
90
-
91
- /// Map Kreuzberg errors to MCP error responses with appropriate error codes.
92
- ///
93
- /// This function ensures different error types are properly differentiated in MCP responses:
94
- /// - `Validation` errors → `INVALID_PARAMS` (-32602)
95
- /// - `UnsupportedFormat` errors → `INVALID_PARAMS` (-32602)
96
- /// - `Parsing` errors → `PARSE_ERROR` (-32700)
97
- /// - `Io` errors → `INTERNAL_ERROR` (-32603) with context preserved
98
- /// - All other errors → `INTERNAL_ERROR` (-32603)
99
- ///
100
- /// The error message and source chain are preserved to aid debugging.
101
- #[doc(hidden)]
102
- pub fn map_kreuzberg_error_to_mcp(error: KreuzbergError) -> McpError {
103
- match error {
104
- KreuzbergError::Validation { message, source } => {
105
- let mut error_message = format!("Validation error: {}", message);
106
- if let Some(src) = source {
107
- error_message.push_str(&format!(" (caused by: {})", src));
108
- }
109
- McpError::invalid_params(error_message, None)
110
- }
111
-
112
- KreuzbergError::UnsupportedFormat(mime_type) => {
113
- McpError::invalid_params(format!("Unsupported format: {}", mime_type), None)
114
- }
115
-
116
- KreuzbergError::MissingDependency(dep) => McpError::invalid_params(
117
- format!(
118
- "Missing required dependency: {}. Please install it to use this feature.",
119
- dep
120
- ),
121
- None,
122
- ),
123
-
124
- KreuzbergError::Parsing { message, source } => {
125
- let mut error_message = format!("Parsing error: {}", message);
126
- if let Some(src) = source {
127
- error_message.push_str(&format!(" (caused by: {})", src));
128
- }
129
- McpError::parse_error(error_message, None)
130
- }
131
-
132
- // OSError/RuntimeError must bubble up - system errors need user reports ~keep
133
- KreuzbergError::Io(io_err) => McpError::internal_error(format!("System I/O error: {}", io_err), None),
134
-
135
- KreuzbergError::Ocr { message, source } => {
136
- let mut error_message = format!("OCR processing error: {}", message);
137
- if let Some(src) = source {
138
- error_message.push_str(&format!(" (caused by: {})", src));
139
- }
140
- McpError::internal_error(error_message, None)
141
- }
142
-
143
- KreuzbergError::Cache { message, source } => {
144
- let mut error_message = format!("Cache error: {}", message);
145
- if let Some(src) = source {
146
- error_message.push_str(&format!(" (caused by: {})", src));
147
- }
148
- McpError::internal_error(error_message, None)
149
- }
150
-
151
- KreuzbergError::ImageProcessing { message, source } => {
152
- let mut error_message = format!("Image processing error: {}", message);
153
- if let Some(src) = source {
154
- error_message.push_str(&format!(" (caused by: {})", src));
155
- }
156
- McpError::internal_error(error_message, None)
157
- }
158
-
159
- KreuzbergError::Serialization { message, source } => {
160
- let mut error_message = format!("Serialization error: {}", message);
161
- if let Some(src) = source {
162
- error_message.push_str(&format!(" (caused by: {})", src));
163
- }
164
- McpError::internal_error(error_message, None)
165
- }
166
-
167
- KreuzbergError::Plugin { message, plugin_name } => {
168
- McpError::internal_error(format!("Plugin '{}' error: {}", plugin_name, message), None)
169
- }
170
-
171
- KreuzbergError::LockPoisoned(msg) => McpError::internal_error(format!("Internal lock poisoned: {}", msg), None),
172
-
173
- KreuzbergError::Other(msg) => McpError::internal_error(msg, None),
174
- }
175
- }
176
-
177
17
  /// Kreuzberg MCP server.
178
18
  ///
179
19
  /// Provides document extraction capabilities via MCP tools.
@@ -234,8 +74,12 @@ impl KreuzbergMcp {
234
74
  )]
235
75
  async fn extract_file(
236
76
  &self,
237
- Parameters(params): Parameters<ExtractFileParams>,
238
- ) -> Result<CallToolResult, McpError> {
77
+ Parameters(params): Parameters<super::params::ExtractFileParams>,
78
+ ) -> Result<CallToolResult, rmcp::ErrorData> {
79
+ use super::errors::map_kreuzberg_error_to_mcp;
80
+ use super::format::{build_config, format_extraction_result};
81
+ use crate::{extract_file, extract_file_sync};
82
+
239
83
  let config = build_config(&self.default_config, params.enable_ocr, params.force_ocr);
240
84
 
241
85
  let result = if params.r#async {
@@ -259,11 +103,16 @@ impl KreuzbergMcp {
259
103
  )]
260
104
  async fn extract_bytes(
261
105
  &self,
262
- Parameters(params): Parameters<ExtractBytesParams>,
263
- ) -> Result<CallToolResult, McpError> {
106
+ Parameters(params): Parameters<super::params::ExtractBytesParams>,
107
+ ) -> Result<CallToolResult, rmcp::ErrorData> {
108
+ use super::errors::map_kreuzberg_error_to_mcp;
109
+ use super::format::{build_config, format_extraction_result};
110
+ use crate::{extract_bytes, extract_bytes_sync};
111
+ use base64::prelude::*;
112
+
264
113
  let bytes = BASE64_STANDARD
265
114
  .decode(&params.data)
266
- .map_err(|e| McpError::invalid_params(format!("Invalid base64: {}", e), None))?;
115
+ .map_err(|e| rmcp::ErrorData::invalid_params(format!("Invalid base64: {}", e), None))?;
267
116
 
268
117
  let config = build_config(&self.default_config, params.enable_ocr, params.force_ocr);
269
118
 
@@ -290,8 +139,12 @@ impl KreuzbergMcp {
290
139
  )]
291
140
  async fn batch_extract_files(
292
141
  &self,
293
- Parameters(params): Parameters<BatchExtractFilesParams>,
294
- ) -> Result<CallToolResult, McpError> {
142
+ Parameters(params): Parameters<super::params::BatchExtractFilesParams>,
143
+ ) -> Result<CallToolResult, rmcp::ErrorData> {
144
+ use super::errors::map_kreuzberg_error_to_mcp;
145
+ use super::format::{build_config, format_extraction_result};
146
+ use crate::{batch_extract_file, batch_extract_file_sync};
147
+
295
148
  let config = build_config(&self.default_config, params.enable_ocr, params.force_ocr);
296
149
 
297
150
  let results = if params.r#async {
@@ -321,8 +174,11 @@ impl KreuzbergMcp {
321
174
  )]
322
175
  fn detect_mime_type(
323
176
  &self,
324
- Parameters(params): Parameters<DetectMimeTypeParams>,
325
- ) -> Result<CallToolResult, McpError> {
177
+ Parameters(params): Parameters<super::params::DetectMimeTypeParams>,
178
+ ) -> Result<CallToolResult, rmcp::ErrorData> {
179
+ use super::errors::map_kreuzberg_error_to_mcp;
180
+ use crate::detect_mime_type;
181
+
326
182
  let mime_type = detect_mime_type(&params.path, params.use_content).map_err(map_kreuzberg_error_to_mcp)?;
327
183
 
328
184
  Ok(CallToolResult::success(vec![Content::text(mime_type)]))
@@ -335,7 +191,10 @@ impl KreuzbergMcp {
335
191
  description = "Get cache statistics including total files, size, and available disk space.",
336
192
  annotations(title = "Cache Stats", read_only_hint = true, idempotent_hint = true)
337
193
  )]
338
- fn cache_stats(&self, Parameters(_): Parameters<()>) -> Result<CallToolResult, McpError> {
194
+ fn cache_stats(&self, Parameters(_): Parameters<()>) -> Result<CallToolResult, rmcp::ErrorData> {
195
+ use super::errors::map_kreuzberg_error_to_mcp;
196
+ use crate::cache;
197
+
339
198
  let cache_dir = std::env::current_dir()
340
199
  .unwrap_or_else(|_| std::path::PathBuf::from("."))
341
200
  .join(".kreuzberg");
@@ -369,7 +228,10 @@ impl KreuzbergMcp {
369
228
  description = "Clear all cached files. Returns the number of files removed and space freed in MB.",
370
229
  annotations(title = "Clear Cache", destructive_hint = true)
371
230
  )]
372
- fn cache_clear(&self, Parameters(_): Parameters<()>) -> Result<CallToolResult, McpError> {
231
+ fn cache_clear(&self, Parameters(_): Parameters<()>) -> Result<CallToolResult, rmcp::ErrorData> {
232
+ use super::errors::map_kreuzberg_error_to_mcp;
233
+ use crate::cache;
234
+
373
235
  let cache_dir = std::env::current_dir()
374
236
  .unwrap_or_else(|_| std::path::PathBuf::from("."))
375
237
  .join(".kreuzberg");
@@ -573,70 +435,9 @@ pub async fn start_mcp_server_http_with_config(
573
435
  Ok(())
574
436
  }
575
437
 
576
- /// Build extraction config from MCP parameters.
577
- ///
578
- /// Starts with the default config and overlays OCR settings from request parameters.
579
- fn build_config(default_config: &ExtractionConfig, enable_ocr: bool, force_ocr: bool) -> ExtractionConfig {
580
- let mut config = default_config.clone();
581
-
582
- config.ocr = if enable_ocr {
583
- Some(crate::OcrConfig {
584
- backend: "tesseract".to_string(),
585
- language: "eng".to_string(),
586
- tesseract_config: None,
587
- })
588
- } else {
589
- None
590
- };
591
- config.force_ocr = force_ocr;
592
-
593
- config
594
- }
595
-
596
- /// Format extraction result as human-readable text.
597
- fn format_extraction_result(result: &KreuzbergResult) -> String {
598
- let mut response = String::new();
599
-
600
- response.push_str(&format!("Content ({} characters):\n", result.content.len()));
601
- response.push_str(&result.content);
602
- response.push_str("\n\n");
603
-
604
- response.push_str("Metadata:\n");
605
- response.push_str(&serde_json::to_string_pretty(&result.metadata).unwrap_or_default());
606
- response.push_str("\n\n");
607
-
608
- if !result.tables.is_empty() {
609
- response.push_str(&format!("Tables ({}):\n", result.tables.len()));
610
- for (i, table) in result.tables.iter().enumerate() {
611
- response.push_str(&format!("\nTable {} (page {}):\n", i + 1, table.page_number));
612
- response.push_str(&table.markdown);
613
- response.push('\n');
614
- }
615
- }
616
-
617
- response
618
- }
619
-
620
438
  #[cfg(test)]
621
439
  mod tests {
622
440
  use super::*;
623
- use std::path::PathBuf;
624
-
625
- /// Get the path to a test document relative to workspace root.
626
- fn get_test_path(relative_path: &str) -> String {
627
- let workspace_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
628
- .parent()
629
- .unwrap()
630
- .parent()
631
- .unwrap()
632
- .to_path_buf();
633
-
634
- workspace_root
635
- .join("test_documents")
636
- .join(relative_path)
637
- .to_string_lossy()
638
- .to_string()
639
- }
640
441
 
641
442
  #[tokio::test]
642
443
  async fn test_tool_router_has_routes() {
@@ -662,23 +463,6 @@ mod tests {
662
463
  assert!(info.capabilities.tools.is_some());
663
464
  }
664
465
 
665
- #[test]
666
- fn test_build_config() {
667
- let default_config = ExtractionConfig::default();
668
-
669
- let config = build_config(&default_config, false, false);
670
- assert!(config.ocr.is_none());
671
- assert!(!config.force_ocr);
672
-
673
- let config = build_config(&default_config, true, false);
674
- assert!(config.ocr.is_some());
675
- assert!(!config.force_ocr);
676
-
677
- let config = build_config(&default_config, true, true);
678
- assert!(config.ocr.is_some());
679
- assert!(config.force_ocr);
680
- }
681
-
682
466
  #[test]
683
467
  fn test_with_config_stores_provided_config() {
684
468
  let custom_config = ExtractionConfig {
@@ -693,699 +477,6 @@ mod tests {
693
477
  assert!(!server.default_config.use_cache);
694
478
  }
695
479
 
696
- #[test]
697
- fn test_map_validation_error_to_invalid_params() {
698
- let error = KreuzbergError::validation("invalid file path");
699
- let mcp_error = map_kreuzberg_error_to_mcp(error);
700
-
701
- assert_eq!(mcp_error.code.0, -32602);
702
- assert!(mcp_error.message.contains("Validation error"));
703
- assert!(mcp_error.message.contains("invalid file path"));
704
- }
705
-
706
- #[test]
707
- fn test_map_validation_error_with_source_preserves_chain() {
708
- let source = std::io::Error::new(std::io::ErrorKind::InvalidInput, "bad param");
709
- let error = KreuzbergError::validation_with_source("invalid configuration", source);
710
- let mcp_error = map_kreuzberg_error_to_mcp(error);
711
-
712
- assert_eq!(mcp_error.code.0, -32602);
713
- assert!(mcp_error.message.contains("Validation error"));
714
- assert!(mcp_error.message.contains("invalid configuration"));
715
- assert!(mcp_error.message.contains("caused by"));
716
- }
717
-
718
- #[test]
719
- fn test_map_unsupported_format_to_invalid_params() {
720
- let error = KreuzbergError::UnsupportedFormat("application/unknown".to_string());
721
- let mcp_error = map_kreuzberg_error_to_mcp(error);
722
-
723
- assert_eq!(mcp_error.code.0, -32602);
724
- assert!(mcp_error.message.contains("Unsupported format"));
725
- assert!(mcp_error.message.contains("application/unknown"));
726
- }
727
-
728
- #[test]
729
- fn test_map_missing_dependency_to_invalid_params() {
730
- let error = KreuzbergError::MissingDependency("tesseract".to_string());
731
- let mcp_error = map_kreuzberg_error_to_mcp(error);
732
-
733
- assert_eq!(mcp_error.code.0, -32602);
734
- assert!(mcp_error.message.contains("Missing required dependency"));
735
- assert!(mcp_error.message.contains("tesseract"));
736
- assert!(mcp_error.message.contains("Please install"));
737
- }
738
-
739
- #[test]
740
- fn test_map_parsing_error_to_parse_error() {
741
- let error = KreuzbergError::parsing("corrupt PDF file");
742
- let mcp_error = map_kreuzberg_error_to_mcp(error);
743
-
744
- assert_eq!(mcp_error.code.0, -32700);
745
- assert!(mcp_error.message.contains("Parsing error"));
746
- assert!(mcp_error.message.contains("corrupt PDF file"));
747
- }
748
-
749
- #[test]
750
- fn test_map_parsing_error_with_source_preserves_chain() {
751
- let source = std::io::Error::new(std::io::ErrorKind::InvalidData, "malformed data");
752
- let error = KreuzbergError::parsing_with_source("failed to parse document", source);
753
- let mcp_error = map_kreuzberg_error_to_mcp(error);
754
-
755
- assert_eq!(mcp_error.code.0, -32700);
756
- assert!(mcp_error.message.contains("Parsing error"));
757
- assert!(mcp_error.message.contains("failed to parse document"));
758
- assert!(mcp_error.message.contains("caused by"));
759
- }
760
-
761
- #[test]
762
- fn test_map_io_error_to_internal_error() {
763
- let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
764
- let error = KreuzbergError::Io(io_error);
765
- let mcp_error = map_kreuzberg_error_to_mcp(error);
766
-
767
- assert_eq!(mcp_error.code.0, -32603);
768
- assert!(mcp_error.message.contains("System I/O error"));
769
- assert!(mcp_error.message.contains("file not found"));
770
- }
771
-
772
- #[test]
773
- fn test_map_ocr_error_to_internal_error() {
774
- let error = KreuzbergError::ocr("tesseract failed");
775
- let mcp_error = map_kreuzberg_error_to_mcp(error);
776
-
777
- assert_eq!(mcp_error.code.0, -32603);
778
- assert!(mcp_error.message.contains("OCR processing error"));
779
- assert!(mcp_error.message.contains("tesseract failed"));
780
- }
781
-
782
- #[test]
783
- fn test_map_cache_error_to_internal_error() {
784
- let error = KreuzbergError::cache("cache write failed");
785
- let mcp_error = map_kreuzberg_error_to_mcp(error);
786
-
787
- assert_eq!(mcp_error.code.0, -32603);
788
- assert!(mcp_error.message.contains("Cache error"));
789
- assert!(mcp_error.message.contains("cache write failed"));
790
- }
791
-
792
- #[test]
793
- fn test_map_image_processing_error_to_internal_error() {
794
- let error = KreuzbergError::image_processing("resize failed");
795
- let mcp_error = map_kreuzberg_error_to_mcp(error);
796
-
797
- assert_eq!(mcp_error.code.0, -32603);
798
- assert!(mcp_error.message.contains("Image processing error"));
799
- assert!(mcp_error.message.contains("resize failed"));
800
- }
801
-
802
- #[test]
803
- fn test_map_serialization_error_to_internal_error() {
804
- let error = KreuzbergError::serialization("JSON encode failed");
805
- let mcp_error = map_kreuzberg_error_to_mcp(error);
806
-
807
- assert_eq!(mcp_error.code.0, -32603);
808
- assert!(mcp_error.message.contains("Serialization error"));
809
- assert!(mcp_error.message.contains("JSON encode failed"));
810
- }
811
-
812
- #[test]
813
- fn test_map_plugin_error_to_internal_error() {
814
- let error = KreuzbergError::Plugin {
815
- message: "extraction failed".to_string(),
816
- plugin_name: "pdf-extractor".to_string(),
817
- };
818
- let mcp_error = map_kreuzberg_error_to_mcp(error);
819
-
820
- assert_eq!(mcp_error.code.0, -32603);
821
- assert!(mcp_error.message.contains("Plugin 'pdf-extractor' error"));
822
- assert!(mcp_error.message.contains("extraction failed"));
823
- }
824
-
825
- #[test]
826
- fn test_map_lock_poisoned_error_to_internal_error() {
827
- let error = KreuzbergError::LockPoisoned("registry lock poisoned".to_string());
828
- let mcp_error = map_kreuzberg_error_to_mcp(error);
829
-
830
- assert_eq!(mcp_error.code.0, -32603);
831
- assert!(mcp_error.message.contains("Internal lock poisoned"));
832
- assert!(mcp_error.message.contains("registry lock poisoned"));
833
- }
834
-
835
- #[test]
836
- fn test_map_other_error_to_internal_error() {
837
- let error = KreuzbergError::Other("unexpected error".to_string());
838
- let mcp_error = map_kreuzberg_error_to_mcp(error);
839
-
840
- assert_eq!(mcp_error.code.0, -32603);
841
- assert!(mcp_error.message.contains("unexpected error"));
842
- }
843
-
844
- #[test]
845
- fn test_error_type_differentiation() {
846
- let validation = KreuzbergError::validation("test");
847
- let parsing = KreuzbergError::parsing("test");
848
- let io = KreuzbergError::Io(std::io::Error::other("test"));
849
-
850
- let val_mcp = map_kreuzberg_error_to_mcp(validation);
851
- let parse_mcp = map_kreuzberg_error_to_mcp(parsing);
852
- let io_mcp = map_kreuzberg_error_to_mcp(io);
853
-
854
- assert_eq!(val_mcp.code.0, -32602);
855
- assert_eq!(parse_mcp.code.0, -32700);
856
- assert_eq!(io_mcp.code.0, -32603);
857
-
858
- assert_ne!(val_mcp.code.0, parse_mcp.code.0);
859
- assert_ne!(val_mcp.code.0, io_mcp.code.0);
860
- assert_ne!(parse_mcp.code.0, io_mcp.code.0);
861
- }
862
-
863
- #[test]
864
- fn test_format_extraction_result_with_content() {
865
- let result = KreuzbergResult {
866
- content: "Sample extracted text".to_string(),
867
- mime_type: "text/plain".to_string(),
868
- metadata: crate::Metadata::default(),
869
- tables: vec![],
870
- detected_languages: None,
871
- chunks: None,
872
- images: None,
873
- pages: None,
874
- };
875
-
876
- let formatted = format_extraction_result(&result);
877
-
878
- assert!(formatted.contains("Content (21 characters)"));
879
- assert!(formatted.contains("Sample extracted text"));
880
- assert!(formatted.contains("Metadata:"));
881
- }
882
-
883
- #[test]
884
- fn test_format_extraction_result_with_tables() {
885
- let result = KreuzbergResult {
886
- content: "Document with tables".to_string(),
887
- mime_type: "application/pdf".to_string(),
888
- metadata: crate::Metadata::default(),
889
- tables: vec![
890
- crate::Table {
891
- cells: vec![
892
- vec!["Col1".to_string(), "Col2".to_string()],
893
- vec!["A".to_string(), "B".to_string()],
894
- ],
895
- page_number: 1,
896
- markdown: "| Col1 | Col2 |\n|------|------|\n| A | B |".to_string(),
897
- },
898
- crate::Table {
899
- cells: vec![
900
- vec!["X".to_string(), "Y".to_string()],
901
- vec!["1".to_string(), "2".to_string()],
902
- ],
903
- page_number: 2,
904
- markdown: "| X | Y |\n|---|---|\n| 1 | 2 |".to_string(),
905
- },
906
- ],
907
- detected_languages: None,
908
- chunks: None,
909
- images: None,
910
- pages: None,
911
- };
912
-
913
- let formatted = format_extraction_result(&result);
914
-
915
- assert!(formatted.contains("Tables (2)"));
916
- assert!(formatted.contains("Table 1 (page 1)"));
917
- assert!(formatted.contains("Table 2 (page 2)"));
918
- assert!(formatted.contains("| Col1 | Col2 |"));
919
- assert!(formatted.contains("| X | Y |"));
920
- }
921
-
922
- #[test]
923
- fn test_format_extraction_result_empty_content() {
924
- let result = KreuzbergResult {
925
- content: String::new(),
926
- mime_type: "text/plain".to_string(),
927
- metadata: crate::Metadata::default(),
928
- tables: vec![],
929
- detected_languages: None,
930
- chunks: None,
931
- images: None,
932
- pages: None,
933
- };
934
-
935
- let formatted = format_extraction_result(&result);
936
-
937
- assert!(formatted.contains("Content (0 characters)"));
938
- assert!(formatted.contains("Metadata:"));
939
- }
940
-
941
- #[test]
942
- fn test_format_extraction_result_no_tables() {
943
- let result = KreuzbergResult {
944
- content: "Simple text".to_string(),
945
- mime_type: "text/plain".to_string(),
946
- metadata: crate::Metadata::default(),
947
- tables: vec![],
948
- detected_languages: None,
949
- chunks: None,
950
- images: None,
951
- pages: None,
952
- };
953
-
954
- let formatted = format_extraction_result(&result);
955
-
956
- assert!(formatted.contains("Simple text"));
957
- assert!(!formatted.contains("Tables"));
958
- }
959
-
960
- #[tokio::test]
961
- async fn test_extract_file_sync_with_valid_pdf() {
962
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
963
- let params = ExtractFileParams {
964
- path: get_test_path("pdfs_with_tables/tiny.pdf").to_string(),
965
- mime_type: None,
966
- enable_ocr: false,
967
- force_ocr: false,
968
- r#async: true,
969
- };
970
-
971
- let result = server.extract_file(Parameters(params)).await;
972
-
973
- assert!(result.is_ok());
974
- let call_result = result.unwrap();
975
- if let Some(content) = call_result.content.first() {
976
- match &content.raw {
977
- RawContent::Text(text) => {
978
- assert!(!text.text.is_empty());
979
- assert!(text.text.contains("Content"));
980
- }
981
- _ => panic!("Expected text content"),
982
- }
983
- } else {
984
- panic!("Expected content in result");
985
- }
986
- }
987
-
988
- #[tokio::test]
989
- async fn test_extract_file_async_with_valid_pdf() {
990
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
991
- let params = ExtractFileParams {
992
- path: get_test_path("pdfs_with_tables/tiny.pdf").to_string(),
993
- mime_type: None,
994
- enable_ocr: false,
995
- force_ocr: false,
996
- r#async: true,
997
- };
998
-
999
- let result = server.extract_file(Parameters(params)).await;
1000
-
1001
- assert!(result.is_ok());
1002
- let call_result = result.unwrap();
1003
- if let Some(content) = call_result.content.first() {
1004
- match &content.raw {
1005
- RawContent::Text(text) => {
1006
- assert!(!text.text.is_empty());
1007
- }
1008
- _ => panic!("Expected text content"),
1009
- }
1010
- } else {
1011
- panic!("Expected content in result");
1012
- }
1013
- }
1014
-
1015
- #[tokio::test]
1016
- async fn test_extract_file_with_invalid_path() {
1017
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1018
- let params = ExtractFileParams {
1019
- path: "/nonexistent/file.pdf".to_string(),
1020
- mime_type: None,
1021
- enable_ocr: false,
1022
- force_ocr: false,
1023
- r#async: true,
1024
- };
1025
-
1026
- let result = server.extract_file(Parameters(params)).await;
1027
-
1028
- assert!(result.is_err());
1029
- let error = result.unwrap_err();
1030
- assert!(error.code.0 == -32602 || error.code.0 == -32603);
1031
- }
1032
-
1033
- #[tokio::test]
1034
- async fn test_extract_file_with_mime_type_hint() {
1035
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1036
- let params = ExtractFileParams {
1037
- path: get_test_path("pdfs_with_tables/tiny.pdf").to_string(),
1038
- mime_type: Some("application/pdf".to_string()),
1039
- enable_ocr: false,
1040
- force_ocr: false,
1041
- r#async: true,
1042
- };
1043
-
1044
- let result = server.extract_file(Parameters(params)).await;
1045
-
1046
- assert!(result.is_ok());
1047
- }
1048
-
1049
- #[tokio::test]
1050
- async fn test_extract_file_with_ocr_enabled() {
1051
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1052
- let params = ExtractFileParams {
1053
- path: get_test_path("pdfs_with_tables/tiny.pdf").to_string(),
1054
- mime_type: None,
1055
- enable_ocr: true,
1056
- force_ocr: false,
1057
- r#async: true,
1058
- };
1059
-
1060
- let result = server.extract_file(Parameters(params)).await;
1061
-
1062
- assert!(result.is_ok() || result.is_err());
1063
- }
1064
-
1065
- #[tokio::test]
1066
- async fn test_extract_file_with_force_ocr() {
1067
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1068
- let params = ExtractFileParams {
1069
- path: get_test_path("pdfs_with_tables/tiny.pdf").to_string(),
1070
- mime_type: None,
1071
- enable_ocr: true,
1072
- force_ocr: true,
1073
- r#async: true,
1074
- };
1075
-
1076
- let result = server.extract_file(Parameters(params)).await;
1077
-
1078
- assert!(result.is_ok() || result.is_err());
1079
- }
1080
-
1081
- #[tokio::test]
1082
- async fn test_extract_bytes_sync_with_valid_data() {
1083
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1084
-
1085
- let text_content = b"Hello, world!";
1086
- let encoded = BASE64_STANDARD.encode(text_content);
1087
-
1088
- let params = ExtractBytesParams {
1089
- data: encoded,
1090
- mime_type: Some("text/plain".to_string()),
1091
- enable_ocr: false,
1092
- force_ocr: false,
1093
- r#async: true,
1094
- };
1095
-
1096
- let result = server.extract_bytes(Parameters(params)).await;
1097
-
1098
- assert!(result.is_ok());
1099
- let call_result = result.unwrap();
1100
- if let Some(content) = call_result.content.first() {
1101
- match &content.raw {
1102
- RawContent::Text(text) => {
1103
- assert!(text.text.contains("Hello, world!"));
1104
- }
1105
- _ => panic!("Expected text content"),
1106
- }
1107
- } else {
1108
- panic!("Expected content in result");
1109
- }
1110
- }
1111
-
1112
- #[tokio::test]
1113
- async fn test_extract_bytes_async_with_valid_data() {
1114
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1115
-
1116
- let text_content = b"Async extraction test";
1117
- let encoded = BASE64_STANDARD.encode(text_content);
1118
-
1119
- let params = ExtractBytesParams {
1120
- data: encoded,
1121
- mime_type: Some("text/plain".to_string()),
1122
- enable_ocr: false,
1123
- force_ocr: false,
1124
- r#async: true,
1125
- };
1126
-
1127
- let result = server.extract_bytes(Parameters(params)).await;
1128
-
1129
- assert!(result.is_ok());
1130
- }
1131
-
1132
- #[tokio::test]
1133
- async fn test_extract_bytes_with_invalid_base64() {
1134
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1135
-
1136
- let params = ExtractBytesParams {
1137
- data: "not-valid-base64!!!".to_string(),
1138
- mime_type: None,
1139
- enable_ocr: false,
1140
- force_ocr: false,
1141
- r#async: true,
1142
- };
1143
-
1144
- let result = server.extract_bytes(Parameters(params)).await;
1145
-
1146
- assert!(result.is_err());
1147
- let error = result.unwrap_err();
1148
- assert_eq!(error.code.0, -32602);
1149
- assert!(error.message.contains("Invalid base64"));
1150
- }
1151
-
1152
- #[tokio::test]
1153
- async fn test_extract_bytes_without_mime_type() {
1154
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1155
-
1156
- let text_content = b"Test content";
1157
- let encoded = BASE64_STANDARD.encode(text_content);
1158
-
1159
- let params = ExtractBytesParams {
1160
- data: encoded,
1161
- mime_type: None,
1162
- enable_ocr: false,
1163
- force_ocr: false,
1164
- r#async: true,
1165
- };
1166
-
1167
- let result = server.extract_bytes(Parameters(params)).await;
1168
-
1169
- assert!(result.is_ok() || result.is_err());
1170
- }
1171
-
1172
- #[tokio::test]
1173
- async fn test_extract_bytes_with_ocr_enabled() {
1174
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1175
-
1176
- let text_content = b"OCR test content";
1177
- let encoded = BASE64_STANDARD.encode(text_content);
1178
-
1179
- let params = ExtractBytesParams {
1180
- data: encoded,
1181
- mime_type: Some("text/plain".to_string()),
1182
- enable_ocr: true,
1183
- force_ocr: false,
1184
- r#async: true,
1185
- };
1186
-
1187
- let result = server.extract_bytes(Parameters(params)).await;
1188
-
1189
- assert!(result.is_ok() || result.is_err());
1190
- }
1191
-
1192
- #[tokio::test]
1193
- async fn test_batch_extract_files_sync_with_valid_files() {
1194
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1195
- let params = BatchExtractFilesParams {
1196
- paths: vec![get_test_path("pdfs_with_tables/tiny.pdf").to_string()],
1197
- enable_ocr: false,
1198
- force_ocr: false,
1199
- r#async: true,
1200
- };
1201
-
1202
- let result = server.batch_extract_files(Parameters(params)).await;
1203
-
1204
- assert!(result.is_ok());
1205
- let call_result = result.unwrap();
1206
- if let Some(content) = call_result.content.first() {
1207
- match &content.raw {
1208
- RawContent::Text(text) => {
1209
- assert!(text.text.contains("Document 1"));
1210
- assert!(text.text.contains("tiny.pdf"));
1211
- }
1212
- _ => panic!("Expected text content"),
1213
- }
1214
- } else {
1215
- panic!("Expected content in result");
1216
- }
1217
- }
1218
-
1219
- #[tokio::test]
1220
- async fn test_batch_extract_files_async_with_multiple_files() {
1221
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1222
- let params = BatchExtractFilesParams {
1223
- paths: vec![
1224
- get_test_path("pdfs_with_tables/tiny.pdf").to_string(),
1225
- get_test_path("pdfs_with_tables/medium.pdf").to_string(),
1226
- ],
1227
- enable_ocr: false,
1228
- force_ocr: false,
1229
- r#async: true,
1230
- };
1231
-
1232
- let result = server.batch_extract_files(Parameters(params)).await;
1233
-
1234
- assert!(result.is_ok());
1235
- let call_result = result.unwrap();
1236
- if let Some(content) = call_result.content.first() {
1237
- match &content.raw {
1238
- RawContent::Text(text) => {
1239
- assert!(text.text.contains("Document 1"));
1240
- assert!(text.text.contains("Document 2"));
1241
- }
1242
- _ => panic!("Expected text content"),
1243
- }
1244
- } else {
1245
- panic!("Expected content in result");
1246
- }
1247
- }
1248
-
1249
- #[tokio::test]
1250
- async fn test_batch_extract_files_with_empty_list() {
1251
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1252
- let params = BatchExtractFilesParams {
1253
- paths: vec![],
1254
- enable_ocr: false,
1255
- force_ocr: false,
1256
- r#async: true,
1257
- };
1258
-
1259
- let result = server.batch_extract_files(Parameters(params)).await;
1260
-
1261
- assert!(result.is_ok());
1262
- let call_result = result.unwrap();
1263
- if let Some(content) = call_result.content.first() {
1264
- match &content.raw {
1265
- RawContent::Text(text) => {
1266
- assert!(text.text.is_empty() || text.text.trim().is_empty());
1267
- }
1268
- _ => panic!("Expected text content"),
1269
- }
1270
- } else {
1271
- panic!("Expected content in result");
1272
- }
1273
- }
1274
-
1275
- #[tokio::test]
1276
- async fn test_batch_extract_files_with_invalid_file() {
1277
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1278
- let params = BatchExtractFilesParams {
1279
- paths: vec!["/nonexistent/file.pdf".to_string()],
1280
- enable_ocr: false,
1281
- force_ocr: false,
1282
- r#async: true,
1283
- };
1284
-
1285
- let result = server.batch_extract_files(Parameters(params)).await;
1286
-
1287
- assert!(result.is_ok() || result.is_err());
1288
- }
1289
-
1290
- #[tokio::test]
1291
- async fn test_detect_mime_type_with_valid_file() {
1292
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1293
- let params = DetectMimeTypeParams {
1294
- path: get_test_path("pdfs_with_tables/tiny.pdf").to_string(),
1295
- use_content: true,
1296
- };
1297
-
1298
- let result = server.detect_mime_type(Parameters(params));
1299
-
1300
- assert!(result.is_ok());
1301
- let call_result = result.unwrap();
1302
- if let Some(content) = call_result.content.first() {
1303
- match &content.raw {
1304
- RawContent::Text(text) => {
1305
- assert!(text.text.contains("application/pdf") || text.text.contains("pdf"));
1306
- }
1307
- _ => panic!("Expected text content"),
1308
- }
1309
- } else {
1310
- panic!("Expected content in result");
1311
- }
1312
- }
1313
-
1314
- #[tokio::test]
1315
- async fn test_detect_mime_type_without_content_detection() {
1316
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1317
- let params = DetectMimeTypeParams {
1318
- path: get_test_path("pdfs_with_tables/tiny.pdf").to_string(),
1319
- use_content: false,
1320
- };
1321
-
1322
- let result = server.detect_mime_type(Parameters(params));
1323
-
1324
- assert!(result.is_ok());
1325
- }
1326
-
1327
- #[tokio::test]
1328
- async fn test_detect_mime_type_with_invalid_file() {
1329
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1330
- let params = DetectMimeTypeParams {
1331
- path: "/nonexistent/file.pdf".to_string(),
1332
- use_content: true,
1333
- };
1334
-
1335
- let result = server.detect_mime_type(Parameters(params));
1336
-
1337
- assert!(result.is_err());
1338
- let error = result.unwrap_err();
1339
- assert!(error.code.0 == -32602 || error.code.0 == -32603);
1340
- }
1341
-
1342
- #[tokio::test]
1343
- async fn test_cache_stats_returns_statistics() {
1344
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1345
-
1346
- let result = server.cache_stats(Parameters(()));
1347
-
1348
- assert!(result.is_ok());
1349
- let call_result = result.unwrap();
1350
- if let Some(content) = call_result.content.first() {
1351
- match &content.raw {
1352
- RawContent::Text(text) => {
1353
- assert!(text.text.contains("Cache Statistics"));
1354
- assert!(text.text.contains("Directory:"));
1355
- assert!(text.text.contains("Total files:"));
1356
- assert!(text.text.contains("Total size:"));
1357
- assert!(text.text.contains("Available space:"));
1358
- }
1359
- _ => panic!("Expected text content"),
1360
- }
1361
- } else {
1362
- panic!("Expected content in result");
1363
- }
1364
- }
1365
-
1366
- #[tokio::test]
1367
- async fn test_cache_clear_returns_result() {
1368
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1369
-
1370
- let result = server.cache_clear(Parameters(()));
1371
-
1372
- assert!(result.is_ok());
1373
- let call_result = result.unwrap();
1374
- if let Some(content) = call_result.content.first() {
1375
- match &content.raw {
1376
- RawContent::Text(text) => {
1377
- assert!(text.text.contains("Cache cleared"));
1378
- assert!(text.text.contains("Directory:"));
1379
- assert!(text.text.contains("Removed files:"));
1380
- assert!(text.text.contains("Freed space:"));
1381
- }
1382
- _ => panic!("Expected text content"),
1383
- }
1384
- } else {
1385
- panic!("Expected content in result");
1386
- }
1387
- }
1388
-
1389
480
  #[test]
1390
481
  fn test_new_creates_server_with_default_config() {
1391
482
  let server = KreuzbergMcp::new();
@@ -1418,92 +509,6 @@ mod tests {
1418
509
  assert!(info.capabilities.tools.is_some());
1419
510
  }
1420
511
 
1421
- #[test]
1422
- fn test_build_config_preserves_default_config_settings() {
1423
- let default_config = ExtractionConfig {
1424
- use_cache: false,
1425
- ..Default::default()
1426
- };
1427
-
1428
- let config = build_config(&default_config, false, false);
1429
-
1430
- assert!(!config.use_cache);
1431
- }
1432
-
1433
- #[test]
1434
- fn test_build_config_ocr_disabled_by_default() {
1435
- let default_config = ExtractionConfig::default();
1436
-
1437
- let config = build_config(&default_config, false, false);
1438
-
1439
- assert!(config.ocr.is_none());
1440
- assert!(!config.force_ocr);
1441
- }
1442
-
1443
- #[test]
1444
- fn test_build_config_ocr_enabled_creates_tesseract_config() {
1445
- let default_config = ExtractionConfig::default();
1446
-
1447
- let config = build_config(&default_config, true, false);
1448
-
1449
- assert!(config.ocr.is_some());
1450
- let ocr_config = config.ocr.unwrap();
1451
- assert_eq!(ocr_config.backend, "tesseract");
1452
- assert_eq!(ocr_config.language, "eng");
1453
- }
1454
-
1455
- #[test]
1456
- fn test_extract_file_params_defaults() {
1457
- let json = r#"{"path": "/test.pdf"}"#;
1458
- let params: ExtractFileParams = serde_json::from_str(json).unwrap();
1459
-
1460
- assert_eq!(params.path, "/test.pdf");
1461
- assert_eq!(params.mime_type, None);
1462
- assert!(!params.enable_ocr);
1463
- assert!(!params.force_ocr);
1464
- assert!(!params.r#async);
1465
- }
1466
-
1467
- #[test]
1468
- fn test_extract_bytes_params_defaults() {
1469
- let json = r#"{"data": "SGVsbG8="}"#;
1470
- let params: ExtractBytesParams = serde_json::from_str(json).unwrap();
1471
-
1472
- assert_eq!(params.data, "SGVsbG8=");
1473
- assert_eq!(params.mime_type, None);
1474
- assert!(!params.enable_ocr);
1475
- assert!(!params.force_ocr);
1476
- assert!(!params.r#async);
1477
- }
1478
-
1479
- #[test]
1480
- fn test_batch_extract_files_params_defaults() {
1481
- let json = r#"{"paths": ["/a.pdf", "/b.pdf"]}"#;
1482
- let params: BatchExtractFilesParams = serde_json::from_str(json).unwrap();
1483
-
1484
- assert_eq!(params.paths.len(), 2);
1485
- assert!(!params.enable_ocr);
1486
- assert!(!params.force_ocr);
1487
- assert!(!params.r#async);
1488
- }
1489
-
1490
- #[test]
1491
- fn test_detect_mime_type_params_defaults() {
1492
- let json = r#"{"path": "/test.pdf"}"#;
1493
- let params: DetectMimeTypeParams = serde_json::from_str(json).unwrap();
1494
-
1495
- assert_eq!(params.path, "/test.pdf");
1496
- assert!(params.use_content);
1497
- }
1498
-
1499
- #[test]
1500
- fn test_detect_mime_type_params_use_content_false() {
1501
- let json = r#"{"path": "/test.pdf", "use_content": false}"#;
1502
- let params: DetectMimeTypeParams = serde_json::from_str(json).unwrap();
1503
-
1504
- assert!(!params.use_content);
1505
- }
1506
-
1507
512
  #[test]
1508
513
  fn test_mcp_server_info_protocol_version() {
1509
514
  let server = KreuzbergMcp::with_config(ExtractionConfig::default());
@@ -1643,6 +648,7 @@ mod tests {
1643
648
  backend: "tesseract".to_string(),
1644
649
  language: "spa".to_string(),
1645
650
  tesseract_config: None,
651
+ output_format: None,
1646
652
  }),
1647
653
  ..Default::default()
1648
654
  };
@@ -1666,234 +672,6 @@ mod tests {
1666
672
  assert_eq!(server1.default_config.force_ocr, server2.default_config.force_ocr);
1667
673
  }
1668
674
 
1669
- #[tokio::test]
1670
- async fn test_extract_bytes_with_empty_data() {
1671
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1672
-
1673
- let params = ExtractBytesParams {
1674
- data: String::new(),
1675
- mime_type: Some("text/plain".to_string()),
1676
- enable_ocr: false,
1677
- force_ocr: false,
1678
- r#async: true,
1679
- };
1680
-
1681
- let result = server.extract_bytes(Parameters(params)).await;
1682
-
1683
- assert!(result.is_ok() || result.is_err());
1684
- }
1685
-
1686
- #[tokio::test]
1687
- async fn test_extract_bytes_with_valid_pdf_bytes() {
1688
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1689
-
1690
- let pdf_path = get_test_path("pdfs_with_tables/tiny.pdf");
1691
-
1692
- if std::path::Path::new(&pdf_path).exists() {
1693
- let pdf_bytes = std::fs::read(&pdf_path).unwrap();
1694
- let encoded = BASE64_STANDARD.encode(&pdf_bytes);
1695
-
1696
- let params = ExtractBytesParams {
1697
- data: encoded,
1698
- mime_type: Some("application/pdf".to_string()),
1699
- enable_ocr: false,
1700
- force_ocr: false,
1701
- r#async: true,
1702
- };
1703
-
1704
- let result = server.extract_bytes(Parameters(params)).await;
1705
-
1706
- assert!(result.is_ok(), "PDF bytes extraction should succeed");
1707
- let call_result = result.unwrap();
1708
- assert!(!call_result.content.is_empty());
1709
- }
1710
- }
1711
-
1712
- #[tokio::test]
1713
- async fn test_extract_bytes_mime_type_auto_detection() {
1714
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1715
-
1716
- let text_content = b"Plain text content for testing";
1717
- let encoded = BASE64_STANDARD.encode(text_content);
1718
-
1719
- let params = ExtractBytesParams {
1720
- data: encoded,
1721
- mime_type: None,
1722
- enable_ocr: false,
1723
- force_ocr: false,
1724
- r#async: true,
1725
- };
1726
-
1727
- let result = server.extract_bytes(Parameters(params)).await;
1728
-
1729
- assert!(result.is_ok() || result.is_err());
1730
- }
1731
-
1732
- #[tokio::test]
1733
- async fn test_batch_extract_preserves_file_order() {
1734
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1735
-
1736
- let file1 = get_test_path("pdfs_with_tables/tiny.pdf");
1737
- let file2 = get_test_path("pdfs_with_tables/medium.pdf");
1738
-
1739
- if std::path::Path::new(&file1).exists() && std::path::Path::new(&file2).exists() {
1740
- let params = BatchExtractFilesParams {
1741
- paths: vec![file1.to_string(), file2.to_string()],
1742
- enable_ocr: false,
1743
- force_ocr: false,
1744
- r#async: true,
1745
- };
1746
-
1747
- let result = server.batch_extract_files(Parameters(params)).await;
1748
-
1749
- if let Ok(call_result) = result
1750
- && let Some(content) = call_result.content.first()
1751
- && let RawContent::Text(text) = &content.raw
1752
- {
1753
- assert!(text.text.contains("Document 1"));
1754
- assert!(text.text.contains("Document 2"));
1755
-
1756
- let doc1_pos = text.text.find("Document 1");
1757
- let doc2_pos = text.text.find("Document 2");
1758
- if let (Some(pos1), Some(pos2)) = (doc1_pos, doc2_pos) {
1759
- assert!(pos1 < pos2, "Documents should be in order");
1760
- }
1761
- }
1762
- }
1763
- }
1764
-
1765
- #[tokio::test]
1766
- async fn test_cache_clear_is_idempotent() {
1767
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1768
-
1769
- let result1 = server.cache_clear(Parameters(()));
1770
- assert!(result1.is_ok());
1771
-
1772
- let result2 = server.cache_clear(Parameters(()));
1773
- assert!(result2.is_ok());
1774
- }
1775
-
1776
- #[tokio::test]
1777
- async fn test_cache_clear_returns_metrics() {
1778
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1779
-
1780
- let result = server.cache_clear(Parameters(()));
1781
-
1782
- assert!(result.is_ok());
1783
- let call_result = result.unwrap();
1784
- if let Some(content) = call_result.content.first()
1785
- && let RawContent::Text(text) = &content.raw
1786
- {
1787
- assert!(text.text.contains("Removed files:"));
1788
- assert!(text.text.contains("Freed space:"));
1789
- }
1790
- }
1791
-
1792
- #[test]
1793
- fn test_error_mapping_preserves_error_context() {
1794
- let validation_error = KreuzbergError::validation("invalid file path");
1795
- let mcp_error = map_kreuzberg_error_to_mcp(validation_error);
1796
-
1797
- assert!(mcp_error.message.contains("invalid file path"));
1798
- }
1799
-
1800
- #[test]
1801
- fn test_io_errors_bubble_up_as_internal() {
1802
- // OSError/RuntimeError must bubble up - system errors need user reports ~keep
1803
- let io_error = std::io::Error::new(std::io::ErrorKind::PermissionDenied, "access denied");
1804
- let kreuzberg_error = KreuzbergError::Io(io_error);
1805
- let mcp_error = map_kreuzberg_error_to_mcp(kreuzberg_error);
1806
-
1807
- assert_eq!(mcp_error.code.0, -32603);
1808
- assert!(mcp_error.message.contains("System I/O error"));
1809
- }
1810
-
1811
- #[test]
1812
- fn test_all_error_variants_have_mappings() {
1813
- let errors = vec![
1814
- KreuzbergError::validation("test"),
1815
- KreuzbergError::UnsupportedFormat("test/unknown".to_string()),
1816
- KreuzbergError::MissingDependency("test-dep".to_string()),
1817
- KreuzbergError::parsing("test"),
1818
- KreuzbergError::Io(std::io::Error::other("test")),
1819
- KreuzbergError::ocr("test"),
1820
- KreuzbergError::cache("test"),
1821
- KreuzbergError::image_processing("test"),
1822
- KreuzbergError::serialization("test"),
1823
- KreuzbergError::Plugin {
1824
- message: "test".to_string(),
1825
- plugin_name: "test-plugin".to_string(),
1826
- },
1827
- KreuzbergError::LockPoisoned("test".to_string()),
1828
- KreuzbergError::Other("test".to_string()),
1829
- ];
1830
-
1831
- for error in errors {
1832
- let mcp_error = map_kreuzberg_error_to_mcp(error);
1833
-
1834
- assert!(mcp_error.code.0 < 0, "Error code should be negative");
1835
-
1836
- assert!(!mcp_error.message.is_empty());
1837
- }
1838
- }
1839
-
1840
- #[tokio::test]
1841
- async fn test_response_includes_metadata() {
1842
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1843
-
1844
- let test_file = get_test_path("pdfs_with_tables/tiny.pdf");
1845
-
1846
- if std::path::Path::new(&test_file).exists() {
1847
- let params = ExtractFileParams {
1848
- path: test_file.to_string(),
1849
- mime_type: None,
1850
- enable_ocr: false,
1851
- force_ocr: false,
1852
- r#async: true,
1853
- };
1854
-
1855
- let result = server.extract_file(Parameters(params)).await;
1856
-
1857
- assert!(result.is_ok());
1858
- let call_result = result.unwrap();
1859
-
1860
- if let Some(content) = call_result.content.first()
1861
- && let RawContent::Text(text) = &content.raw
1862
- {
1863
- assert!(text.text.contains("Metadata:"));
1864
- }
1865
- }
1866
- }
1867
-
1868
- #[tokio::test]
1869
- async fn test_response_includes_content_length() {
1870
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
1871
-
1872
- let test_file = get_test_path("pdfs_with_tables/tiny.pdf");
1873
-
1874
- if std::path::Path::new(&test_file).exists() {
1875
- let params = ExtractFileParams {
1876
- path: test_file.to_string(),
1877
- mime_type: None,
1878
- enable_ocr: false,
1879
- force_ocr: false,
1880
- r#async: true,
1881
- };
1882
-
1883
- let result = server.extract_file(Parameters(params)).await;
1884
-
1885
- assert!(result.is_ok());
1886
- let call_result = result.unwrap();
1887
-
1888
- if let Some(content) = call_result.content.first()
1889
- && let RawContent::Text(text) = &content.raw
1890
- {
1891
- assert!(text.text.contains("characters"));
1892
- assert!(text.text.contains("Content"));
1893
- }
1894
- }
1895
- }
1896
-
1897
675
  #[tokio::test]
1898
676
  async fn test_server_is_thread_safe() {
1899
677
  let server = KreuzbergMcp::with_config(ExtractionConfig::default());
@@ -1910,181 +688,4 @@ mod tests {
1910
688
 
1911
689
  assert_eq!(info1.server_info.name, info2.server_info.name);
1912
690
  }
1913
-
1914
- #[test]
1915
- fn test_extract_file_params_serialization() {
1916
- let params = ExtractFileParams {
1917
- path: "/test.pdf".to_string(),
1918
- mime_type: Some("application/pdf".to_string()),
1919
- enable_ocr: true,
1920
- force_ocr: false,
1921
- r#async: true,
1922
- };
1923
-
1924
- let json = serde_json::to_string(&params).unwrap();
1925
- let deserialized: ExtractFileParams = serde_json::from_str(&json).unwrap();
1926
-
1927
- assert_eq!(params.path, deserialized.path);
1928
- assert_eq!(params.mime_type, deserialized.mime_type);
1929
- assert_eq!(params.enable_ocr, deserialized.enable_ocr);
1930
- assert_eq!(params.force_ocr, deserialized.force_ocr);
1931
- assert_eq!(params.r#async, deserialized.r#async);
1932
- }
1933
-
1934
- #[test]
1935
- fn test_extract_bytes_params_serialization() {
1936
- let params = ExtractBytesParams {
1937
- data: "SGVsbG8=".to_string(),
1938
- mime_type: None,
1939
- enable_ocr: false,
1940
- force_ocr: false,
1941
- r#async: false,
1942
- };
1943
-
1944
- let json = serde_json::to_string(&params).unwrap();
1945
- let deserialized: ExtractBytesParams = serde_json::from_str(&json).unwrap();
1946
-
1947
- assert_eq!(params.data, deserialized.data);
1948
- }
1949
-
1950
- #[test]
1951
- fn test_batch_extract_params_serialization() {
1952
- let params = BatchExtractFilesParams {
1953
- paths: vec!["/a.pdf".to_string(), "/b.pdf".to_string()],
1954
- enable_ocr: true,
1955
- force_ocr: true,
1956
- r#async: true,
1957
- };
1958
-
1959
- let json = serde_json::to_string(&params).unwrap();
1960
- let deserialized: BatchExtractFilesParams = serde_json::from_str(&json).unwrap();
1961
-
1962
- assert_eq!(params.paths, deserialized.paths);
1963
- assert_eq!(params.enable_ocr, deserialized.enable_ocr);
1964
- }
1965
-
1966
- #[test]
1967
- fn test_detect_mime_type_params_serialization() {
1968
- let params = DetectMimeTypeParams {
1969
- path: "/test.pdf".to_string(),
1970
- use_content: false,
1971
- };
1972
-
1973
- let json = serde_json::to_string(&params).unwrap();
1974
- let deserialized: DetectMimeTypeParams = serde_json::from_str(&json).unwrap();
1975
-
1976
- assert_eq!(params.path, deserialized.path);
1977
- assert_eq!(params.use_content, deserialized.use_content);
1978
- }
1979
-
1980
- #[tokio::test]
1981
- async fn test_extract_file_respects_custom_default_config() {
1982
- let custom_config = ExtractionConfig {
1983
- use_cache: false,
1984
- ..Default::default()
1985
- };
1986
-
1987
- let server = KreuzbergMcp::with_config(custom_config);
1988
-
1989
- let test_file = get_test_path("pdfs_with_tables/tiny.pdf");
1990
-
1991
- if std::path::Path::new(&test_file).exists() {
1992
- let params = ExtractFileParams {
1993
- path: test_file.to_string(),
1994
- mime_type: None,
1995
- enable_ocr: false,
1996
- force_ocr: false,
1997
- r#async: true,
1998
- };
1999
-
2000
- let result = server.extract_file(Parameters(params)).await;
2001
-
2002
- assert!(result.is_ok() || result.is_err());
2003
- }
2004
- }
2005
-
2006
- #[tokio::test]
2007
- async fn test_batch_extract_with_single_file() {
2008
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
2009
-
2010
- let test_file = get_test_path("pdfs_with_tables/tiny.pdf");
2011
-
2012
- if std::path::Path::new(&test_file).exists() {
2013
- let params = BatchExtractFilesParams {
2014
- paths: vec![test_file.to_string()],
2015
- enable_ocr: false,
2016
- force_ocr: false,
2017
- r#async: true,
2018
- };
2019
-
2020
- let result = server.batch_extract_files(Parameters(params)).await;
2021
-
2022
- assert!(result.is_ok());
2023
- let call_result = result.unwrap();
2024
- assert!(!call_result.content.is_empty());
2025
- }
2026
- }
2027
-
2028
- #[tokio::test]
2029
- async fn test_detect_mime_type_with_extension_only() {
2030
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
2031
-
2032
- let test_file = get_test_path("pdfs_with_tables/tiny.pdf");
2033
-
2034
- if std::path::Path::new(&test_file).exists() {
2035
- let params = DetectMimeTypeParams {
2036
- path: test_file.to_string(),
2037
- use_content: false,
2038
- };
2039
-
2040
- let result = server.detect_mime_type(Parameters(params));
2041
-
2042
- assert!(result.is_ok());
2043
- let call_result = result.unwrap();
2044
- if let Some(content) = call_result.content.first()
2045
- && let RawContent::Text(text) = &content.raw
2046
- {
2047
- assert!(text.text.contains("pdf") || text.text.contains("PDF"));
2048
- }
2049
- }
2050
- }
2051
-
2052
- #[tokio::test]
2053
- async fn test_detect_mime_type_with_content_analysis() {
2054
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
2055
-
2056
- let test_file = get_test_path("pdfs_with_tables/tiny.pdf");
2057
-
2058
- if std::path::Path::new(&test_file).exists() {
2059
- let params = DetectMimeTypeParams {
2060
- path: test_file.to_string(),
2061
- use_content: true,
2062
- };
2063
-
2064
- let result = server.detect_mime_type(Parameters(params));
2065
-
2066
- assert!(result.is_ok());
2067
- }
2068
- }
2069
-
2070
- #[tokio::test]
2071
- async fn test_cache_stats_returns_valid_data() {
2072
- let server = KreuzbergMcp::with_config(ExtractionConfig::default());
2073
-
2074
- let result = server.cache_stats(Parameters(()));
2075
-
2076
- assert!(result.is_ok());
2077
- let call_result = result.unwrap();
2078
- if let Some(content) = call_result.content.first()
2079
- && let RawContent::Text(text) = &content.raw
2080
- {
2081
- assert!(text.text.contains("Cache Statistics"));
2082
- assert!(text.text.contains("Directory:"));
2083
- assert!(text.text.contains("Total files:"));
2084
- assert!(text.text.contains("Total size:"));
2085
- assert!(text.text.contains("Available space:"));
2086
- assert!(text.text.contains("Oldest file age:"));
2087
- assert!(text.text.contains("Newest file age:"));
2088
- }
2089
- }
2090
691
  }