Skip to main content
Glama
seohyunjun

OpenSearch MCP Server

by seohyunjun

generate_discover_url

Create OpenSearch Dashboards Discover URLs to visualize and analyze indexed data based on specific queries, time ranges, and index patterns.

Instructions

Generate OpenSearch Dashboards Discover view URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
index_pattern_idYes
from_timeYes
to_timeYes

Implementation Reference

  • The handler function for the 'generate_discover_url' tool. It constructs an OpenSearch Dashboards Discover URL using the provided query, index_pattern_id, from_time, and to_time parameters, encoding them into rison format query params.
    @mcp.tool(description="Generate OpenSearch Dashboards Discover view URL") async def generate_discover_url(query: str, index_pattern_id: str, from_time: str, to_time: str) -> list[TextContent]: """ Generate a URL for the OpenSearch Dashboards Discover view that will display the results of a query. The argument values must be compatible with the rison data format used by OpenSearch Dashboards. Use the list index patterns tool to determine the available index pattern IDs. Index_pattern_id argument must be the ID of the index pattern to be used. The query arguement must be a valid OpenSearch lucene format. Refrain from using querying the timestamp or @timestamp fields in the query. Use from_time and to_time parameters instead The function constructs a URL that includes the query and index pattern as parameters. Args: query str: The query to apply in the Discover view in lucene format. index_pattern_id str: The index pattern ID to use in the Discover view URL. from_time str: The starting time for the query in the format like `now-15m`. to_time str: The ending time for the query in the format like `now`. Returns: list[TextContent]: A list containing the generated URL or an error message. """ self.logger.info("Generating Discover view URL") config = self._get_es_config() try: base_url = config["dashboards_host"] + "/app/data-explorer/discover#?" #"http[s]://host[:port]/app/data-explorer/discover#? + query_params" query_params = { "_g": "(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'"+from_time+"',to:'"+to_time+"'))", "_q": "(filters:!(),query:(language:lucene,query:\'"+query+"\'))", "_a": "(discover:(columns:!(_source),isDirty:!f,sort:!()),metadata:(indexPattern:\'"+index_pattern_id+"\',view:discover))" } url = base_url + urlencode(query_params, safe="(),:") return [TextContent(type="text", text=url)] except Exception as e: self.logger.error(f"Error generating Discover view URL: {e}") return [TextContent(type="text", text=f"Error: {str(e)}")]
  • Registers the DashboardTools instance by calling its register_tools method on the MCP server instance. This indirectly registers the 'generate_discover_url' tool along with other dashboard tools.
    index_tools = IndexTools(self.logger) document_tools = DocumentTools(self.logger) cluster_tools = ClusterTools(self.logger) dashboard_tools = DashboardTools(self.logger) admin_index_tools = AdminIndexTools(self.logger) admin_cluster_tools = AdminClusterTools(self.logger) # Register tools from each module index_tools.register_tools(self.mcp) document_tools.register_tools(self.mcp) cluster_tools.register_tools(self.mcp) dashboard_tools.register_tools(self.mcp) admin_index_tools.register_tools(self.mcp) admin_cluster_tools.register_tools(self.mcp)
  • Imports the DashboardTools class which contains the generate_discover_url tool implementation.
    from .tools.dashboards import DashboardTools

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/seohyunjun/opensearch-mcp-server'

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