Skip to main content
Glama

Azure MCP Server

Official
MIT License
1,161
  • Linux
  • Apple
IndexQueryCommand.cs2.92 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using AzureMcp.Core.Commands; using AzureMcp.Search.Options; using AzureMcp.Search.Options.Index; using AzureMcp.Search.Services; using Microsoft.Extensions.Logging; namespace AzureMcp.Search.Commands.Index; public sealed class IndexQueryCommand(ILogger<IndexQueryCommand> logger) : GlobalCommand<IndexQueryOptions>() { private const string CommandTitle = "Query Azure AI Search (formerly known as \"Azure Cognitive Search\") Index"; private readonly ILogger<IndexQueryCommand> _logger = logger; private readonly Option<string> _serviceOption = SearchOptionDefinitions.Service; private readonly Option<string> _indexOption = SearchOptionDefinitions.Index; private readonly Option<string> _queryOption = SearchOptionDefinitions.Query; public override string Name => "query"; public override string Description => """ Query an Azure AI Search index. Returns search results matching the specified query. Required arguments: - service: The name of the Azure AI Search service - index: The name of the search index to query - query: The search text to query with """; public override string Title => CommandTitle; public override ToolMetadata Metadata => new() { Destructive = false, ReadOnly = true }; protected override void RegisterOptions(Command command) { base.RegisterOptions(command); command.AddOption(_serviceOption); command.AddOption(_indexOption); command.AddOption(_queryOption); } protected override IndexQueryOptions BindOptions(ParseResult parseResult) { var options = base.BindOptions(parseResult); options.Service = parseResult.GetValueForOption(_serviceOption); options.Index = parseResult.GetValueForOption(_indexOption); options.Query = parseResult.GetValueForOption(_queryOption); return options; } public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult) { var options = BindOptions(parseResult); try { if (!Validate(parseResult.CommandResult, context.Response).IsValid) { return context.Response; } var searchService = context.GetService<ISearchService>(); var results = await searchService.QueryIndex( options.Service!, options.Index!, options.Query!, options.RetryPolicy); context.Response.Results = ResponseResult.Create(results, SearchJsonContext.Default.ListJsonElement); } catch (Exception ex) { _logger.LogError(ex, "Error executing search query"); HandleException(context, ex); } return context.Response; } }

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