kibela_search_notes
Search your Kibela notes using a query to locate specific information. Access relevant content from your team's knowledge base.
Instructions
Search Kibela notes by query
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query |
Implementation Reference
- src/tools/searchNotes.ts:23-44 (handler)The handler function that executes the tool logic. It validates the 'query' argument, calls the GraphQL searchNotes function, extracts document nodes from search results, and returns them as JSON text.
handler: async (args) => { if (!args.query) { throw new Error('Query is required') } const response = await searchNotes({ query: args.query }) const edges = response.search?.edges ?? [] const notes = edges .filter((edge): edge is NonNullable<(typeof edges)[number]> => edge != null) .filter((edge) => edge.node?.document != null) .map((edge) => edge.node?.document) return { content: [ { type: 'text', text: JSON.stringify(notes, null, 2), }, ], } }, - src/tools/searchNotes.ts:4-22 (schema)Input schema and type definitions for the tool. Defines SearchNotesArgs type (query: string) and the inputSchema with required 'query' string property.
export type SearchNotesArgs = { query: string } export const searchNotesTool: ToolDefinition<SearchNotesArgs> = { tool: { name: 'kibela_search_notes', description: 'Search Kibela notes by query', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query', }, }, required: ['query'], }, }, - src/tools/index.ts:9-16 (registration)Registration of the tool in the toolDefinitions map. Maps the name 'kibela_search_notes' to the searchNotesTool definition, which is later exported via TOOLS and dispatched via handleToolRequest.
const toolDefinitions = { kibela_search_notes: searchNotesTool, kibela_get_my_notes: getMyNotesTool, kibela_get_note_content: getNoteContentTool, kibela_get_note_from_path: getNoteFromPathTool, kibela_update_note_content: updateNoteContentTool, kibela_create_note: createNoteTool, } as const - GraphQL query helper that defines the 'searchNotes' query (SearchNotes query with query variable, returning up to 15 results with id/title/url) and the searchNotes function that executes it via gqlRequest.
import { TypedDocumentNode } from '@graphql-typed-document-node/core' import { gql } from 'graphql-tag' import { gqlRequest } from '../request' type SearchNotesResponse = { search: { edges: { node: { document: { id: string title: string url: string } } }[] } } type SearchNotesVariables = { query: string } const searchNotesQuery: TypedDocumentNode<SearchNotesResponse, SearchNotesVariables> = gql` query SearchNotes($query: String!) { search(query: $query, first: 15) { edges { node { document { ... on Note { id title url } } } } } } ` export async function searchNotes(variables: SearchNotesVariables): Promise<SearchNotesResponse> { return gqlRequest(searchNotesQuery, variables) } - src/graphql/request.ts:4-41 (helper)Generic GraphQL request helper (gqlRequest) that sends the query to the Kibela API endpoint using environment variables for team and token authentication.
export async function gqlRequest<TData, TVariables>( query: TypedDocumentNode<TData, TVariables>, variables: TVariables, ): Promise<TData> { const queryString = query.loc?.source.body ?? '' if (!queryString) { throw new Error('Failed to get query string') } console.error('Query:', queryString) console.error('Variables:', variables) const response = await fetch(`https://${env.KIBELA_TEAM}.kibe.la/api/v1`, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${env.KIBELA_TOKEN}`, }, body: JSON.stringify({ query: queryString, variables, }), }) if (!response.ok) { const errorText = await response.text() console.error('Response:', errorText) throw new Error(`HTTP error! status: ${response.status}, body: ${errorText}`) } const json = await response.json() const typedJson = json as { errors?: Array<{ message: string }>; data: TData } if (typedJson.errors) { throw new Error(typedJson.errors[0].message) } return typedJson.data }