get_items_by_user
Retrieve articles written by a specific Qiita user. Provide the user ID to access their published content with pagination support for browsing multiple pages.
Instructions
Get articles written by a specific user.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | User ID | |
| page | No | Page number (1-100, default: 1) | |
| per_page | No | Items per page (1-100, default: 20) |
Implementation Reference
- src/index.ts:79-90 (handler)Core handler function in QiitaClient that fetches and returns Qiita items authored by a specific user via the API.async getItemsByUser( userId: string, page: number = 1, perPage: number = 20 ): Promise<any[]> { const params = new URLSearchParams({ page: page.toString(), per_page: perPage.toString(), }); return this.fetch(`/users/${userId}/items?${params.toString()}`); }
- src/index.ts:195-216 (schema)Input schema definition for the get_items_by_user tool, specifying parameters and validation.inputSchema: { type: "object", properties: { user_id: { type: "string", description: "User ID", }, page: { type: "number", description: "Page number (1-100, default: 1)", minimum: 1, maximum: 100, }, per_page: { type: "number", description: "Items per page (1-100, default: 20)", minimum: 1, maximum: 100, }, }, required: ["user_id"], },
- src/index.ts:192-217 (registration)Tool registration in the tools array, defining name, description, and schema for list tools response.{ name: "get_items_by_user", description: "Get articles written by a specific user.", inputSchema: { type: "object", properties: { user_id: { type: "string", description: "User ID", }, page: { type: "number", description: "Page number (1-100, default: 1)", minimum: 1, maximum: 100, }, per_page: { type: "number", description: "Items per page (1-100, default: 20)", minimum: 1, maximum: 100, }, }, required: ["user_id"], }, },
- src/index.ts:348-360 (handler)Dispatch handler in the CallToolRequestSchema handler that validates input and calls the QiitaClient method for get_items_by_user.case "get_items_by_user": { if (!args?.user_id) { throw new Error("user_id is required"); } const result = await qiitaClient.getItemsByUser( args.user_id as string, args?.page as number | undefined, args?.per_page as number | undefined ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }
- src/index.ts:24-43 (helper)Helper fetch method used by QiitaClient methods to make authenticated API requests to Qiita.private async fetch(endpoint: string): Promise<any> { const headers: HeadersInit = { "Content-Type": "application/json", }; if (this.accessToken) { headers["Authorization"] = `Bearer ${this.accessToken}`; } const response = await fetch(`${this.baseUrl}${endpoint}`, { headers }); if (!response.ok) { const errorBody = await response.text(); throw new Error( `Qiita API error: ${response.status} ${response.statusText} - ${errorBody}` ); } return response.json(); }