跳转到内容

Notion MCP 工具(用于 ADK)

在 ADK 中得到支持。PythonTypeScriptGo

The Notion MCP 服务器 该功能将您的 ADK 代理连接到 Notion,使其能够在工作空间内搜索、创建和管理页面、数据库等资源。这样一来,您的代理就可以使用自然语言在 Notion 工作空间中查询、创建和整理内容了。

使用场景

  • 在您的工作空间中搜索所需的内容。:根据内容查找项目页面、会议记录或文档。

  • 创建新内容:为会议记录、项目计划或任务生成新的页面。

  • 管理任务和数据库:更新任务的状态、向数据库中添加数据,或修改对象的属性。

  • 整理您的工作空间可以移动页面、复制模板,或向文档中添加注释。

先决条件

  • 通过访问相关页面来获取 Notion 集成令牌。 Notion 的集成功能(Notion Integrations) 在你的个人资料中。请参考…… 授权文档 如需更多详情,请参阅……(请填写具体参考资料或链接)。
  • 请确保您的集成系统能够访问相关的页面和数据库。请前往您系统中的“访问”(Access)选项卡进行设置。 Notion 集成 首先,进入 “settings”(设置)页面; 接着,通过选择您希望使用的页面来授予相应的访问权限。

与代理程序(agent)一起使用。

from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from mcp import StdioServerParameters

NOTION_TOKEN = "YOUR_NOTION_TOKEN"

root_agent = Agent(
    model="gemini-flash-latest",
    name="notion_agent",
    instruction="Help users get information from Notion",
    tools=[
        McpToolset(
            connection_params=StdioConnectionParams(
                server_params = StdioServerParameters(
                    command="npx",
                    args=[
                        "-y",
                        "@notionhq/notion-mcp-server",
                    ],
                    env={
                        "NOTION_TOKEN": NOTION_TOKEN,
                    }
                ),
                timeout=30,
            ),
        )
    ],
)
import { LlmAgent, MCPToolset } from "@google/adk";

const NOTION_TOKEN = "YOUR_NOTION_TOKEN";

const rootAgent = new LlmAgent({
    model: "gemini-flash-latest",
    name: "notion_agent",
    instruction: "Help users get information from Notion",
    tools: [
        new MCPToolset({
            type: "StdioConnectionParams",
            serverParams: {
                command: "npx",
                args: ["-y", "@notionhq/notion-mcp-server"],
                env: {
                    NOTION_TOKEN: NOTION_TOKEN,
                },
            },
        }),
    ],
});

export { rootAgent };
package main

import (
    "context"
    "log"
    "os"
    "os/exec"

    "github.com/modelcontextprotocol/go-sdk/mcp"
    "google.golang.org/genai"

    "google.golang.org/adk/v2/agent"
    "google.golang.org/adk/v2/agent/llmagent"
    "google.golang.org/adk/v2/cmd/launcher"
    "google.golang.org/adk/v2/cmd/launcher/full"
    "google.golang.org/adk/v2/model/gemini"
    "google.golang.org/adk/v2/tool"
    "google.golang.org/adk/v2/tool/mcptoolset"
)

const notionToken = "YOUR_NOTION_TOKEN"

func main() {
    ctx := context.Background()

    model, err := gemini.NewModel(ctx, "gemini-flash-latest", &genai.ClientConfig{
        APIKey: os.Getenv("GOOGLE_API_KEY"),
    })
    if err != nil {
        log.Fatalf("Failed to create the model: %v", err)
    }

    server := exec.CommandContext(ctx, "npx", "-y", "@notionhq/notion-mcp-server")
    // Forward only what npx needs, plus the Notion token. The parent environment
    // may hold unrelated secrets, such as the GOOGLE_API_KEY read above.
    server.Env = []string{"NOTION_TOKEN=" + notionToken}
    for _, k := range []string{
        "PATH", "HOME", // POSIX
        "APPDATA", "LOCALAPPDATA", "TEMP", "USERPROFILE", // Windows
    } {
        if v, ok := os.LookupEnv(k); ok {
            server.Env = append(server.Env, k+"="+v)
        }
    }

    notion, err := mcptoolset.New(mcptoolset.Config{
        Transport: &mcp.CommandTransport{Command: server},
    })
    if err != nil {
        log.Fatalf("Failed to create the Notion tool set: %v", err)
    }

    rootAgent, err := llmagent.New(llmagent.Config{
        Model:       model,
        Name:        "notion_agent",
        Instruction: "Help users get information from Notion",
        Toolsets:    []tool.Toolset{notion},
    })
    if err != nil {
        log.Fatalf("Failed to create the agent: %v", err)
    }

    l := full.NewLauncher()
    cfg := &launcher.Config{AgentLoader: agent.NewSingleLoader(rootAgent)}
    if err := l.Execute(ctx, cfg, os.Args[1:]); err != nil {
        log.Fatalf("Run failed: %v\n\n%s", err, l.CommandLineSyntax())
    }
}

可用的工具

工具 描述
notion-search 您可以在自己的 Notion 工作空间以及连接的工具(如 Slack、Google Drive 和 Jira)中搜索所需内容。如果人工智能功能不可用,系统会自动切换回基本的工作空间搜索功能。
notion-fetch 通过 URL 从 Notion 页面或数据库中检索内容。
notion-create-pages 根据指定的属性和内容,创建一个或多个 Notion 页面。
notion-update-page 更新 Notion 页面的属性或内容。
notion-move-pages 将一个或多个 Notion 页面或数据库移动到新的父目录(或父文件夹)中。
notion-duplicate-page 在工作区内复制一个 Notion 页面。此操作是异步完成的。
notion-create-database 创建一个新的 Notion 数据库、初始数据源以及具有指定属性的初始视图。
notion-update-database 更新 Notion 数据源的属性(如名称、描述或其他特性)。
notion-create-comment 在页面上添加一条评论。
notion-get-comments 列出特定页面上的所有评论,包括那些属于连续讨论(即“线程化讨论”)的评论。
notion-get-teams 获取当前工作空间中的所有团队(或团队空间)的列表。
notion-get-users 列出工作空间中的所有用户及其详细信息。
notion-get-user 通过用户 ID 检索您的用户信息
notion-get-self 用于获取有关您自己创建的机器人用户以及您所连接的 Notion 工作区的信息。

其他资源