doc-to-text
Convert documents in various formats to plain text for easy text extraction and processing. Supports URLs or base64 file input and customizable page selection.
Instructions
Convert various document formats to plain text.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | URL or base64-encoded file content | |
| inputMethod | Yes | Input method | |
| pages | No | Pages to process (e.g., '1, 2-5') |
Implementation Reference
- src/index.ts:521-545 (registration)Registration of the 'doc-to-text' MCP tool, including description, input schema, and handler function that proxies requests to an external API.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) }] }; } );
- src/index.ts:529-544 (handler)The handler function for 'doc-to-text' tool: checks for API key, sends POST request to external doc-to-text endpoint with parameters, handles errors, and returns JSON-stringified response wrapped in MCP content format.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 schema defining inputs for the 'doc-to-text' tool: inputMethod (url or base64), required file (URL or base64), optional pages specifier.{ 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')"), },