is_item_stocked
Check if a specific Qiita article has been stocked by users to monitor content popularity and engagement on the Japanese developer platform.
Instructions
指定された記事がストックされているかどうかを確認します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| itemId | Yes | 記事ID |
Implementation Reference
- src/tools/handlers.ts:116-119 (handler)The handler definition for the 'is_item_stocked' tool. It uses itemIdSchema for input validation and delegates execution to the QiitaApiClient's isItemStocked method.is_item_stocked: { schema: itemIdSchema, execute: async ({ itemId }, client) => client.isItemStocked(itemId), },
- src/tools/definitions.ts:320-333 (schema)MCP tool definition providing the name, description, and input schema for 'is_item_stocked' used in ListTools response.{ name: 'is_item_stocked', description: '指定された記事がストックされているかどうかを確認します', inputSchema: { type: 'object', properties: { itemId: { type: 'string', description: '記事ID', }, }, required: ['itemId'], }, },
- src/qiitaApiClient.ts:117-128 (helper)Core logic implementation in QiitaApiClient that checks if the item is stocked by the authenticated user via a GET request to the stock endpoint, interpreting 404 as not stocked.async isItemStocked(itemId: string) { this.assertAuthenticated(); try { await this.client.get(`/items/${itemId}/stock`); return { stocked: true }; } catch (error: any) { if (error.response?.status === 404) { return { stocked: false }; } throw error; } }
- src/index.ts:30-65 (registration)MCP server request handler for CallToolRequestSchema that retrieves the handler from toolHandlers by name, parses arguments, executes the handler, and returns the result.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; const accessToken = process.env.QIITA_ACCESS_TOKEN; const qiita = new QiitaApiClient(accessToken); const handler = toolHandlers[name]; try { if (!handler) { throw new Error(`未知のツール: ${name}`); } const parsedArgs = handler.schema.parse(args ?? {}); const result = await handler.execute(parsedArgs, qiita); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error: any) { const message = error?.message ?? String(error); return { content: [ { type: 'text', text: `エラーが発生しました: ${message}`, }, ], isError: true, }; } });