Package com.tnsai.tools.productivity
Class NotionTools
java.lang.Object
com.tnsai.tools.productivity.NotionTools
Function-shape Notion tools — page + database operations via the Notion
REST API v1 (version pinned to
2022-06-28). Replaces the legacy
NotionTool (single dispatched tool).
| Method | Endpoint | Idempotent |
|---|---|---|
notionSearch(java.lang.String) | POST /search | true |
notionGetPage(java.lang.String) | GET /pages/{id} | true |
notionQueryDatabase(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>) | POST /databases/{id}/query | true |
notionCreatePage(java.lang.String, java.lang.String, java.lang.String) | POST /pages | false (creates a page) |
Requires NOTION_API_KEY (Notion integration token, starts with
secret_). Pin Notion-Version header so the response shape stays
predictable across Notion API releases.
- Since:
- 0.5.7 (Phase 2 batch 19a — built-in tool migration to function shape, see #188)
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor — picks NOTION_API_KEY from env.NotionTools(String apiKey) Explicit-key constructor.NotionTools(String apiKey, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests / shared HTTP. -
Method Summary
Modifier and TypeMethodDescriptionnotionCreatePage(String parentId, String title, String content) notionGetPage(String pageId) notionQueryDatabase(String databaseId, Map<String, Object> filter) notionSearch(String query)
-
Constructor Details
-
NotionTools
public NotionTools()Default constructor — picks NOTION_API_KEY from env. -
NotionTools
Explicit-key constructor. -
NotionTools
public NotionTools(String apiKey, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests / shared HTTP.
-
-
Method Details
-
notionSearch
@Tool(name="notion_search", description="Search across the Notion workspace by free-text {query}. Matches both pages and databases. Returns the raw JSON response with results array. Requires NOTION_API_KEY.", keywords={"notion","search","workspace","find"}, idempotent=true) public String notionSearch(@ToolParam(description="Free-text search query") String query) throws IOException - Throws:
IOException
-
notionGetPage
@Tool(name="notion_get_page", description="Fetch a Notion page by id. Returns the raw JSON page object with properties + parent + url. Note this fetches metadata; for the page\'s body content blocks use the /blocks/{id}/children endpoint via http_request. Requires NOTION_API_KEY.", keywords={"notion","page","get","read"}, idempotent=true) public String notionGetPage(@ToolParam(description="Notion page id (UUID)") String pageId) throws IOException - Throws:
IOException
-
notionQueryDatabase
@Tool(name="notion_query_database", description="Query a Notion database. Optional {filter} is a JSON filter object per the Notion API filter spec (e.g. { \"property\": \"Status\", \"select\": { \"equals\": \"Done\" } }). Returns the raw JSON results array.", keywords={"notion","database","query","filter"}, idempotent=true) public String notionQueryDatabase(@ToolParam(description="Notion database id") String databaseId, @ToolParam(description="Optional Notion filter object",required=false) Map<String, Object> filter) throws IOException- Throws:
IOException
-
notionCreatePage
@Tool(name="notion_create_page", description="Create a new Notion page under {parentId} with a {title}. Optional {content} adds a single paragraph block as the page body. Returns the raw JSON of the created page (includes id + url). NOT idempotent \u2014 every call creates a new page even with the same arguments.", keywords={"notion","create","page","new"}, idempotent=false) public String notionCreatePage(@ToolParam(description="Parent page id (the new page becomes its child)") String parentId, @ToolParam(description="Page title") String title, @ToolParam(description="Optional page body (single paragraph)",required=false,defaultValue="") String content) throws IOException - Throws:
IOException
-