DaaS / Products / AI Agent with Notion via MCP

AI Agent with Notion via MCP

Build an AI agent on Alibaba Cloud Bailian that connects to Notion as an MCP tool, enabling the LLM to read, search, and write Notion pages and databases through natural language tool calling.

Products involved

Scenario

Developers use this workflow when they need a Qwen-powered agent on Alibaba Cloud Bailian to autonomously query, update, and organize Notion workspaces using natural language. By exposing Notion as an MCP tool, the agent bypasses rigid UI constraints and performs structured knowledge management through dynamic tool calling.

Integration steps

  1. Create Notion Internal Integration: In Notion Settings → Integrations, create a new integration and copy the NOTION_TOKEN (format: ntn_xxxxxxxxxxxx).
  2. Share Workspace Content: Open target Notion pages/databases, click •••Add connections, and select your integration to grant read_content and insert_content scopes.
  3. Initialize MCP Server: Scaffold with npm create @modelcontextprotocol/server@latest notion-mcp and install @notionhq/client. Set environment variables:
  4. ``bash export NOTION_API_KEY="ntn_xxxxxxxxxxxx" export MCP_PORT=3001 ``

  5. Define MCP Tools: Register tools that map to Notion API v1 endpoints:
  6. ``javascript server.tool("notion_search", { query: z.string() }, async ({ query }) => { const res = await notion.search({ query, filter: { property: "object", value: "page" } }); return { content: [{ type: "text", text: JSON.stringify(res.results) }] }; }); ``

  7. Start MCP Server: Run node index.js. Verify connectivity with curl -X POST http://localhost:3001/mcp -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"tools/list","id":1}'.
  8. Configure Bailian Agent: In Bailian Console → Agent Builder → Tools, add an MCP endpoint. Set server_url to http://<host>:3001/mcp and transport to sse. Enable auto_tool_selection.
  9. Bind & Test: In the Bailian SDK, initialize with tools: ["notion_search", "notion_create_page"]. Send: "Find all Q3 OKRs in Notion and summarize them."

Architecture

The user prompt hits the Bailian orchestration layer, where Qwen evaluates registered MCP tool definitions. When a Notion-related intent is detected, Bailian’s MCP client sends a JSON-RPC request over SSE to the hosted MCP server. The server translates the call into authenticated POST /v1/search or POST /v1/pages requests against Notion’s REST API, returning structured JSON. Bailian parses the response, injects it into Qwen’s context window for reasoning, and generates the final output. Notion acts purely as the data layer; Bailian handles prompt routing, context management, and tool execution.

Prerequisites

Common pitfalls

Typical questions