create_todo
Create and manage user-specific tasks by specifying a title and user ID, enabling structured task tracking and organization.
Instructions
创建待办事项
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | 待办事项标题 | |
| userId | Yes | 用户ID |
Implementation Reference
- src/index.ts:148-178 (handler)The handler function for the create_todo tool. It destructures title and userId from args, checks if the user exists in testData.users, creates a new todo with incremental ID, appends to testData.todos and logs the action, then returns a success message with the new todo JSON.}, async (args) => { const { title, userId } = args; // 检查用户是否存在 const user = testData.users.find(u => u.id === userId); if (!user) { return { content: [{ type: "text", text: `❌ 错误: 用户ID ${userId} 不存在` }] }; } const newTodo = { id: Math.max(...testData.todos.map(t => t.id)) + 1, title, completed: false, userId }; testData.todos.push(newTodo); testData.logs.push(`创建待办事项: "${title}" (用户: ${user.name})`); return { content: [{ type: "text", text: `✅ 成功创建待办事项: ${JSON.stringify(newTodo, null, 2)}` }] }; });
- src/index.ts:146-147 (schema)Zod input schema defining title as string and userId as number with descriptions.title: z.string().describe("待办事项标题"), userId: z.number().describe("用户ID")
- src/index.ts:145-145 (registration)The server.tool registration call for create_todo, specifying name, description, schema, and handler.server.tool("create_todo", "创建待办事项", {