Skip to content

Commit 8d05b48

Browse files
authored
Merge pull request #31 from mvletter/main
Update index.ts
2 parents 9c49ca8 + bbb8f39 commit 8d05b48

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

notion/src/index.ts

+43
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,26 @@ const deleteBlockTool: Tool = {
537537
},
538538
};
539539

540+
const updateBlockTool: Tool = {
541+
name: "notion_update_block",
542+
description: "Update the content of a block in Notion based on its type. The update replaces the entire value for a given field.",
543+
inputSchema: {
544+
type: "object",
545+
properties: {
546+
block_id: {
547+
type: "string",
548+
description: "The ID of the block to update." + commonIdDescription,
549+
},
550+
block: {
551+
type: "object",
552+
description: "The updated content for the block. Must match the block's type schema.",
553+
},
554+
format: formatParameter,
555+
},
556+
required: ["block_id", "block"],
557+
},
558+
};
559+
540560
// Pages
541561
const retrievePageTool: Tool = {
542562
name: "notion_retrieve_page",
@@ -951,6 +971,16 @@ export class NotionClientWrapper {
951971
return response.json();
952972
}
953973

974+
async updateBlock(block_id: string, block: Partial<BlockResponse>): Promise<BlockResponse> {
975+
const response = await fetch(`${this.baseUrl}/blocks/${block_id}`, {
976+
method: "PATCH",
977+
headers: this.headers,
978+
body: JSON.stringify(block),
979+
});
980+
981+
return response.json();
982+
}
983+
954984
async retrievePage(page_id: string): Promise<PageResponse> {
955985
const response = await fetch(`${this.baseUrl}/pages/${page_id}`, {
956986
method: "GET",
@@ -1263,6 +1293,18 @@ async function main() {
12631293
break;
12641294
}
12651295

1296+
case "notion_update_block": {
1297+
const args = request.params.arguments as unknown as {
1298+
block_id: string;
1299+
block: Partial<BlockResponse>;
1300+
};
1301+
if (!args.block_id || !args.block) {
1302+
throw new Error("Missing required arguments: block_id and block");
1303+
}
1304+
response = await notionClient.updateBlock(args.block_id, args.block);
1305+
break;
1306+
}
1307+
12661308
case "notion_retrieve_page": {
12671309
const args = request.params
12681310
.arguments as unknown as RetrievePageArgs;
@@ -1456,6 +1498,7 @@ async function main() {
14561498
retrieveBlockTool,
14571499
retrieveBlockChildrenTool,
14581500
deleteBlockTool,
1501+
updateBlockTool,
14591502
retrievePageTool,
14601503
updatePagePropertiesTool,
14611504
listAllUsersTool,

0 commit comments

Comments
 (0)