Skip to main content
Glama

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

Input Schema

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

Implementation Reference

  • 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' } }; } }
  • 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() }),
  • 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'] } },
  • 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);

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/gurveeer/mcp-server-gemini-pro'

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