write_note
Create and save notes to the inBox note-taking system via the MCP-Server-Inbox. Add titles and markdown-formatted content with ease through any MCP client.
Instructions
Write note to inBox
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Text content of the note with markdown format | |
| title | No | Optional title of the note |
Implementation Reference
- src/inbox.ts:28-65 (handler)Core handler function `writeNote` in InboxClient that validates input and performs POST request to inBox API to create the note.async writeNote({ title, content }: { title?: string; content: string }) { try { if (!content) { throw new Error("invalid content"); } // 检查内容长度 if (content.length > 3000) { throw new Error("note content exceeds 3000 characters limit"); } // 构建请求体,直接传递 title 和 content 参数 const req: { content: string; title?: string } = { content, }; // 如果有title参数,添加到请求中 if (title) { req.title = title; } const resp = await fetch(this.apiUrl, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(req), }); if (!resp.ok) { throw new Error(`request failed with status ${resp.statusText}`); } return resp.json(); } catch (e) { throw e; } }
- src/index.ts:62-75 (schema)Input schema for the 'write_note' tool defining optional 'title' and required 'content' fields.inputSchema: { type: "object", properties: { title: { type: "string", description: "Optional title of the note", }, content: { type: "string", description: "Text content of the note with markdown format", }, }, required: ["content"], },
- src/index.ts:56-79 (registration)Tool registration in ListToolsRequestHandler, exposing 'write_note' tool with schema.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "write_note", description: "Write note to inBox", inputSchema: { type: "object", properties: { title: { type: "string", description: "Optional title of the note", }, content: { type: "string", description: "Text content of the note with markdown format", }, }, required: ["content"], }, }, ], }; });
- src/index.ts:87-122 (handler)MCP CallTool handler case for 'write_note' that processes arguments, instantiates InboxClient, calls writeNote, and returns formatted response.case "write_note": { const content = String(request.params.arguments?.content); const title = request.params.arguments?.title ? String(request.params.arguments.title) : undefined; if (!content) { throw new Error("Content is required"); } // 获取用户Token,优先使用命令行参数,其次使用环境变量 const userToken = args.inbox_user_token || process.env.INBOX_USER_TOKEN; if (!userToken) { throw new Error("inBox token or URL not set. Please provide it via:\n" + "1. Token format: --inbox_user_token=your_token\n" + "2. URL format: --inbox_user_token=https://inbox.gudong.site/api/inbox/your_token"); } // 创建inBox客户端并写入笔记 const inbox = new InboxClient({ userToken }); const result = await inbox.writeNote({ title, content }); // 返回成功信息 let successMessage = `笔记已成功保存到inBox!`; if (title) { successMessage += `\n\n标题: ${title}`; } successMessage += `\n\n${content.substring(0, 50)}${content.length > 50 ? '...' : ''}`; return { content: [ { type: "text", text: successMessage }, ], }; }