summarize_transcript
Summarize video transcripts into LinkedIn posts by adjusting tone, audience focus, and length to create professional content from video material.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| transcript | Yes | Video transcript text | |
| tone | No | Tone of the summary | professional |
| audience | No | Target audience for the summary | general |
| wordCount | No | Approximate word count for the summary |
Implementation Reference
- Core handler function that executes the transcript summarization using OpenAI API, handling truncation and prompt engineering.export async function summarizeTranscript(transcript, tone, audience, wordCount, apiKey) { if (!apiKey) { throw new Error("OpenAI API key not provided"); } if (!transcript || transcript.trim().length === 0) { throw new Error("Empty transcript provided"); } console.log(`Summarizing transcript (${transcript.length} chars) with tone: ${tone}, audience: ${audience}`); try { // Initialize OpenAI client with provided API key const openai = new OpenAI({ apiKey: apiKey, }); // Truncate transcript if it's too long (to fit within token limits) const truncatedTranscript = truncateText(transcript, 15000); const response = await openai.chat.completions.create({ model: "gpt-3.5-turbo", messages: [ { role: "system", content: `You are a professional content summarizer. Summarize the provided transcript in a ${tone} tone for a ${audience} audience. The summary should be approximately ${wordCount} words and capture the key points, insights, and valuable information from the transcript. Focus on making the summary concise, informative, and engaging.` }, { role: "user", content: `Please summarize the following video transcript:\n\n${truncatedTranscript}` } ], temperature: 0.7, max_tokens: 500 }); if (response.choices && response.choices.length > 0) { return response.choices[0].message.content.trim(); } else { throw new Error("No summary generated"); } } catch (error) { console.error("Summarization error:", error); throw new Error(`Failed to summarize transcript: ${error.message}`); } }
- src/server.js:113-164 (registration)MCP tool registration for 'summarize_transcript', including input schema, handler wrapper, and description.server.tool( "summarize_transcript", { transcript: z.string().describe("Video transcript text"), tone: z.enum(["educational", "inspirational", "professional", "conversational"]) .default("professional") .describe("Tone of the summary"), audience: z.enum(["general", "technical", "business", "academic"]) .default("general") .describe("Target audience for the summary"), wordCount: z.number().min(100).max(300).default(200) .describe("Approximate word count for the summary") }, async ({ transcript, tone, audience, wordCount }) => { try { // Check if OpenAI API key is set if (!apiKeyManager.hasOpenAIKey()) { throw new Error("OpenAI API key not set. Please use the set_api_keys tool first."); } const summary = await summarizeTranscript( transcript, tone, audience, wordCount, apiKeyManager.getOpenAIKey() ); return { content: [{ type: "text", text: JSON.stringify({ success: true, summary }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: error.message }, null, 2) }], isError: true }; } }, { description: "Summarize a video transcript" } );
- src/server.js:115-125 (schema)Zod input schema defining parameters for the summarize_transcript tool.{ transcript: z.string().describe("Video transcript text"), tone: z.enum(["educational", "inspirational", "professional", "conversational"]) .default("professional") .describe("Tone of the summary"), audience: z.enum(["general", "technical", "business", "academic"]) .default("general") .describe("Target audience for the summary"), wordCount: z.number().min(100).max(300).default(200) .describe("Approximate word count for the summary") },
- Helper function to truncate long transcripts to fit token limits, used in the handler./** * Truncate text to a maximum character length * @param {string} text - Text to truncate * @param {number} maxLength - Maximum length in characters * @returns {string} - Truncated text */ function truncateText(text, maxLength) { if (text.length <= maxLength) return text; // Try to truncate at a sentence boundary const truncated = text.substring(0, maxLength); const lastPeriod = truncated.lastIndexOf('.'); if (lastPeriod > maxLength * 0.8) { return truncated.substring(0, lastPeriod + 1); } return truncated + "..."; }