Skip to content

Commit 82983df

Browse files
committed
got the update tools working
1 parent fcd933d commit 82983df

1 file changed

Lines changed: 122 additions & 1 deletion

File tree

notion_brain_dump/server.py

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
from typing import List
55

6-
token = "ntn_token"
6+
token = "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"
77
mcp = FastMCP("notion_bd_server")
88
brain = AsyncClient(auth=token)
99

@@ -22,6 +22,127 @@ async def add_task(task: str):
2222
return f"Task has been added {pg_create['id']}"
2323

2424

25+
@mcp.resource("notion://dumpdb/all")
26+
async def get_all_database_items():
27+
dump_db = "1d784ade96ac80a3b7ecf54f3eae5f49"
28+
all_results = []
29+
next_cursor = None
30+
31+
while True:
32+
response = (
33+
await brain.databases.query(database_id=dump_db, start_cursor=next_cursor)
34+
if next_cursor
35+
else await brain.databases.query(database_id=dump_db)
36+
)
37+
38+
all_results.extend(response["results"])
39+
40+
if response.get("has_more"):
41+
next_cursor = response["next_cursor"]
42+
else:
43+
break
44+
45+
text_conv = ""
46+
for result in all_results:
47+
page_id = result["id"]
48+
last_edited_time = result["last_edited_time"]
49+
# getting the properties now
50+
task_title = result["properties"]["TaskTitle"]["title"][0]["text"]["content"]
51+
task_status = result["properties"]["TaskStatus"]["select"]
52+
area = result["properties"]["Area"]["rich_text"]
53+
resource = result["properties"]["Resource"]["rich_text"]
54+
due_date = result["properties"]["DueDate"]["date"]
55+
url = result["url"]
56+
text_conv += f"Task: {task_title}\t Status: {task_status}\t Area: {area}\t Resource: {resource}\t Due Date: {due_date}\t URL: {url}\t Page ID: {page_id}\t Last Edited Time: {last_edited_time}\t "
57+
# return results[0]["text"]
58+
return text_conv
59+
60+
61+
@mcp.tool()
62+
async def list_task():
63+
"""Lists the tasks in the Notion database as text"""
64+
tlist = await mcp.read_resource("notion://dumpdb/all")
65+
return tlist
66+
67+
68+
@mcp.tool()
69+
async def remove_task(task_text: str):
70+
"""Search for the task from the Notion database and delete it"""
71+
dump_db = "1d784ade96ac80a3b7ecf54f3eae5f49"
72+
search_results = await brain.databases.query(
73+
database_id=dump_db,
74+
filter={
75+
"property": "TaskTitle",
76+
"title": {
77+
"equals": task_text,
78+
},
79+
},
80+
)
81+
results = search_results.get("results", [])
82+
page_id = results[0]["id"]
83+
delete_page = await brain.pages.update(page_id=page_id, archived=True)
84+
return delete_page
85+
86+
87+
@mcp.tool()
88+
async def add_resource(task_text: str, resource_text: str):
89+
"""Search for the task from the Notion database and add resource to it"""
90+
91+
dump_db = "1d784ade96ac80a3b7ecf54f3eae5f49"
92+
93+
search_results = await brain.databases.query(
94+
database_id=dump_db,
95+
filter={
96+
"property": "TaskTitle",
97+
"title": {
98+
"equals": task_text,
99+
},
100+
},
101+
)
102+
results = search_results.get("results", [])
103+
104+
page_id = results[0]["id"]
105+
prop = {}
106+
107+
prop["Resource"] = {
108+
"type": "rich_text",
109+
"rich_text": [{"text": {"content": resource_text}}],
110+
}
111+
112+
updt = await brain.pages.update(page_id=page_id, properties=prop)
113+
return f"Updated the resource to {updt['id']}"
114+
115+
116+
@mcp.tool()
117+
async def add_area(task_text: str, area_text: str):
118+
"""Search for the task from the Notion database and add area to it"""
119+
120+
dump_db = "1d784ade96ac80a3b7ecf54f3eae5f49"
121+
122+
search_results = await brain.databases.query(
123+
database_id=dump_db,
124+
filter={
125+
"property": "TaskTitle",
126+
"title": {
127+
"equals": task_text,
128+
},
129+
},
130+
)
131+
results = search_results.get("results", [])
132+
133+
page_id = results[0]["id"]
134+
prop = {}
135+
136+
if area_text:
137+
prop["Area"] = {
138+
"type": "rich_text",
139+
"rich_text": [{"text": {"content": area_text}}],
140+
}
141+
142+
updt = await brain.pages.update(page_id=page_id, properties=prop)
143+
return f"Updated the area to {updt['id']}"
144+
145+
25146
@mcp.prompt()
26147
def task_steps(task_text: str) -> str:
27148
"""Prompt to get the steps to complete the tasks"""

0 commit comments

Comments
 (0)