embed_text
Generate embeddings for text using Google's Gemini embedding models to convert text into numerical representations for machine learning tasks.
Instructions
Generate embeddings for text using Gemini embedding models
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | Embedding model to use | text-embedding-004 |
| text | Yes | Text to generate embeddings for |
Implementation Reference
- src/enhanced-stdio-server.ts:830-868 (handler)The main handler function that executes the embed_text tool, generating embeddings using Gemini's embedContent API.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/enhanced-stdio-server.ts:353-370 (registration)Registration of the embed_text tool in the available tools list, including name, description, and input schema definition.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/utils/validation.ts:102-105 (schema)Zod schema definition for validating input parameters of the embed_text tool.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:499-500 (registration)Dispatcher case in handleToolCall method that routes embed_text calls to the handler function.case 'embed_text': return await this.embedText(request.id, args);