Skip to main content
Glama
rawveg

Ollama MCP Server

ollama_embed

Generate numerical vector embeddings from text input to enable semantic search, clustering, or similarity comparisons.

Instructions

Generate embeddings for text input. Returns numerical vector representations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYesName of the model to use
inputYesText input. For batch processing, provide a JSON-encoded array of strings, e.g., ["text1", "text2"]
formatNojson

Implementation Reference

  • Main handler function for ollama_embed. Calls ollama.embed() with the model and input, then formats the response.
    export async function embedWithModel(
      ollama: Ollama,
      model: string,
      input: string | string[],
      format: ResponseFormat
    ): Promise<string> {
      const response = await ollama.embed({
        model,
        input,
      });
    
      return formatResponse(JSON.stringify(response), format);
    }
  • Tool handler that validates args via EmbedInputSchema.parse() and delegates to embedWithModel().
      handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => {
        const validated = EmbedInputSchema.parse(args);
        return embedWithModel(ollama, validated.model, validated.input, format);
      },
    };
  • Tool definition registration for 'ollama_embed' including name, description, inputSchema, and handler. Exported as toolDefinition for autoloader discovery.
    export const toolDefinition: ToolDefinition = {
      name: 'ollama_embed',
      description:
        'Generate embeddings for text input. Returns numerical vector representations.',
      inputSchema: {
        type: 'object',
        properties: {
          model: {
            type: 'string',
            description: 'Name of the model to use',
          },
          input: {
            type: 'string',
            description:
              'Text input. For batch processing, provide a JSON-encoded array of strings, e.g., ["text1", "text2"]',
          },
          format: {
            type: 'string',
            enum: ['json', 'markdown'],
            default: 'json',
          },
        },
        required: ['model', 'input'],
      },
      handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => {
        const validated = EmbedInputSchema.parse(args);
        return embedWithModel(ollama, validated.model, validated.input, format);
      },
    };
  • Zod schema for ollama_embed tool input validation (EmbedInputSchema). Validates model (string), input (string or JSON array of strings), and format.
     * Schema for ollama_embed tool
     */
    export const EmbedInputSchema = z.object({
      model: z.string().min(1),
      input: z.string().transform((val, ctx) => {
        const trimmed = val.trim();
        // If it looks like a JSON array, try to parse it
        if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
          try {
            const parsed = JSON.parse(trimmed);
            if (Array.isArray(parsed)) {
              // Validate all elements are strings
              const allStrings = parsed.every((item) => typeof item === 'string');
              if (allStrings) {
                return parsed as string[];
              } else {
                ctx.addIssue({
                  code: z.ZodIssueCode.custom,
                  message:
                    'Input is a JSON array but contains non-string elements',
                });
                return z.NEVER;
              }
            }
          } catch (e) {
            // Failed to parse as JSON, treat as plain string
          }
        }
        // Return as plain string
        return trimmed;
      }),
      format: ResponseFormatSchema.default('json'),
    });
  • Helper function formatResponse used by the handler to format output as JSON or markdown.
    export function formatResponse(
      content: string,
      format: ResponseFormat
    ): string {
      if (format === ResponseFormat.JSON) {
        // For JSON format, validate and potentially wrap errors
        try {
          // Try to parse to validate it's valid JSON
          JSON.parse(content);
          return content;
        } catch {
          // If not valid JSON, wrap in error object
          return JSON.stringify({
            error: 'Invalid JSON content',
            raw_content: content,
          });
        }
      }
    
      // Format as markdown
      try {
        const data = JSON.parse(content);
        return jsonToMarkdown(data);
      } catch {
        // If not valid JSON, return as-is
        return content;
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description should disclose behaviors. It states the output type but lacks details on side effects (none expected), permissions, or rate limits. Adequate for a simple read-like operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, concise and front-loaded with purpose. Every word is necessary.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema; description could mention vector dimensions, normalization, or use cases. Lacks detail on return format but is minimally sufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 67%, description adds no extra meaning beyond what schema already provides for model and input. Format parameter has enum and default in schema. Baseline 3 since description is not incorrect but adds minimal value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states the action (generate), resource (embeddings), and output (numerical vector representations). It distinguishes from siblings like ollama_chat and ollama_generate which produce text.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use embeddings vs other tools like chat or generation. No mention of use cases such as semantic search or when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/rawveg/ollama-mcp'

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