/**
* OneNote tools for Microsoft Graph API
* Provides read/write access to notebooks, sections, and pages
*/
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import {
handleListNotebooks,
handleGetNotebook,
handleListSections,
handleGetSection,
handleListPages,
handleGetPage,
handleGetPageContent,
handleGetPagePreview,
handleCreatePage,
handleUpdatePage,
handleSearchNotes,
} from './handlers.js';
// Tool 1: List Notebooks
export const listNotebooks: Tool = {
name: 'onenote_list_notebooks',
description: 'List all OneNote notebooks accessible by the user',
inputSchema: {
type: 'object',
properties: {
filter: {
type: 'string',
description: 'OData filter (e.g., "isDefault eq true")'
},
orderby: {
type: 'string',
description: 'Sort order (e.g., "displayName", "lastModifiedDateTime desc")',
default: 'displayName'
},
top: {
type: 'number',
description: 'Maximum number of notebooks to return',
default: 50
},
expand: {
type: 'string',
description: 'Expand related entities (e.g., "sections,sectionGroups")'
}
}
}
};
// Tool 2: Get Notebook
export const getNotebook: Tool = {
name: 'onenote_get_notebook',
description: 'Get details of a specific OneNote notebook',
inputSchema: {
type: 'object',
properties: {
notebookId: {
type: 'string',
description: 'The notebook ID'
},
expand: {
type: 'string',
description: 'Expand related entities (e.g., "sections,sectionGroups")'
}
},
required: ['notebookId']
}
};
// Tool 3: List Sections
export const listSections: Tool = {
name: 'onenote_list_sections',
description: 'List sections in a notebook or all sections',
inputSchema: {
type: 'object',
properties: {
notebookId: {
type: 'string',
description: 'Notebook ID (optional, if not provided lists all sections)'
},
filter: {
type: 'string',
description: 'OData filter expression'
},
orderby: {
type: 'string',
description: 'Sort order',
default: 'displayName'
},
top: {
type: 'number',
description: 'Maximum number of sections to return',
default: 50
}
}
}
};
// Tool 4: Get Section
export const getSection: Tool = {
name: 'onenote_get_section',
description: 'Get details of a specific section',
inputSchema: {
type: 'object',
properties: {
sectionId: {
type: 'string',
description: 'The section ID'
},
expand: {
type: 'string',
description: 'Expand related entities (e.g., "parentNotebook")'
}
},
required: ['sectionId']
}
};
// Tool 5: List Pages
export const listPages: Tool = {
name: 'onenote_list_pages',
description: 'List pages in a section or all pages',
inputSchema: {
type: 'object',
properties: {
sectionId: {
type: 'string',
description: 'Section ID (optional, if not provided lists all pages)'
},
filter: {
type: 'string',
description: 'OData filter expression'
},
orderby: {
type: 'string',
description: 'Sort order',
default: 'lastModifiedDateTime desc'
},
top: {
type: 'number',
description: 'Maximum number of pages to return',
default: 20
},
search: {
type: 'string',
description: 'Search query to filter pages by content'
}
}
}
};
// Tool 6: Get Page
export const getPage: Tool = {
name: 'onenote_get_page',
description: 'Get metadata of a specific page',
inputSchema: {
type: 'object',
properties: {
pageId: {
type: 'string',
description: 'The page ID'
},
expand: {
type: 'string',
description: 'Expand related entities (e.g., "parentSection,parentNotebook")'
}
},
required: ['pageId']
}
};
// Tool 7: Get Page Content
export const getPageContent: Tool = {
name: 'onenote_get_page_content',
description: 'Get the HTML content of a page',
inputSchema: {
type: 'object',
properties: {
pageId: {
type: 'string',
description: 'The page ID'
},
includeIDs: {
type: 'boolean',
description: 'Include element IDs for PATCH operations',
default: false
}
},
required: ['pageId']
}
};
// Tool 8: Get Page Preview
export const getPagePreview: Tool = {
name: 'onenote_get_page_preview',
description: 'Get a text preview of a page',
inputSchema: {
type: 'object',
properties: {
pageId: {
type: 'string',
description: 'The page ID'
}
},
required: ['pageId']
}
};
// Tool 9: Create Page
export const createPage: Tool = {
name: 'onenote_create_page',
description: 'Create a new page in a section',
inputSchema: {
type: 'object',
properties: {
sectionId: {
type: 'string',
description: 'The section ID where the page will be created'
},
title: {
type: 'string',
description: 'Page title'
},
htmlContent: {
type: 'string',
description: 'HTML content for the page body'
}
},
required: ['sectionId', 'title', 'htmlContent']
}
};
// Tool 10: Update Page
export const updatePage: Tool = {
name: 'onenote_update_page',
description: 'Update page content using PATCH operations',
inputSchema: {
type: 'object',
properties: {
pageId: {
type: 'string',
description: 'The page ID'
},
changes: {
type: 'array',
description: 'Array of PATCH operations',
items: {
type: 'object',
properties: {
target: {
type: 'string',
description: 'CSS selector or element ID (e.g., "#div-id", "body")'
},
action: {
type: 'string',
enum: ['replace', 'append', 'prepend', 'insert', 'delete'],
description: 'The action to perform'
},
content: {
type: 'string',
description: 'HTML content (required for replace/append/prepend/insert)'
},
position: {
type: 'string',
enum: ['before', 'after'],
description: 'Position for insert action'
}
},
required: ['target', 'action']
}
}
},
required: ['pageId', 'changes']
}
};
// Tool 11: Search Notes
export const searchNotes: Tool = {
name: 'onenote_search',
description: 'Search across all OneNote pages',
inputSchema: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'Search query'
},
filter: {
type: 'string',
description: 'Additional OData filter'
},
top: {
type: 'number',
description: 'Maximum number of results',
default: 25
}
},
required: ['query']
}
};
// Export all tools as array
export const onenoteTools: Tool[] = [
listNotebooks,
getNotebook,
listSections,
getSection,
listPages,
getPage,
getPageContent,
getPagePreview,
createPage,
updatePage,
searchNotes,
];
// Export handlers map
export const onenoteHandlers: Record<string, Function> = {
'onenote_list_notebooks': handleListNotebooks,
'onenote_get_notebook': handleGetNotebook,
'onenote_list_sections': handleListSections,
'onenote_get_section': handleGetSection,
'onenote_list_pages': handleListPages,
'onenote_get_page': handleGetPage,
'onenote_get_page_content': handleGetPageContent,
'onenote_get_page_preview': handleGetPagePreview,
'onenote_create_page': handleCreatePage,
'onenote_update_page': handleUpdatePage,
'onenote_search': handleSearchNotes,
};