kagi_enrichment_enhance
Enhance content by integrating specialized knowledge and non-mainstream results from Teclis and TinyGem indexes, optimizing discovery via MCP-omnisearch.
Instructions
Provides supplementary content from specialized indexes (Teclis for web, TinyGem for news). Ideal for discovering non-mainstream results and enriching content with specialized knowledge.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Content to enhance |
Input Schema (JSON Schema)
{
"properties": {
"content": {
"description": "Content to enhance",
"type": "string"
}
},
"required": [
"content"
],
"type": "object"
}
Implementation Reference
- Core handler logic: Fetches supplementary content from Kagi's web (Teclis) and news (TinyGem) enrichment APIs, filters for AI/software relevance, cleans snippets, and returns enhanced result with sources.async enhance_content(content: string): Promise<EnhancementResult> { const api_key = validate_api_key( config.enhancement.kagi_enrichment.api_key, this.name, ); const enrich_request = async () => { try { // Try both web and news endpoints const [webData, newsData] = await Promise.all([ http_json<EnrichmentResponse & { message?: string }>( this.name, `https://kagi.com/api/v0/enrich/web?${new URLSearchParams( { q: sanitize_query( 'artificial intelligence software development', ), limit: '5', }, )}`, { method: 'GET', headers: { Authorization: `Bot ${api_key}`, Accept: 'application/json', }, signal: AbortSignal.timeout( config.enhancement.kagi_enrichment.timeout, ), }, ), http_json<EnrichmentResponse & { message?: string }>( this.name, `https://kagi.com/api/v0/enrich/news?${new URLSearchParams( { q: sanitize_query( 'artificial intelligence code generation testing', ), limit: '5', }, )}`, { method: 'GET', headers: { Authorization: `Bot ${api_key}`, Accept: 'application/json', }, signal: AbortSignal.timeout( config.enhancement.kagi_enrichment.timeout, ), }, ), ]); if (!webData?.data || !newsData?.data) { throw new ProviderError( ErrorType.API_ERROR, 'Unexpected response: missing data from enrichment endpoints', this.name, ); } // Combine and filter results const allData = [...webData.data, ...newsData.data].filter( (result) => // Filter for results about software/development/AI result.snippet?.toLowerCase().includes('software') || result.snippet?.toLowerCase().includes('develop') || result.snippet?.toLowerCase().includes('programming') || result.snippet?.toLowerCase().includes('code') || result.snippet ?.toLowerCase() .includes('artificial intelligence') || result.snippet?.toLowerCase().includes('ai'), ); // Clean and combine snippets const enhanced_content = allData .map((result) => result.snippet) .filter(Boolean) .map((snippet) => // Fix HTML entities snippet .replace(/'/g, "'") .replace(/"/g, '"') .replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>'), ) .join('\n\n'); return { original_content: content, enhanced_content, enhancements: [ { type: 'content_enrichment', description: 'Added supplementary information from Teclis (web) and TinyGem (news) specialized indexes', }, ], sources: allData.map((result) => ({ title: result.title, url: result.url, })), source_provider: this.name, }; } catch (error) { handle_provider_error(error, this.name, 'enrich content'); } }; return retry_with_backoff(enrich_request); }
- src/providers/index.ts:136-142 (registration)Registers the KagiEnrichmentProvider instance if the API key is valid, making it available for dynamic tool registration.is_api_key_valid( config.enhancement.kagi_enrichment.api_key, 'kagi_enrichment', ) ) { register_enhancement_provider(new KagiEnrichmentProvider()); }
- src/server/tools.ts:442-478 (registration)Dynamically registers the 'kagi_enrichment_enhance' MCP tool for each enhancement provider (including KagiEnrichmentProvider), defining schema, description, and thin wrapper handler that invokes the provider's enhance_content and serializes the result.this.enhancement_providers.forEach((provider) => { server.tool( { name: `${provider.name}_enhance`, description: provider.description, schema: v.object({ content: v.pipe(v.string(), v.description('Content')), }), }, async ({ content }) => { try { const result = await provider.enhance_content(content); return { content: [ { type: 'text' as const, text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { const error_response = create_error_response( error as Error, ); return { content: [ { type: 'text' as const, text: error_response.error, }, ], isError: true, }; } }, ); });
- src/server/tools.ts:447-449 (schema)Input schema for the enhance tool: requires 'content' string.schema: v.object({ content: v.pipe(v.string(), v.description('Content')), }),
- Defines the provider name 'kagi_enrichment' (used to construct tool name 'kagi_enrichment_enhance') and description (used in tool).name = 'kagi_enrichment'; description = 'Provides supplementary content from specialized indexes (Teclis for web, TinyGem for news). Ideal for discovering non-mainstream results and enriching content with specialized knowledge.';