Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ejb503 committed Jan 16, 2025
1 parent 72b7d69 commit 29e5bff
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 203 deletions.
49 changes: 32 additions & 17 deletions src/constants/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,52 @@ export const NOTION_TOOLS: NotionTool[] = [
// List Operations
{
name: "systemprompt_list_notion_pages",
description: "Lists pages in Notion, sorted by last edited time.",
description:
"Lists all accessible Notion pages in your workspace, sorted by last edited time. Returns key metadata including title, URL, and last edited timestamp.",
inputSchema: {
type: "object",
properties: {
maxResults: {
type: "number",
description: "Maximum number of results to return. Defaults to 50.",
description:
"Maximum number of pages to return in the response. Defaults to 50 if not specified.",
},
},
additionalProperties: false,
},
},
{
name: "systemprompt_list_notion_databases",
description: "Lists databases in Notion, sorted by last edited time.",
description:
"Lists all accessible Notion databases in your workspace, sorted by last edited time. Returns key metadata including database title, schema, and last edited timestamp.",
inputSchema: {
type: "object",
properties: {
maxResults: {
type: "number",
description: "Maximum number of results to return. Defaults to 50.",
description:
"Maximum number of databases to return in the response. Defaults to 50 if not specified.",
},
},
additionalProperties: false,
},
},
{
name: "systemprompt_search_notion_pages",
description: "Searches for pages in Notion using a text query.",
description:
"Performs a full-text search across all accessible Notion pages using the provided query. Searches through titles, content, and metadata to find relevant matches.",
inputSchema: {
type: "object",
properties: {
query: {
type: "string",
description: "Search query to find Notion pages",
description:
"Search query to find relevant Notion pages. Can include keywords, phrases, or partial matches.",
},
maxResults: {
type: "number",
description: "Maximum number of results to return. Defaults to 10.",
description:
"Maximum number of search results to return. Defaults to 10 if not specified.",
},
},
required: ["query"],
Expand All @@ -64,17 +71,20 @@ export const NOTION_TOOLS: NotionTool[] = [
},
{
name: "systemprompt_search_notion_pages_by_title",
description: "Searches for pages in Notion by their title.",
description:
"Searches specifically for Notion pages with titles matching the provided query. Useful for finding exact or similar title matches when you know the page name.",
inputSchema: {
type: "object",
properties: {
title: {
type: "string",
description: "Title to search for",
description:
"Title text to search for. Can be exact or partial match.",
},
maxResults: {
type: "number",
description: "Maximum number of results to return. Defaults to 10.",
description:
"Maximum number of matching pages to return. Defaults to 10 if not specified.",
},
},
required: ["title"],
Expand All @@ -83,13 +93,15 @@ export const NOTION_TOOLS: NotionTool[] = [
},
{
name: "systemprompt_get_notion_page",
description: "Retrieves a specific Notion page by its ID.",
description:
"Retrieves comprehensive details of a specific Notion page, including its content, properties, and metadata. Returns the complete page structure and all nested content blocks.",
inputSchema: {
type: "object",
properties: {
pageId: {
type: "string",
description: "The ID of the Notion page to retrieve",
description:
"The unique identifier of the Notion page to retrieve. Must be a valid Notion page ID.",
},
},
required: ["pageId"],
Expand Down Expand Up @@ -127,18 +139,19 @@ export const NOTION_TOOLS: NotionTool[] = [
{
name: "systemprompt_update_notion_page",
description:
"Updates a Notion page with rich, detailed content that expands upon basic inputs.",
"Updates an existing Notion page with rich, comprehensive content based on user instructions. Takes simple inputs and transforms them into well-structured, detailed page content while preserving existing information. Can enhance, reorganize, or expand the current content while maintaining page integrity.",
inputSchema: {
type: "object",
properties: {
pageId: {
type: "string",
description: "The ID of the page to edit",
description:
"The unique identifier of the Notion page to update. Must be a valid Notion page ID.",
},
userInstructions: {
type: "string",
description:
"Basic instructions for editing the page that will be expanded into a comprehensive structure",
"Natural language instructions for updating the page. These will be expanded into comprehensive changes, potentially including new sections, enhanced formatting, additional context, and improved structure while respecting existing content. Can include specific changes, content additions, or general directions for improvement.",
},
},
required: ["pageId", "userInstructions"],
Expand All @@ -155,13 +168,15 @@ export const NOTION_TOOLS: NotionTool[] = [
},
{
name: "systemprompt_delete_notion_page",
description: "Deletes a Notion page.",
description:
"Permanently deletes a specified Notion page and all its contents. This action cannot be undone, so use with caution.",
inputSchema: {
type: "object",
properties: {
pageId: {
type: "string",
description: "The ID of the page to delete",
description:
"The unique identifier of the Notion page to delete. Must be a valid Notion page ID. Warning: deletion is permanent.",
},
},
required: ["pageId"],
Expand Down
5 changes: 1 addition & 4 deletions src/handlers/__tests__/tool-handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
import { NotionService } from "../../services/notion-service.js";
import { handleToolCall } from "../tool-handlers.js";
import type { CallToolRequest } from "@modelcontextprotocol/sdk/types.js";
import type {
RichTextItemResponse,
GetPagePropertyResponse,
} from "@notionhq/client/build/src/api-endpoints.js";

import type { NotionPage } from "../../types/notion.js";
import { NOTION_TOOLS, TOOL_ERROR_MESSAGES } from "../../constants/tools.js";

Expand Down
83 changes: 71 additions & 12 deletions src/handlers/tool-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import { NotionService } from "../services/notion-service.js";
import { NOTION_TOOLS, TOOL_ERROR_MESSAGES } from "../constants/tools.js";
import { validateToolRequest } from "../utils/tool-validation.js";
import { ajv, validateWithErrors } from "../utils/validation.js";
import {
createTextResponse,
createPagesResponse,
createDatabasesResponse,
} from "../utils/tool-utils.js";
import { sendSamplingRequest } from "./sampling.js";
import { handleGetPrompt } from "./prompt-handlers.js";

Expand All @@ -39,35 +34,85 @@ export async function handleToolCall(
typeof args.maxResults === "number" ? args.maxResults : 50;
const notion = NotionService.getInstance();
const result = await notion.listPages({ pageSize: maxResults });
return createPagesResponse(result.pages);
return {
type: "text",
content: [
{
type: "text",
text: JSON.stringify(result.pages, null, 2),
},
],
};
}

case "systemprompt_list_notion_databases": {
const maxResults =
typeof args.maxResults === "number" ? args.maxResults : 50;
const notion = NotionService.getInstance();
const response = await notion.searchDatabases(maxResults);
return createDatabasesResponse(response.results);
return {
type: "text",
content: [
{
type: "text",
text: JSON.stringify(response.results, null, 2),
},
],
};
}

case "systemprompt_search_notion_pages": {
const maxResults =
typeof args.maxResults === "number" ? args.maxResults : 10;
const notion = NotionService.getInstance();
const result = await notion.searchPages(String(args.query), maxResults);
return createPagesResponse(result.pages.slice(0, maxResults));
return {
content: [
{
type: "resource",
resource: {
uri: "notion://pages",
text: JSON.stringify(
result.pages.slice(0, maxResults),
null,
2
),
mimeType: "application/json",
},
},
],
};
}

case "systemprompt_get_notion_page": {
const notion = NotionService.getInstance();
const page = await notion.getPage(String(args.pageId));
return createPagesResponse([page]);
return {
content: [
{
type: "resource",
resource: {
uri: "notion://pages",
text: JSON.stringify([page], null, 2),
mimeType: "application/json",
},
},
],
};
}

case "systemprompt_delete_notion_page": {
const notion = NotionService.getInstance();
await notion.deletePage(String(args.pageId));
return createTextResponse("Page deleted successfully");
return {
type: "text",
content: [
{
type: "text",
text: "Page deleted successfully",
},
],
};
}

case "systemprompt_create_notion_page": {
Expand Down Expand Up @@ -99,7 +144,14 @@ export async function handleToolCall(
arguments: args,
},
});
return createTextResponse(result.content.text as string);
return {
content: [
{
type: "text",
text: result.content.text as string,
},
],
};
}

case "systemprompt_update_notion_page": {
Expand Down Expand Up @@ -141,7 +193,14 @@ export async function handleToolCall(
arguments: args,
},
});
return createTextResponse(result.content.text as string);
return {
content: [
{
type: "text",
text: result.content.text as string,
},
],
};
}

default:
Expand Down
Loading

0 comments on commit 29e5bff

Please sign in to comment.