doc-to-text
Convert documents from various formats to plain text for content processing and knowledge management. Extract text from URLs or base64 files with page range selection.
Instructions
Convert various document formats to plain text.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputMethod | Yes | Input method | |
| file | Yes | URL or base64-encoded file content | |
| pages | No | Pages to process (e.g., '1, 2-5') |
Implementation Reference
- src/index.ts:529-544 (handler)The handler function for the 'doc-to-text' tool. It proxies the request to the external Dumpling AI API at /api/v1/doc-to-text, authenticates with DUMPLING_API_KEY, and returns the API response as text content.async ({ inputMethod, file, pages }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch(`${NWS_API_BASE}/api/v1/doc-to-text`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ inputMethod, file, pages }), }); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; }
- src/index.ts:524-528 (schema)Zod input schema for the 'doc-to-text' tool, defining parameters: inputMethod (url or base64), file (URL or base64 content), and optional pages.{ inputMethod: z.enum(["url", "base64"]).describe("Input method"), file: z.string().describe("URL or base64-encoded file content"), pages: z.string().optional().describe("Pages to process (e.g., '1, 2-5')"), },
- src/index.ts:521-545 (registration)Registration of the 'doc-to-text' MCP tool using McpServer.tool(), specifying name, description, input schema, and handler function.server.tool( "doc-to-text", "Convert various document formats to plain text.", { inputMethod: z.enum(["url", "base64"]).describe("Input method"), file: z.string().describe("URL or base64-encoded file content"), pages: z.string().optional().describe("Pages to process (e.g., '1, 2-5')"), }, async ({ inputMethod, file, pages }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch(`${NWS_API_BASE}/api/v1/doc-to-text`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ inputMethod, file, pages }), }); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } );