summarize_transcript
Generate concise summaries from video transcripts for LinkedIn posts. Customize tone, audience, and word count to match your professional messaging needs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| audience | No | Target audience for the summary | general |
| tone | No | Tone of the summary | professional |
| transcript | Yes | Video transcript text | |
| wordCount | No | Approximate word count for the summary |
Implementation Reference
- Core handler function that implements the transcript summarization logic using OpenAI's chat completions API. Handles input validation, truncation, prompt construction, API call, and error handling.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 server tool registration for 'summarize_transcript', including schema, wrapper handler that retrieves API key and calls the core summarizeTranscript function, and tool 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 validating the parameters for the summarize_transcript tool: transcript (string), tone (enum), audience (enum), wordCount (number 100-300).{ 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 a maximum length, attempting to cut at sentence boundaries to preserve readability before sending to OpenAI.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 + "..."; }