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.
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.
NOTION_TOKEN (format: ntn_xxxxxxxxxxxx).••• → Add connections, and select your integration to grant read_content and insert_content scopes.npm create @modelcontextprotocol/server@latest notion-mcp and install @notionhq/client. Set environment variables: export NOTION_API_KEY="ntn_xxxxxxxxxxxx"
export MCP_PORT=3001
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) }] };
});
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}'.server_url to http://<host>:3001/mcp and transport to sse. Enable auto_tool_selection.tools: ["notion_search", "notion_create_page"]. Send: "Find all Q3 OKRs in Notion and summarize them."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.
npm@notionhq/client and @modelcontextprotocol/sdk packagesngrok) for remote MCP hostingread_content or insert_content, causing 403 Forbidden on MCP calls. Verify scopes in Notion Developer Console.sse but the server defaults to stdio; explicitly configure transport: "sse" in your MCP server initialization.search invocations trigger 429 Too Many Requests. Implement client-side caching or debounce tool calls in your MCP server.Q: How do I build an AI agent that connects to Notion via MCP using Alibaba Cloud Bailian? A: You can integrate a Bailian AI agent with Notion by deploying a custom MCP server that exposes Notion API endpoints and configuring the Bailian Agent Builder to call it via SSE. First, create a Notion internal integration with read and insert scopes, then scaffold the MCP server using the provided npm package and set the required environment variables. Finally, add the MCP endpoint to your Bailian agent's tools, enable auto tool selection, and bind the specific tool names to test natural language queries.