Skip to main content
Glama

post-draft-note

Publish draft articles to note.com by providing title, body content, and optional tags. Update existing drafts using their ID to manage your content publishing workflow.

Instructions

下書き状態の記事を投稿する

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYes記事のタイトル
bodyYes記事の本文
tagsNoタグ(最大10個)
idNo既存の下書きID(既存の下書きを更新する場合)

Implementation Reference

  • Primary handler implementation for the 'post-draft-note' tool. Registers the tool, defines input schema with Zod, and provides the async execution logic that handles draft note creation or update via multiple API fallback attempts to note.com endpoints.
    server.tool( "post-draft-note", "下書き状態の記事を新規作成または更新する", { title: z.string().describe("記事のタイトル"), body: z.string().describe("記事の本文"), tags: z.array(z.string()).optional().describe("タグ(最大10個)"), id: z.string().optional().describe("既存の下書きID(既存の下書きを更新する場合)"), }, async ({ title, body, tags, id }) => { let previewAccessToken: string | null = null; try { if (!hasAuth()) { return createAuthErrorResponse(); } if (id) { // 既存の下書きIDがある場合のみpreview_access_tokenを取得 previewAccessToken = await getPreviewAccessToken(id); if (!previewAccessToken) { console.error(`Failed to get preview_access_token for noteId: ${id}. Proceeding without it for draft save.`); // トークン取得失敗時は、以前の挙動(トークンなし)で試行する } } console.error("下書き保存リクエスト内容:"); // 試行1: 公式API形式で試行(参考: https://note.com/taku_sid/n/n1b1b7894e28f) try { console.error("試行1: 公式API形式 /api/v1/text_notes"); // 参照記事に基づく正しいパラメータ形式 const postData1: any = { name: title, // 'title'ではなく'name' body: body, template_key: null // 新規作成時に必要 }; // 更新時はstatusを追加し、template_keyを削除 if (id) { postData1.status = "draft"; delete postData1.template_key; } console.error(`リクエスト内容: ${JSON.stringify(postData1, null, 2)}`); let endpoint = ""; let method: "POST" | "PUT"; if (id) { // 既存記事の更新 endpoint = `/v1/text_notes/${id}`; method = "PUT"; } else { // 新規作成 endpoint = `/v1/text_notes`; method = "POST"; } const headers1 = buildAuthHeaders(); if (previewAccessToken) { headers1['Authorization'] = `Bearer ${previewAccessToken}`; } const data = await noteApiRequest(endpoint, method, postData1, true, headers1); console.error(`成功: ${JSON.stringify(data, null, 2)}`); return createSuccessResponse({ success: true, data: data, message: id ? "既存の記事を下書き保存しました" : "新しい記事を下書き保存しました", noteId: data.data?.key || id || data.id || null }); } catch (error1) { console.error(`試行1でエラー: ${error1}`); // 試行2: 旧APIエンドポイント try { console.error("試行2: 旧APIエンドポイント"); const postData2 = { title, body, tags: tags || [], }; console.error(`リクエスト内容: ${JSON.stringify(postData2, null, 2)}`); const endpoint = id ? `/v1/text_notes/draft_save?id=${id}&user_id=${env.NOTE_USER_ID}` : `/v1/text_notes/draft_save?user_id=${env.NOTE_USER_ID}`; const headers2 = buildAuthHeaders(); // 試行2ではpreviewAccessTokenを必須としない(旧APIのため互換性維持) // もし試行1で取得できていれば利用する形も考えられるが、一旦シンプルに const data = await noteApiRequest(endpoint, "POST", postData2, true, headers2); console.error(`成功: ${JSON.stringify(data, null, 2)}`); return createSuccessResponse({ success: true, data: data, message: id ? "既存の記事を下書き保存しました" : "新しい記事を下書き保存しました", noteId: data.id || data.note_id || id || null }); } catch (error2) { console.error(`試行2でエラー: ${error2}`); return createErrorResponse( `記事の投稿に失敗しました:\n試行1エラー: ${error1}\n試行2エラー: ${error2}\n\nセッションの有効期限が切れている可能性があります。.envファイルのCookie情報を更新してください。` ); } } } catch (error) { console.error(`下書き保存処理全体でエラー: ${error}`); return handleApiError(error, "記事投稿"); } } );
  • Tool registration entry point in the all-tools aggregator, which calls registerNoteTools to include post-draft-note in the MCP server.
    registerNoteTools(server);
  • Static schema definition for 'post-draft-note' tool in the tools/list response for HTTP transport.
    { name: "post-draft-note", description: "note.comに下書き記事を投稿", inputSchema: { type: "object", properties: { title: { type: "string", description: "記事タイトル" }, body: { type: "string", description: "記事本文" }, tags: { type: "array", items: { type: "string" }, description: "タグ(最大10個)" }, id: { type: "string", description: "既存の下書きID(更新する場合)" } }, required: ["title", "body"] } },

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/shimayuz/note-com-mcp'

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