create_item
Create and publish new articles on Qiita, a Japanese developer community platform, by providing title, markdown content, tags, and privacy settings.
Instructions
新しい記事を作成します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | Yes | 記事の本文(Markdown形式) | |
| private | No | 非公開記事かどうか | |
| tags | Yes | タグの配列 | |
| title | Yes | 記事のタイトル | |
| tweet | No | Twitterに投稿するかどうか |
Implementation Reference
- src/tools/handlers.ts:96-98 (handler)Handler definition for the 'create_item' tool. It references the input schema and provides an execute function that passes the validated input directly to the QiitaApiClient's createItem method.create_item: { schema: createItemSchema, execute: async (input, client) => client.createItem(input),
- src/tools/handlers.ts:36-42 (schema)Zod schema used for input validation of the create_item tool.const createItemSchema = z.object({ title: z.string(), body: z.string(), tags: z.array(tagSpecificationSchema), private: z.boolean().default(false), tweet: z.boolean().default(false), });
- src/qiitaApiClient.ts:76-86 (helper)Core helper method implementing the Qiita API call to create a new item by posting to /items endpoint.async createItem(item: { title: string; body: string; tags: Array<{ name: string; versions: string[] }>; private?: boolean; tweet?: boolean; }) { this.assertAuthenticated(); const response = await this.client.post('/items', item); return response.data; }
- src/tools/definitions.ts:181-229 (schema)MCP tool schema definition for 'create_item', used in listTools response.{ name: 'create_item', description: '新しい記事を作成します', inputSchema: { type: 'object', properties: { title: { type: 'string', description: '記事のタイトル', }, body: { type: 'string', description: '記事の本文(Markdown形式)', }, tags: { type: 'array', description: 'タグの配列', items: { type: 'object', properties: { name: { type: 'string', description: 'タグ名', }, versions: { type: 'array', description: 'タグのバージョン', items: { type: 'string', }, }, }, required: ['name', 'versions'], }, }, private: { type: 'boolean', description: '非公開記事かどうか', default: false, }, tweet: { type: 'boolean', description: 'Twitterに投稿するかどうか', default: false, }, }, required: ['title', 'body', 'tags'], }, },
- src/index.ts:30-65 (registration)Generic tool call handler registration in MCP server that dispatches to specific toolHandlers[name].execute for 'create_item' and others.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, }; } });