Templates / AI agent tools

Notion MCP tool: add tasks to a database from any AI chat

An MCP tool that adds a page to a Notion database — “add a task to review the Q3 deck” from Claude, ChatGPT or Cursor lands in your task list.

Capture tasks wherever you’re chatting with AI. The tool creates a page in one Notion database with a title and optional due date, using an integration that can only see that database.

Build it with Wisp

Type this into Wisp, or press Build this — it writes the code below, deploys it and gives you a URL:

An MCP tool add_task that creates a page in the Notion database NOTION_DATABASE_ID with the given title (and optional due date) using NOTION_TOKEN.

The code

add-task · MCP

import { config } from 'wisp';

export async function handler(req) {
  const { title, due } = req.body ?? {};
  if (typeof title !== 'string' || !title.trim()) return { status: 400, body: { error: 'title is required' } };
  const properties = {
    [config.get('NOTION_TITLE_PROPERTY', 'Name')]: { title: [{ text: { content: title.slice(0, 2000) } }] },
  };
  if (due && /^\d{4}-\d{2}-\d{2}$/.test(due)) properties[config.get('NOTION_DUE_PROPERTY', 'Due')] = { date: { start: due } };

  const res = await fetch('https://api.notion.com/v1/pages', {
    method: 'POST',
    headers: { authorization: `Bearer ${config.require('NOTION_TOKEN')}`, 'notion-version': '2022-06-28', 'content-type': 'application/json' },
    body: JSON.stringify({ parent: { database_id: config.require('NOTION_DATABASE_ID') }, properties }),
  });
  if (!res.ok) return { status: 502, body: { error: `Notion said ${res.status}: ${(await res.text()).slice(0, 200)}` } };
  const page = await res.json();
  return { body: { url: page.url } };
}

Set it up

Add these in the project’s Variables & secrets (secrets are encrypted and never shown in logs):

Try it

Connect the MCP URL to Claude and say “add a task: send the invoice to Acme, due Friday”. The agent fills in the date and returns the new page’s link.

How it works

Variations

Questions

Why does Notion return 404 for my database? The database isn’t shared with the integration. Open it in Notion → ••• → Connections → add your integration.

Build it with Wisp — free trial

Related