// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { Metadata, asTextContentResult } from 'chunkr-ai-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import Chunkr from 'chunkr-ai'; export const metadata: Metadata = { resource: 'tasks.parse', operation: 'write', tags: [], httpMethod: 'post', httpPath: '/tasks/parse', operationId: 'create_parse_task_route', }; export const tool: Tool = { name: 'create_tasks_parse', description: 'Queues a document for processing and returns a `TaskResponse` with the\nassigned `task_id`, initial configuration, file metadata, and timestamps.\nThe initial status is `Starting`.\n\nCreates a parse task and returns its metadata immediately.', inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'The file to be parsed. Supported inputs:\n- `ch://files/{file_id}`: Reference to an existing file. Upload via the Files API\n- `http(s)://...`: Remote URL to fetch\n- `data:*;base64,...` or raw base64 string', }, chunk_processing: { $ref: '#/$defs/chunk_processing', }, error_handling: { type: 'string', description: 'Controls how errors are handled during processing:\n- `Fail`: Stops processing and fails the task when any error occurs\n- `Continue`: Attempts to continue processing despite non-critical errors (eg. LLM refusals etc.)', enum: ['Fail', 'Continue'], }, expires_in: { type: 'integer', description: 'The number of seconds until task is deleted.\nExpired tasks can **not** be updated, polled or accessed via web interface.', }, file_name: { type: 'string', description: 'The name of the file to be parsed. If not set a name will be generated.', }, ocr_strategy: { type: 'string', description: 'Controls the Optical Character Recognition (OCR) strategy.\n- `All`: Processes all pages with OCR. (Latency penalty: ~0.5 seconds per page)\n- `Auto`: Selectively applies OCR only to pages with missing or low-quality text. When text layer is present the bounding boxes from the text layer are used.', enum: ['All', 'Auto'], }, pipeline: { type: 'string', enum: ['Azure', 'Chunkr'], }, segment_processing: { $ref: '#/$defs/segment_processing', }, segmentation_strategy: { type: 'string', description: 'Controls the segmentation strategy:\n- `LayoutAnalysis`: Analyzes pages for layout elements (e.g., `Table`, `Picture`, `Formula`, etc.) using bounding boxes. Provides fine-grained segmentation and better chunking.\n- `Page`: Treats each page as a single segment. Faster processing, but without layout element detection and only simple chunking.', enum: ['LayoutAnalysis', 'Page'], }, }, required: ['file'], $defs: { chunk_processing: { type: 'object', description: 'Controls the setting for the chunking and post-processing of each chunk.', properties: { ignore_headers_and_footers: { type: 'boolean', description: 'DEPRECATED: use `segment_processing.ignore` instead', }, target_length: { type: 'integer', description: 'The target number of words in each chunk. If 0, each chunk will contain a single segment.', }, tokenizer: { anyOf: [ { type: 'object', title: 'Enum', description: 'Use one of the predefined tokenizer types', properties: { Enum: { type: 'string', description: 'Use one of the predefined tokenizer types', enum: ['Word', 'Cl100kBase', 'XlmRobertaBase', 'BertBaseUncased'], }, }, required: ['Enum'], }, { type: 'object', title: 'String', description: 'Use any Hugging Face tokenizer by specifying its model ID\nExamples: "Qwen/Qwen-tokenizer", "facebook/bart-large"', properties: { String: { type: 'string', description: 'Use any Hugging Face tokenizer by specifying its model ID\nExamples: "Qwen/Qwen-tokenizer", "facebook/bart-large"', }, }, required: ['String'], }, ], description: 'The tokenizer to use for the chunking process.', }, }, }, segment_processing: { type: 'object', description: 'Configuration for how each document segment is processed and formatted.\n\nEach segment has sensible defaults, but you can override specific settings:\n- `format`: Output as `Html` or `Markdown`\n- `strategy`: `Auto` (rule-based), `LLM` (AI-generated), or `Ignore` (skip)\n- `crop_image`: Whether to crop images to segment bounds\n- `extended_context`: Use full page as context for LLM processing\n- `description`: Generate descriptions for segments\n\n**Defaults per segment type:** Check the documentation for more details.\n\nOnly specify the fields you want to change - everything else uses the defaults.', properties: { Caption: { $ref: '#/$defs/generation_config', }, Footnote: { $ref: '#/$defs/generation_config', }, FormRegion: { $ref: '#/$defs/generation_config', }, Formula: { $ref: '#/$defs/generation_config', }, GraphicalItem: { $ref: '#/$defs/generation_config', }, Legend: { $ref: '#/$defs/generation_config', }, LineNumber: { $ref: '#/$defs/generation_config', }, ListItem: { $ref: '#/$defs/generation_config', }, Page: { $ref: '#/$defs/generation_config', }, PageFooter: { $ref: '#/$defs/generation_config', }, PageHeader: { $ref: '#/$defs/generation_config', }, PageNumber: { $ref: '#/$defs/generation_config', }, Picture: { $ref: '#/$defs/generation_config', }, Table: { $ref: '#/$defs/generation_config', }, Text: { $ref: '#/$defs/generation_config', }, Title: { $ref: '#/$defs/generation_config', }, Unknown: { $ref: '#/$defs/generation_config', }, }, }, generation_config: { type: 'object', description: "Controls the processing and generation for the segment.\n- `crop_image` controls whether to crop the file's images to the segment's bounding box.\n The cropped image will be stored in the segment's `image` field. Use `All` to always crop,\n or `Auto` to only crop when needed for post-processing.\n- `format` specifies the output format: `Html` or `Markdown`\n- `strategy` determines how the content is generated: `Auto`, `LLM`, or `Ignore`\n - `Auto`: Process content automatically\n - `LLM`: Use large language models for processing\n - `Ignore`: Exclude segments from final output\n- `description` enables LLM-generated descriptions for segments.\n **Note:** This uses chunkr's own VLM models and is not configurable via LLM processing configuration.\n- `extended_context` uses the full page image as context for LLM generation.", properties: { crop_image: { type: 'string', description: 'Controls the cropping strategy for an item (e.g. segment, chunk, etc.)\n- `All` crops all images in the item\n- `Auto` crops images only if required for post-processing', enum: ['All', 'Auto'], }, description: { type: 'boolean', description: 'Generate LLM descriptions for this segment', }, extended_context: { type: 'boolean', description: 'Use the full page image as context for LLM generation', }, format: { type: 'string', description: 'The format for the `content` field of a segment.', enum: ['Html', 'Markdown'], }, llm: { type: 'string', }, strategy: { type: 'string', description: 'The strategy for generating the `content` field of a segment.', enum: ['LLM', 'Auto', 'Ignore'], }, }, }, }, }, annotations: {}, }; export const handler = async (client: Chunkr, args: Record | undefined) => { const body = args as any; return asTextContentResult(await client.tasks.parse.create(body)); }; export default { metadata, tool, handler };