summarize
Generate concise summaries of plain text, web pages, PDF documents, EPUB books, or HTML content. Specify text, desired length, and language for tailored results.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"text": "<text>"
},
"name": "summarize"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | en | |
| maxLength | No | ||
| text | Yes |
Implementation Reference
- src/index.ts:23-45 (handler)The asynchronous handler function that generates a summary of the input text using the Google Gemini model via the 'ai' SDK. It constructs a prompt, calls generateText, and returns the result in MCP format, with error handling.
async ({ text, maxLength, language }) => { try { const prompt = `Please summarize the following text in ${language}, keeping the summary within ${maxLength} characters:\n\n${text}`; const model = google.chat("gemini-1.5-pro"); const result = await generateText({ model: model, prompt: prompt, maxTokens: maxLength, temperature: 0.5 }); return { content: [{ type: "text", text: result.text }] }; } catch (error) { console.error('Summarization error:', error); throw new Error('Failed to generate summary'); } } - src/index.ts:18-22 (schema)Zod schema for the 'summarize' tool inputs: 'text' (required string, min length 1), 'maxLength' (optional number, default 200), 'language' (optional string, default 'en').
{ text: z.string().min(1), maxLength: z.number().optional().default(200), language: z.string().optional().default("en") }, - src/index.ts:17-46 (registration)The server.tool() call that registers the 'summarize' tool, specifying its input schema and handler function.
server.tool("summarize", { text: z.string().min(1), maxLength: z.number().optional().default(200), language: z.string().optional().default("en") }, async ({ text, maxLength, language }) => { try { const prompt = `Please summarize the following text in ${language}, keeping the summary within ${maxLength} characters:\n\n${text}`; const model = google.chat("gemini-1.5-pro"); const result = await generateText({ model: model, prompt: prompt, maxTokens: maxLength, temperature: 0.5 }); return { content: [{ type: "text", text: result.text }] }; } catch (error) { console.error('Summarization error:', error); throw new Error('Failed to generate summary'); } } );