import { notionMcpSetupMessage, callNotionMcp, firstArray } from './mcp.ts'
type Input = { query?: string }
/**
* Search Notion pages through the connected Notion MCP server.
* @param input - Optional helper arguments (query, limit, filters).
* @returns Structured helper result for agents.
* @example
* import search from 'kody:@kody/notion-mcp/search'
* const result = await search()
* // => { ... }
*/
export default async function searchNotion(input: Input = {}) {
const mcp = await callNotionMcp(
[
"search",
"notion-search",
"API-post-search"
],
{ query: input.query?.trim() || undefined },
)
if (!mcp) {
throw new Error(notionMcpSetupMessage())
}
return {
via: 'mcp',
tool: mcp.tool,
results: firstArray(mcp.result) ?? mcp.result,
}
}