ADK 的 Notion MCP 工具¶
Supported in ADKPythonTypeScriptGo
Notion MCP 服务器 将你的 ADK 智能体连接到 Notion,允许它在工作区中搜索、创建和管理页面、数据库等。这使你的智能体能够使用自然语言查询、创建和组织你的 Notion 工作区中的内容。
使用案例¶
-
搜索你的工作区:根据内容查找项目页面、会议记录或文档。
-
创建新内容:生成会议记录、项目计划或任务的新页面。
-
管理任务和数据库:更新任务状态、向数据库添加项目或更改属性。
-
组织你的工作区:移动页面、复制模板或向文档添加评论。
前置条件¶
- 通过访问你个人资料中的 Notion 集成 获取 Notion 集成令牌。有关更多详细信息,请参阅 授权文档。
- 确保相关页面和数据库可以被你的集成访问。访问 Notion 集成 设置中的访问选项卡,然后通过选择要使用的页面来授予访问权限。
与智能体配合使用¶
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="帮助用户从 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: "帮助用户从 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("创建模型失败:%v", err)
}
server := exec.CommandContext(ctx, "npx", "-y", "@notionhq/notion-mcp-server")
// 只转发 npx 所需的内容,外加 Notion 令牌。父环境可能
// 包含无关的机密信息,例如上面读取的 GOOGLE_API_KEY。
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("创建 Notion 工具集失败:%v", err)
}
rootAgent, err := llmagent.New(llmagent.Config{
Model: model,
Name: "notion_agent",
Instruction: "帮助用户从 Notion 获取信息",
Toolsets: []tool.Toolset{notion},
})
if err != nil {
log.Fatalf("创建智能体失败:%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("运行失败:%v\n\n%s", err, l.CommandLineSyntax())
}
}
可用工具¶
| 工具 | 描述 |
|---|---|
notion-search |
在你的 Notion 工作区和连接的工具(如 Slack、Google Drive 和 Jira)中进行搜索。如果 AI 功能不可用,则回退到基本工作区搜索。 |
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 工作区的信息。 |