Skip to main content
Glama
supavec

Supavec MCP Server

by supavec

fetch-embeddings

Retrieve embeddings for a file using its ID and a specific query, enabling vector search and context extraction via the Supavec MCP Server.

Instructions

Fetch embeddings for a file by ID and query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_idYesID of the file to get embeddings for
queryYesQuery to search for in the file

Implementation Reference

  • Executes the fetch-embeddings tool: extracts file_id and query from arguments, constructs API URL, calls makeSupavecRequest to Supavec embeddings endpoint, handles error or returns concatenated document contents as JSON text content.
    if (request.params.name === "fetch-embeddings") {
      const file_id = request.params.arguments?.file_id as string;
      const query = request.params.arguments?.query as string;
      const embeddingsUrl = `${SUPAVEC_BASE_URL}/embeddings`;
      const embeddings = await makeSupavecRequest<Embeddings>(
        embeddingsUrl,
        {
          file_ids: [file_id],
          query: query,
        },
        apiKey
      );
    
      if ("error" in embeddings) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to retrieve embeddings for ${file_id}: ${embeddings.error}`,
            },
          ],
        };
      }
    
      return {
        content: [
          {
            type: "text",
            mimeType: "application/json",
            text: JSON.stringify(
              embeddings.documents.map((d) => d.content).join("\n"),
              null,
              2
            ),
          },
        ],
      };
    }
  • Registers the fetch-embeddings tool in the tools array used for listTools response, including name, description, and inputSchema.
    {
      name: "fetch-embeddings",
      description: "Fetch embeddings for a file by ID and query",
      inputSchema: {
        type: "object",
        properties: {
          file_id: {
            type: "string",
            description: "ID of the file to get embeddings for",
          },
          query: {
            type: "string",
            description: "Query to search for in the file",
          },
        },
        required: ["file_id", "query"],
      },
    },
  • Defines the JSON input schema for the fetch-embeddings tool, specifying required file_id and query parameters.
    inputSchema: {
      type: "object",
      properties: {
        file_id: {
          type: "string",
          description: "ID of the file to get embeddings for",
        },
        query: {
          type: "string",
          description: "Query to search for in the file",
        },
      },
      required: ["file_id", "query"],
    },
  • Generic utility function to make authenticated POST requests to Supavec API endpoints, used by the fetch-embeddings handler to call the embeddings endpoint.
    export async function makeSupavecRequest<T>(
      url: string,
      body: object,
      apiKey: string
    ): Promise<T | { error: string }> {
      try {
        const response = await fetch(url, {
          method: "POST",
          headers: {
            authorization: apiKey,
            "Content-Type": "application/json",
          },
          body: JSON.stringify(body),
        });
        if (!response.ok) {
          return {
            error: `Failed to fetch data: status ${response.status}`,
          };
        }
    
        const data = await response.json();
        return data as T;
      } catch (error) {
        return {
          error: `Failed to fetch data: ${error}`,
        };
      }
    }
  • TypeScript type definition for the Embeddings response from the Supavec API, used in the handler.
    export type Embeddings = {
      documents: {
        content: string;
      }[];
    };
Install Server

Other Tools

Related 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/supavec/mcp-server'

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