Skip to main content
Glama

embed_text

Generate text embeddings using Gemini models to convert text into numerical vectors for AI applications like semantic search and similarity analysis.

Instructions

Generate embeddings for text using Gemini embedding models

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesText to generate embeddings for
modelNoEmbedding model to usetext-embedding-004

Implementation Reference

  • The core handler function that executes the embed_text tool by calling Google Gemini's embedContent API to generate text embeddings.
    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' } }; } }
  • Tool registration in the getAvailableTools() method, defining the tool name, description, and input schema.
    { 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'] } },
  • Input schema definition for the embed_text tool, specifying required 'text' parameter and optional embedding model.
    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'] } },
  • Dispatch logic in handleToolCall() switch statement that routes embed_text calls to the handler.
    case 'embed_text': return await this.embedText(request.id, args);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aliargun/mcp-server-gemini'

If you have feedback or need assistance with the MCP directory API, please join our Discord server