get_user_docs
Retrieve a complete list of your Yuque knowledge base documents, including both private and collaborative workspaces, to manage and access your content efficiently.
Instructions
获取当前用户的所有知识库文档列表,包括私人和协作文档
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accessToken | No | 用于认证 API 请求的令牌 |
Implementation Reference
- src/server.ts:168-187 (handler)The MCP tool handler function for 'get_user_docs'. It creates a YuqueService instance and calls getUserDocs() to fetch the user's documents, then returns them as a JSON string in the MCP content format. Handles errors appropriately.async ({ accessToken }) => { try { Logger.log("Fetching user's documents"); const yuqueService = this.createYuqueService(accessToken); const docs = await yuqueService.getUserDocs(); Logger.log(`Successfully fetched ${docs.length} documents`); return { content: [{ type: "text", text: JSON.stringify(docs) }], }; } catch (error) { Logger.error("Error fetching user docs:", error); return { content: [ { type: "text", text: `Error fetching user docs: ${error}` }, ], }; } } );
- src/server.ts:165-167 (schema)Input schema for the get_user_docs tool, defined using Zod. The only parameter is an optional accessToken for authentication.{ accessToken: z.string().optional().describe("用于认证 API 请求的令牌"), },
- src/server.ts:162-187 (registration)Registration of the 'get_user_docs' tool on the McpServer using server.tool(name, description, inputSchema, handler). This is where the tool is made available in the MCP protocol.this.server.tool( "get_user_docs", "获取当前用户的所有知识库文档列表,包括私人和协作文档", { accessToken: z.string().optional().describe("用于认证 API 请求的令牌"), }, async ({ accessToken }) => { try { Logger.log("Fetching user's documents"); const yuqueService = this.createYuqueService(accessToken); const docs = await yuqueService.getUserDocs(); Logger.log(`Successfully fetched ${docs.length} documents`); return { content: [{ type: "text", text: JSON.stringify(docs) }], }; } catch (error) { Logger.error("Error fetching user docs:", error); return { content: [ { type: "text", text: `Error fetching user docs: ${error}` }, ], }; } } );
- src/services/yuque.ts:219-222 (helper)Helper method in YuqueService that performs the actual API call to Yuque's /user/docs endpoint to retrieve the list of user documents.async getUserDocs(): Promise<YuqueDoc[]> { const response = await this.client.get('/user/docs'); return response.data.data; }
- src/services/yuque.ts:45-72 (schema)TypeScript interface definition for YuqueDoc, which defines the structure of documents returned by getUserDocs.export interface YuqueDoc { id: number; slug: string; title: string; description: string; user_id: number; book_id: number; format: string; public: number; status: number; likes_count: number; read_count?: number; comments_count: number; content_updated_at: string; created_at: string; updated_at: string; published_at?: string; first_published_at?: string; word_count: number; body?: string; body_html?: string; body_lake?: string; body_draft?: string; book?: YuqueRepo; user?: YuqueUser; last_editor?: YuqueUser; creator?: YuqueUser; }