Skip to main content
Glama

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
NameRequiredDescriptionDefault
user_idYesUser ID
pageNoPage number (1-100, default: 1)
per_pageNoItems per page (1-100, default: 20)

Implementation Reference

  • 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()}`);
    }
  • 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"],
      },
    },
  • 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) }],
      };
    }
  • 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();
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ningen/qiita-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server