embed_text
Generate text embeddings using Gemini models to convert text into numerical vectors for analysis and processing.
Instructions
Generate embeddings for text using Gemini embedding models
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": "embed_text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to generate embeddings for | |
| model | No | Embedding model to use | text-embedding-004 |
Implementation Reference
- src/enhanced-stdio-server.ts:830-868 (handler)The main handler function for the embed_text tool. It calls the Gemini API to generate text embeddings and returns the embedding vector as JSON.
private async embedText(id: any, args: any): Promise<MCPResponse> { try { const model = args.model || 'text-embedding-004'; const result = await this.genAI.models.embedContent({ model, contents: args.text }); return { jsonrpc: '2.0', id, result: { content: [ { type: 'text', text: JSON.stringify({ embedding: result.embeddings?.[0]?.values || [], model }) } ], metadata: { model, dimensions: result.embeddings?.[0]?.values?.length || 0 } } }; } catch (error) { return { jsonrpc: '2.0', id, error: { code: -32603, message: error instanceof Error ? error.message : 'Internal error' } }; } } - src/utils/validation.ts:102-105 (schema)Zod schema defining the input parameters for the embed_text tool: required 'text' string and optional 'model' enum.
embedText: z.object({ text: z.string().min(1, 'Text is required'), model: z.enum(['text-embedding-004', 'text-multilingual-embedding-002']).optional() }), - src/enhanced-stdio-server.ts:352-371 (registration)Tool registration entry in the getAvailableTools() method, defining the tool's name, description, and input schema for MCP protocol.
{ name: 'embed_text', description: 'Generate embeddings for text using Gemini embedding models', inputSchema: { type: 'object', properties: { text: { type: 'string', description: 'Text to generate embeddings for' }, model: { type: 'string', description: 'Embedding model to use', enum: ['text-embedding-004', 'text-multilingual-embedding-002'], default: 'text-embedding-004' } }, required: ['text'] } }, - src/enhanced-stdio-server.ts:499-500 (registration)Dispatch case in handleToolCall switch statement that routes embed_text calls to the handler method.
case 'embed_text': return await this.embedText(request.id, args);