Skip to main content
Glama

Azure MCP Server

Official
MIT License
1,161
  • Linux
  • Apple
EmbeddingService.cs1.76 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Text; using System.Text.Json; using ToolSelection.Models; namespace ToolSelection.Services; public class EmbeddingService(HttpClient httpClient, string endpoint, string apiKey) { private readonly HttpClient _httpClient = httpClient; private readonly string _endpoint = endpoint; private readonly string _apiKey = apiKey; public async Task<float[]> CreateEmbeddingsAsync(string input) { var requestBody = new EmbeddingRequest { Input = new[] { input } }; var json = JsonSerializer.Serialize(requestBody, SourceGenerationContext.Default.EmbeddingRequest); var content = new StringContent(json, Encoding.UTF8, "application/json"); var request = new HttpRequestMessage(HttpMethod.Post, _endpoint) { Content = content }; request.Headers.Add("api-key", _apiKey); var response = await _httpClient.SendAsync(request); response.EnsureSuccessStatusCode(); var responseContent = await response.Content.ReadAsStringAsync(); var embeddingResponse = JsonSerializer.Deserialize(responseContent, SourceGenerationContext.Default.EmbeddingResponse); if (embeddingResponse?.Error != null) { throw new InvalidOperationException($"API error: {embeddingResponse.Error.Type} - {embeddingResponse.Error.Message}"); } if (embeddingResponse?.Data == null || embeddingResponse.Data.Length == 0) { throw new InvalidOperationException($"No embedding data returned from API. Response: {responseContent}"); } return embeddingResponse.Data[0].Embedding; } }

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/Azure/azure-mcp'

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