yuque_create_doc
Create new documents in Yuque knowledge bases by specifying repository ID, title, content, and format to organize and share knowledge effectively.
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-182 (handler)Executes the yuque_create_doc tool by invoking YuqueClient.createDoc with provided arguments and formats the response as MCP 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)Switch case in the main tool dispatcher (handleTool) that registers and routes yuque_create_doc to its handler 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 API implementation in YuqueClient that performs the HTTP POST request to create a document in Yuque.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:46-67 (registration)MCP server request handlers for listing tools (using definitions) and executing tools (dispatching to handlers.ts). This registers all tools including yuque_create_doc.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: YUQUE_TOOLS, }; }); // Handle tool execution requests 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}` ); } });