yuque_create_doc
Create new documents in Yuque knowledge bases using markdown, lake, or HTML formats to organize and share information.
Instructions
创建新文档 (Create new document)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repoId | Yes | 知识库ID (Repository ID) | |
| title | Yes | 文档标题 (Document title) | |
| content | Yes | 文档内容 (Document content) | |
| format | No | 文档格式,默认markdown (Document format, default markdown) |
Implementation Reference
- src/tools/handlers.ts:160-183 (handler)The specific handler function for yuque_create_doc that calls YuqueClient.createDoc and returns the created document as JSON text content.async function handleCreateDoc( client: YuqueClient, args: { repoId: number; title: string; content: string; format?: 'markdown' | 'lake' | 'html'; } ) { const doc = await client.createDoc( args.repoId, args.title, args.content, args.format ); return { content: [ { type: 'text', text: JSON.stringify(doc, null, 2), }, ], }; }
- src/tools/definitions.ts:76-105 (schema)Tool definition including name, description, and input schema validation for yuque_create_doc.{ name: 'yuque_create_doc', description: '创建新文档 (Create new document)', inputSchema: { type: 'object', properties: { repoId: { type: 'number', description: '知识库ID (Repository ID)', }, title: { type: 'string', description: '文档标题 (Document title)', minLength: 1, maxLength: 200, }, content: { type: 'string', description: '文档内容 (Document content)', minLength: 1, }, format: { type: 'string', enum: ['markdown', 'lake', 'html'], description: '文档格式,默认markdown (Document format, default markdown)', }, }, required: ['repoId', 'title', 'content'], }, },
- src/tools/handlers.ts:42-51 (registration)Registration of the tool name in the main switch dispatcher within handleTool function.case 'yuque_create_doc': return await handleCreateDoc( client, args as { repoId: number; title: string; content: string; format?: 'markdown' | 'lake' | 'html'; } );
- src/yuque-client.ts:190-205 (helper)Core utility function in YuqueClient that performs the actual HTTP POST request to create a document in Yuque, including slug generation.async createDoc( repoId: number, title: string, content: string, format: 'markdown' | 'lake' | 'html' = 'markdown' ): Promise<YuqueDoc> { return this.request<YuqueDoc>(`/repos/${repoId}/docs`, { method: 'POST', data: { title, slug: this.generateSlug(title), body: content, format, }, }); }
- src/server.ts:53-67 (registration)Registers the handleTool function as the MCP CallToolRequest handler in the server.server.setRequestHandler(CallToolRequestSchema, async (request) => { try { return await handleTool(request, { client: yuqueClient }); } catch (error) { if (error instanceof McpError) { throw error; } const errorMessage = error instanceof Error ? error.message : String(error); throw new McpError( ErrorCode.InternalError, `Error executing tool: ${errorMessage}` ); } });