Skip to main content
Glama
efikuta
by efikuta

generate_knowledge_graph

Create knowledge graphs from multiple YouTube videos to visualize concept relationships and connections across content.

Instructions

Create cross-video knowledge graphs showing concept relationships

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
videoIdsYesYouTube video IDs to create knowledge graph from
graphDepthNoDepth of concept extraction and analysismedium
focusTopicsNoSpecific topics to focus on (optional)
includeTranscriptsNoInclude transcript content in analysis

Implementation Reference

  • Main handler function that executes the generate_knowledge_graph tool. Parses input args using the schema, gathers video data, extracts concepts using LLM, merges them, builds the graph structure, enhances with clustering, and caches the result.
    async execute(args: unknown): Promise<KnowledgeGraph> { const params = GenerateKnowledgeGraphSchema.parse(args); this.logger.info(`Generating knowledge graph for ${params.videoIds.length} videos`); // Generate cache key const cacheKey = `knowledge_graph:${params.videoIds.sort().join(',')}:${params.graphDepth}`; // Check cache first const cached = await this.cache.get<KnowledgeGraph>(cacheKey); if (cached) { this.logger.info(`Returning cached knowledge graph for videos`); return cached; } try { // Step 1: Gather video data const videoData = await this.gatherVideoData(params); // Step 2: Extract concepts from each video const conceptExtractions = await this.extractConceptsFromVideos(videoData, params); // Step 3: Merge and deduplicate concepts const mergedConcepts = this.mergeConceptExtractions(conceptExtractions); // Step 4: Build knowledge graph structure const knowledgeGraph = await this.buildKnowledgeGraph(mergedConcepts, videoData, params); // Step 5: Enhance with clustering and analysis const enhancedGraph = await this.enhanceKnowledgeGraph(knowledgeGraph); // Cache the result await this.cache.set(cacheKey, enhancedGraph, 7200); // 2 hours cache this.logger.info(`Knowledge graph generated: ${enhancedGraph.nodes.length} nodes, ${enhancedGraph.edges.length} edges`); return enhancedGraph; } catch (error) { this.logger.error(`Failed to generate knowledge graph:`, error); throw error; } }
  • Zod schema defining the input parameters for the generate_knowledge_graph tool, used for validation in the handler.
    export const GenerateKnowledgeGraphSchema = z.object({ videoIds: z.array(z.string()).min(2).max(20).describe('Array of YouTube video IDs to analyze'), focusTopics: z.array(z.string()).optional().describe('Specific topics to focus on'), includeTranscripts: z.boolean().default(true).describe('Whether to analyze video transcripts'), graphDepth: z.enum(['shallow', 'medium', 'deep']).default('medium').describe('Depth of knowledge graph analysis'), });
  • src/index.ts:596-598 (registration)
    Registration in the tool dispatch switch statement: calls the KnowledgeGraphGenerator.execute() method when the tool is invoked.
    case 'generate_knowledge_graph': result = await this.knowledgeGraphTool.execute(args); break;
  • src/index.ts:507-542 (registration)
    Tool specification registered in the listTools response, including name, description, and input schema matching the Zod schema.
    { name: 'generate_knowledge_graph', description: 'Create cross-video knowledge graphs showing concept relationships', inputSchema: { type: 'object', properties: { videoIds: { type: 'array', items: { type: 'string' }, minItems: 2, maxItems: 10, description: 'YouTube video IDs to create knowledge graph from' }, graphDepth: { type: 'string', enum: ['shallow', 'medium', 'deep'], default: 'medium', description: 'Depth of concept extraction and analysis' }, focusTopics: { type: 'array', items: { type: 'string' }, description: 'Specific topics to focus on (optional)' }, includeTranscripts: { type: 'boolean', default: true, description: 'Include transcript content in analysis' } }, required: ['videoIds'] }
  • src/index.ts:182-182 (registration)
    Instantiation of the KnowledgeGraphGenerator class instance used as the tool handler.
    this.knowledgeGraphTool = new KnowledgeGraphGenerator(this.youtubeClient, this.cache, this.llmService, this.transcriptProcessor, this.logger);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/efikuta/youtube-knowledge-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server