create_document
Creates a new markdown document in Unmarkdown, allowing you to set title, content, folder, template, and theme for generating styled documents ready to publish.
Instructions
Create a new markdown document in Unmarkdown
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | No | Document title | |
| content | No | Markdown content (default: empty) | |
| folder | No | Folder name (case-insensitive) or folder ID to place the document in | |
| template_id | No | Visual template ID (default: "swiss") | |
| theme_mode | No | Color theme (default: "light") |
Implementation Reference
- src/tools.ts:112-126 (handler)The handler function for create_document that sends a POST request to /v1/documents with optional title, content, folder, template_id, and theme_mode parameters.
async ({ title, content, folder, template_id, theme_mode }) => { try { const body: Record<string, unknown> = {}; if (title) body.title = title; if (content) body.content = content; if (folder) body.folder = folder; if (template_id) body.template_id = template_id; if (theme_mode) body.theme_mode = theme_mode; const result = await client.request("POST", "/v1/documents", body); return jsonResult(result); } catch (err) { return errorResult(err); } }, ); - src/tools.ts:86-103 (schema)Zod schema defining the input parameters for create_document: title, content, folder, template_id, and theme_mode (all optional).
{ title: z.string().optional().describe("Document title"), content: z .string() .optional() .describe("Markdown content (default: empty)"), folder: z .string() .optional() .describe("Folder name (case-insensitive) or folder ID to place the document in"), template_id: z .string() .optional() .describe('Visual template ID (default: "swiss")'), theme_mode: z .enum(["light", "dark"]) .optional() .describe('Color theme (default: "light")'), - src/tools.ts:83-126 (registration)Registration of create_document on the McpServer via server.tool(), with name, description, schema, metadata hints, and handler.
server.tool( "create_document", "Create a new markdown document in Unmarkdown", { title: z.string().optional().describe("Document title"), content: z .string() .optional() .describe("Markdown content (default: empty)"), folder: z .string() .optional() .describe("Folder name (case-insensitive) or folder ID to place the document in"), template_id: z .string() .optional() .describe('Visual template ID (default: "swiss")'), theme_mode: z .enum(["light", "dark"]) .optional() .describe('Color theme (default: "light")'), }, { title: "Create Document", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true, }, async ({ title, content, folder, template_id, theme_mode }) => { try { const body: Record<string, unknown> = {}; if (title) body.title = title; if (content) body.content = content; if (folder) body.folder = folder; if (template_id) body.template_id = template_id; if (theme_mode) body.theme_mode = theme_mode; const result = await client.request("POST", "/v1/documents", body); return jsonResult(result); } catch (err) { return errorResult(err); } }, ); - src/tools.ts:24-30 (helper)Helper function used by create_document handler to wrap the API response as a JSON text result.
function jsonResult(data: unknown) { return { content: [ { type: "text" as const, text: JSON.stringify(data, null, 2) }, ], }; } - src/tools.ts:5-22 (helper)Helper function used by create_document handler to format error responses.
function errorResult(err: unknown) { if (err instanceof ApiError) { return { content: [ { type: "text" as const, text: `Error ${err.status} (${err.code}): ${err.message}`, }, ], isError: true, }; } const message = err instanceof Error ? err.message : String(err); return { content: [{ type: "text" as const, text: `Error: ${message}` }], isError: true, }; }