### Interact with Server Endpoints Source: https://context7.com/grafana/loki-mcp/llms.txt Examples for testing the server's SSE and MCP endpoints to verify connectivity and list available tools. ```bash curl -X POST http://localhost:8080/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": "1", "method": "tools/list", "params": {} }' ``` -------------------------------- ### Configure Claude Desktop for Loki MCP Source: https://context7.com/grafana/loki-mcp/llms.txt Configuration examples for integrating the Loki MCP server into Claude Desktop, supporting binary execution, Go scripts, or Docker containers. ```json { "mcpServers": { "loki-mcp-server": { "command": "/path/to/loki-mcp-server", "args": [], "env": { "LOKI_URL": "http://localhost:3100" } } } } ``` -------------------------------- ### Manage Loki Local Environment Source: https://github.com/grafana/loki-mcp/blob/main/README.md Commands to start the Docker Compose environment, query logs using the test script, and insert dummy data for testing purposes. ```bash docker-compose up -d ./test-loki-query.sh ./test-loki-query.sh '{job="varlogs"} |= "ERROR"' ./test-loki-query.sh '{job="varlogs"}' '-1h' 'now' 50 ./insert-loki-logs.sh ./insert-loki-logs.sh --num 20 --job "custom-job" --app "my-app" ./insert-loki-logs.sh --env "production" --interval 0.5 ``` -------------------------------- ### Get Label Values (env) Source: https://context7.com/grafana/loki-mcp/llms.txt Retrieves all unique values for the 'env' label from Loki. ```APIDOC ## POST /mcp ### Description Retrieves all unique values for a specified label from Grafana Loki. ### Method POST ### Endpoint /mcp ### Parameters #### Request Body - **jsonrpc** (string) - Required - Specifies the JSON-RPC version. - **id** (string) - Required - The ID of the request. - **method** (string) - Required - The method to call, must be "tools/call". - **params** (object) - Required - Parameters for the method call. - **name** (string) - Required - The name of the tool to call, must be "loki_label_values". - **arguments** (object) - Required - Arguments for the "loki_label_values" tool. - **label** (string) - Required - The label for which to retrieve values (e.g., "env"). - **url** (string) - Required - The URL of the Loki instance. - **start** (string) - Optional - The start time for the query (e.g., "-24h"). - **end** (string) - Optional - The end time for the query (e.g., "now"). - **format** (string) - Optional - The desired output format ("raw" or "json"). Defaults to "raw". ### Request Example ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_label_values", "arguments": { "label": "env", "url": "http://localhost:3100", "format": "json" } } } ``` ### Response #### Success Response (200) - **jsonrpc** (string) - The JSON-RPC version. - **id** (string) - The ID of the request. - **result** (string or object) - The result of the operation. For "raw" format, it's a string with one value per line. For "json" format, it's an object containing the label values. #### Response Example (json format) ```json { "status": "success", "data": ["production", "staging", "development"] } ``` ``` -------------------------------- ### Get Label Values (job) Source: https://context7.com/grafana/loki-mcp/llms.txt Retrieves all unique values for the 'job' label from Loki. ```APIDOC ## POST /mcp ### Description Retrieves all unique values for a specified label from Grafana Loki. ### Method POST ### Endpoint /mcp ### Parameters #### Request Body - **jsonrpc** (string) - Required - Specifies the JSON-RPC version. - **id** (string) - Required - The ID of the request. - **method** (string) - Required - The method to call, must be "tools/call". - **params** (object) - Required - Parameters for the method call. - **name** (string) - Required - The name of the tool to call, must be "loki_label_values". - **arguments** (object) - Required - Arguments for the "loki_label_values" tool. - **label** (string) - Required - The label for which to retrieve values (e.g., "job"). - **url** (string) - Required - The URL of the Loki instance. - **start** (string) - Optional - The start time for the query (e.g., "-24h"). - **end** (string) - Optional - The end time for the query (e.g., "now"). - **format** (string) - Optional - The desired output format ("raw" or "json"). Defaults to "raw". ### Request Example ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_label_values", "arguments": { "label": "job", "url": "http://localhost:3100", "start": "-24h", "end": "now", "format": "raw" } } } ``` ### Response #### Success Response (200) - **jsonrpc** (string) - The JSON-RPC version. - **id** (string) - The ID of the request. - **result** (string or object) - The result of the operation. For "raw" format, it's a string with one value per line. For "json" format, it's an object containing the label values. #### Response Example (raw format) ``` varlogs nginx api-server postgres ``` #### Response Example (json format) ```json { "status": "success", "data": ["production", "staging", "development"] } ``` ``` -------------------------------- ### loki_label_names - Get All Label Names Source: https://context7.com/grafana/loki-mcp/llms.txt Retrieves all available label names from Loki within a specified time range. Supports authentication and time range parameters. ```APIDOC ## POST /mcp (JSON-RPC) ### Description Retrieves all available label names from Grafana Loki. ### Method POST ### Endpoint /mcp ### Parameters #### Request Body - **jsonrpc** (string) - Required - JSON-RPC version, must be "2.0". - **id** (string) - Required - Unique identifier for the request. - **method** (string) - Required - The method to call, must be "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the tool, must be "loki_label_names". - **arguments** (object) - Required - Arguments for the "loki_label_names" tool. - **url** (string) - Optional - The URL of the Grafana Loki instance. Defaults to the LOKI_URL environment variable. - **start** (string) - Optional - The start time for the query. Can be a relative duration (e.g., "-24h") or an absolute RFC3339 timestamp. Defaults to the beginning of the available data. - **end** (string) - Optional - The end time for the query. Can be a relative duration (e.g., "-1h") or an absolute RFC3339 timestamp. Defaults to "now". - **format** (string) - Optional - The output format. Supported values: "raw", "json", "text". Defaults to "raw". - **org** (string) - Optional - The organization ID for multi-tenant setups. Defaults to the LOKI_ORG_ID environment variable. - **username** (string) - Optional - Username for basic authentication. Defaults to the LOKI_USERNAME environment variable. - **password** (string) - Optional - Password for basic authentication. Defaults to the LOKI_PASSWORD environment variable. - **token** (string) - Optional - Bearer token for authentication. Defaults to the LOKI_TOKEN environment variable. ### Request Example ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_label_names", "arguments": { "url": "http://localhost:3100", "start": "-24h", "end": "now", "format": "raw" } } } ``` ### Response #### Success Response (200) - **jsonrpc** (string) - JSON-RPC version. - **id** (string) - Request ID. - **result** (string or object) - The label names. Format depends on the `format` argument. #### Response Example (raw/text format) ``` job app env level host ``` #### Response Example (json format) ```json { "status": "success", "data": ["job", "app", "env", "level", "host"] } ``` ``` -------------------------------- ### loki_label_values - Get Values for a Specific Label Source: https://context7.com/grafana/loki-mcp/llms.txt Retrieves all values for a specific label name from Loki. Supports authentication and time range parameters. ```APIDOC ## POST /mcp (JSON-RPC) ### Description Retrieves all values for a specific label name from Grafana Loki. ### Method POST ### Endpoint /mcp ### Parameters #### Request Body - **jsonrpc** (string) - Required - JSON-RPC version, must be "2.0". - **id** (string) - Required - Unique identifier for the request. - **method** (string) - Required - The method to call, must be "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the tool, must be "loki_label_values". - **arguments** (object) - Required - Arguments for the "loki_label_values" tool. - **labelName** (string) - Required - The name of the label for which to retrieve values. - **url** (string) - Optional - The URL of the Grafana Loki instance. Defaults to the LOKI_URL environment variable. - **start** (string) - Optional - The start time for the query. Can be a relative duration (e.g., "-24h") or an absolute RFC3339 timestamp. Defaults to the beginning of the available data. - **end** (string) - Optional - The end time for the query. Can be a relative duration (e.g., "-1h") or an absolute RFC3339 timestamp. Defaults to "now". - **format** (string) - Optional - The output format. Supported values: "raw", "json", "text". Defaults to "raw". - **org** (string) - Optional - The organization ID for multi-tenant setups. Defaults to the LOKI_ORG_ID environment variable. - **username** (string) - Optional - Username for basic authentication. Defaults to the LOKI_USERNAME environment variable. - **password** (string) - Optional - Password for basic authentication. Defaults to the LOKI_PASSWORD environment variable. - **token** (string) - Optional - Bearer token for authentication. Defaults to the LOKI_TOKEN environment variable. ### Request Example ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_label_values", "arguments": { "labelName": "job", "url": "http://localhost:3100", "start": "-24h", "end": "now", "format": "json" } } } ``` ### Response #### Success Response (200) - **jsonrpc** (string) - JSON-RPC version. - **id** (string) - Request ID. - **result** (string or object) - The label values. Format depends on the `format` argument. #### Response Example (json format) ```json { "status": "success", "data": ["varlogs", "promtail", "fluentd"] } ``` #### Response Example (raw/text format) ``` varlogs promtail fluentd ``` ``` -------------------------------- ### Get Values for a Specific Label with loki_label_values Source: https://context7.com/grafana/loki-mcp/llms.txt The `loki_label_values` tool retrieves all values for a specified label name from Grafana Loki. This is useful for discovering available values for a label to refine LogQL queries. It supports similar parameters as other tools. -------------------------------- ### Build and Run Loki MCP Server and Client Source: https://context7.com/grafana/loki-mcp/llms.txt Instructions for building and running the Loki MCP server and its associated test client. This involves using Go build commands and setting environment variables for configuration. ```bash go build -o loki-mcp-server ./cmd/server ./loki-mcp-server go build -o loki-mcp-client ./cmd/client ``` -------------------------------- ### Build and Configure Loki MCP Server Source: https://github.com/grafana/loki-mcp/blob/main/README.md Commands to build the server binary or prepare shell scripts for integration with Claude Desktop. ```bash go build -o loki-mcp-server ./cmd/server chmod +x run-mcp-server.sh ``` -------------------------------- ### List Available Tools Source: https://context7.com/grafana/loki-mcp/llms.txt Lists all available tools that can be called via the MCP endpoint. ```APIDOC ## POST /mcp ### Description Lists all available tools that can be executed by the MCP server. ### Method POST ### Endpoint /mcp ### Parameters #### Request Body - **jsonrpc** (string) - Required - Specifies the JSON-RPC version. - **id** (string) - Required - The ID of the request. - **method** (string) - Required - The method to call, must be "tools/list". - **params** (object) - Required - Parameters for the method call. Should be an empty object for this method. ### Request Example ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/list", "params": {} } ``` ### Response #### Success Response (200) - **jsonrpc** (string) - The JSON-RPC version. - **id** (string) - The ID of the request. - **result** (object) - An object containing a list of available tools. - **tools** (array) - A list of tool objects. - **name** (string) - The name of the tool. - **description** (string) - A description of the tool's functionality. #### Response Example ```json { "jsonrpc": "2.0", "id": "1", "result": { "tools": [ {"name": "loki_query", "description": "Run a query against Grafana Loki"}, {"name": "loki_label_names", "description": "Get all label names from Loki"}, {"name": "loki_label_values", "description": "Get all values for a specific label from Loki"} ] } } ``` ``` -------------------------------- ### Establish SSE Connection and Handle Loki Streams Source: https://github.com/grafana/loki-mcp/blob/main/examples/sse-client.html This snippet demonstrates how to initialize an EventSource connection to the Loki MCP server. It includes logic to parse incoming JSON events, specifically handling 'loki_query_result' types by formatting stream labels and converting nanosecond timestamps to ISO strings for display. ```javascript let eventSource = null; function connect() { if (eventSource) return; eventSource = new EventSource('http://localhost:8080/sse'); eventSource.onmessage = (event) => { try { const eventData = JSON.parse(event.data); if (eventData.type === 'loki_query_result') { eventData.results.data.result.forEach((entry) => { entry.values.forEach(val => { const timestamp = new Date(parseFloat(val[0]) / 1000000).toISOString(); console.log(`[${timestamp}] ${val[1]}`); }); }); } } catch (e) { console.error('Failed to parse event', e); } }; } function disconnect() { if (eventSource) { eventSource.close(); eventSource = null; } } ``` -------------------------------- ### Deploy Loki MCP with Docker Source: https://context7.com/grafana/loki-mcp/llms.txt Commands to build, run, and manage the Loki MCP server environment using Docker and Docker Compose. ```bash docker build -t loki-mcp-server . docker-compose up -d ./test-loki-query.sh '{job="varlogs"}' ``` -------------------------------- ### Configure Loki MCP Environment Variables Source: https://context7.com/grafana/loki-mcp/llms.txt This snippet demonstrates how to set up the Loki MCP server using environment variables. It covers connection settings, authentication methods (Basic and Bearer token), and server port configuration. ```bash export LOKI_URL="https://loki.example.com" export LOKI_ORG_ID="production" export LOKI_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." export PORT="8080" ./loki-mcp-server ``` -------------------------------- ### Configure Loki MCP Server in Claude Desktop Source: https://github.com/grafana/loki-mcp/blob/main/README.md A JSON configuration template for the Claude Desktop application to enable the Loki MCP server. It defines the command path, environment variables for authentication, and auto-approval settings for specific tools. ```json { "mcpServers": { "lokiserver": { "command": "path/to/loki-mcp-server", "args": [], "env": { "LOKI_URL": "http://localhost:3100", "LOKI_ORG_ID": "your-default-org-id", "LOKI_USERNAME": "your-username", "LOKI_PASSWORD": "your-password", "LOKI_TOKEN": "your-bearer-token" }, "disabled": false, "autoApprove": ["loki_query"] } } } ``` -------------------------------- ### Query Grafana Loki Logs with loki_query Tool Source: https://context7.com/grafana/loki-mcp/llms.txt Demonstrates how to use the `loki_query` tool to fetch log entries from Grafana Loki. It covers basic queries, time range specification, limiting results, multi-tenancy, and various authentication methods (basic auth, bearer tokens). ```bash # Basic query using environment variable for URL export LOKI_URL="http://localhost:3100" ./loki-mcp-client loki_query "{job=\"varlogs\"}" # Query with explicit URL, time range, and limit ./loki-mcp-client loki_query http://localhost:3100 "{job=\"varlogs\"}" "-1h" "now" 100 # Query with organization ID for multi-tenant setups export LOKI_ORG_ID="tenant-123" ./loki-mcp-client loki_query "{job=\"varlogs\"}" # Query with authentication export LOKI_URL="http://localhost:3100" export LOKI_USERNAME="admin" export LOKI_PASSWORD="password" ./loki-mcp-client loki_query "{job=\"varlogs\"}" # Query with bearer token authentication export LOKI_URL="http://localhost:3100" export LOKI_TOKEN="your-bearer-token" ./loki-mcp-client loki_query "{job=\"varlogs\"}" # Filter for error logs only ./loki-mcp-client loki_query '{job="varlogs"} |= \"ERROR\"' ``` ```bash # Direct curl to SSE endpoint (JSON-RPC format) curl -X POST http://localhost:8080/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_query", "arguments": { "query": "{job=\"varlogs\"}", "url": "http://localhost:3100", "start": "-1h", "end": "now", "limit": 100, "format": "raw" } } }' ``` ```text # Response format (raw): # 2024-01-15T10:30:00Z {job=varlogs,app=myapp} INFO: Application started successfully # 2024-01-15T10:30:05Z {job=varlogs,app=myapp} ERROR: Connection timeout occurred ``` -------------------------------- ### Run Loki MCP Server via Docker Source: https://github.com/grafana/loki-mcp/blob/main/README.md Build and execute the Loki MCP server container with port mapping to enable SSE communication. ```bash docker build -t loki-mcp-server . docker run -p 8080:8080 --rm -i loki-mcp-server ``` -------------------------------- ### Query Loki Label Values via JSON-RPC Source: https://context7.com/grafana/loki-mcp/llms.txt Demonstrates how to fetch label values from Loki using the MCP tools/call method. Supports both raw text and JSON output formats. ```bash curl -X POST http://localhost:8080/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_label_values", "arguments": { "label": "job", "url": "http://localhost:3100", "start": "-24h", "end": "now", "format": "raw" } } }' ``` -------------------------------- ### Establish and Manage SSE Connection in JavaScript Source: https://github.com/grafana/loki-mcp/blob/main/examples/simple-sse-client.html This script manages the lifecycle of a Server-Sent Events connection. It includes functions to connect to the endpoint, handle incoming messages, manage error states, and gracefully disconnect. ```javascript let eventSource = null; const eventsContainer = document.getElementById('events'); const connectButton = document.getElementById('connect'); const disconnectButton = document.getElementById('disconnect'); const statusElement = document.getElementById('status'); function addEvent(text) { const eventElement = document.createElement('div'); eventElement.className = 'event'; eventElement.textContent = `${new Date().toLocaleTimeString()}: ${text}`; eventsContainer.appendChild(eventElement); eventsContainer.scrollTop = eventsContainer.scrollHeight; } function connect() { if (eventSource) { return; } try { eventSource = new EventSource('http://localhost:8081/sse'); eventSource.onopen = function() { statusElement.textContent = 'Connected'; connectButton.disabled = true; disconnectButton.disabled = false; addEvent('Connection established'); }; eventSource.onmessage = function(event) { addEvent(`Received: ${event.data}`); }; eventSource.onerror = function(error) { addEvent('Connection error'); disconnect(); }; addEvent('Connecting to SSE endpoint...'); } catch (error) { addEvent(`Error: ${error.message}`); } } function disconnect() { if (eventSource) { eventSource.close(); eventSource = null; statusElement.textContent = 'Disconnected'; connectButton.disabled = false; disconnectButton.disabled = true; addEvent('Disconnected from SSE endpoint'); } } connectButton.addEventListener('click', connect); disconnectButton.addEventListener('click', disconnect); ``` -------------------------------- ### Handle Connection Events in JavaScript Source: https://github.com/grafana/loki-mcp/blob/main/examples/sse-client.html This snippet demonstrates how to handle click events for connect and disconnect buttons using JavaScript. It also includes a function to log events, which is useful for debugging and monitoring the state of the SSE client. The code disables the disconnect button when the client is not connected. ```javascript ectButton.disabled = true; } } connectButton.addEventListener('click', connect); disconnectButton.addEventListener('click', disconnect); // Log initial state logEvent('SSE client initialized. Click "Connect" to establish connection.'); ``` -------------------------------- ### SSE Client Connection Source: https://github.com/grafana/loki-mcp/blob/main/examples/simple-sse-client.html This snippet demonstrates how to connect to the Loki MCP Server's SSE endpoint using JavaScript's EventSource API, handle incoming messages, and manage connection status. ```APIDOC ## GET /sse ### Description This endpoint provides a stream of events from the Loki MCP Server using Server-Sent Events (SSE). ### Method GET ### Endpoint /sse ### Parameters None ### Request Example This endpoint is accessed via a client-side script that establishes an EventSource connection. ### Response #### Success Response (200 OK) - Content-Type: text/event-stream - The response body is a stream of events, each formatted according to the SSE specification. #### Response Example ``` data: {"message": "System status updated"} ``` ### Client-Side JavaScript Example ```javascript let eventSource = null; const eventsContainer = document.getElementById('events'); const connectButton = document.getElementById('connect'); const disconnectButton = document.getElementById('disconnect'); const statusElement = document.getElementById('status'); function addEvent(text) { const eventElement = document.createElement('div'); eventElement.className = 'event'; eventElement.textContent = `${new Date().toLocaleTimeString()}: ${text}`; eventsContainer.appendChild(eventElement); eventsContainer.scrollTop = eventsContainer.scrollHeight; } function connect() { if (eventSource) { return; } try { // Connect to the SSE endpoint eventSource = new EventSource('http://localhost:8081/sse'); // Connection opened eventSource.onopen = function() { statusElement.textContent = 'Connected'; connectButton.disabled = true; disconnectButton.disabled = false; addEvent('Connection established'); }; // Listen for messages eventSource.onmessage = function(event) { addEvent(`Received: ${event.data}`); }; // Handle errors eventSource.onerror = function(error) { addEvent('Connection error'); disconnect(); }; addEvent('Connecting to SSE endpoint...'); } catch (error) { addEvent(`Error: ${error.message}`); } } function disconnect() { if (eventSource) { eventSource.close(); eventSource = null; statusElement.textContent = 'Disconnected'; connectButton.disabled = false; disconnectButton.disabled = true; addEvent('Disconnected from SSE endpoint'); } } // Add event listeners connectButton.addEventListener('click', connect); disconnectButton.addEventListener('click', disconnect); // Initial state disconnect(); // Ensure buttons are in the correct initial state ``` -------------------------------- ### SSE Endpoint Source: https://context7.com/grafana/loki-mcp/llms.txt Connects to the Server-Sent Events (SSE) endpoint for real-time event streaming. ```APIDOC ## GET /sse ### Description Connects to the Server-Sent Events (SSE) endpoint to receive real-time events and data streams from the MCP server. ### Method GET ### Endpoint /sse ### Parameters None ### Request Example ```bash curl -N http://localhost:8080/sse ``` ### Response #### Success Response (200) - The response is a stream of Server-Sent Events. The format of each event depends on the type of data being streamed. #### Response Example (Example event format, actual format may vary) ``` event: update data: {"message": "New log entry received"} ``` ``` -------------------------------- ### loki_query - Query Grafana Loki Logs Source: https://context7.com/grafana/loki-mcp/llms.txt Executes LogQL queries against a Grafana Loki instance and returns matching log entries. Supports flexible time ranges, authentication, and multi-tenancy. ```APIDOC ## POST /mcp (JSON-RPC) ### Description Executes a LogQL query against a Grafana Loki instance. ### Method POST ### Endpoint /mcp ### Parameters #### Request Body - **jsonrpc** (string) - Required - JSON-RPC version, must be "2.0". - **id** (string) - Required - Unique identifier for the request. - **method** (string) - Required - The method to call, must be "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the tool, must be "loki_query". - **arguments** (object) - Required - Arguments for the "loki_query" tool. - **query** (string) - Required - The LogQL query to execute. - **url** (string) - Optional - The URL of the Grafana Loki instance. Defaults to the LOKI_URL environment variable. - **start** (string) - Optional - The start time for the query. Can be a relative duration (e.g., "-1h") or an absolute RFC3339 timestamp. Defaults to the beginning of the available data. - **end** (string) - Optional - The end time for the query. Can be a relative duration (e.g., "-30m") or an absolute RFC3339 timestamp. Defaults to "now". - **limit** (integer) - Optional - The maximum number of log lines to return. Defaults to no limit. - **format** (string) - Optional - The output format. Supported values: "raw", "json". Defaults to "raw". - **org** (string) - Optional - The organization ID for multi-tenant setups. Defaults to the LOKI_ORG_ID environment variable. - **username** (string) - Optional - Username for basic authentication. Defaults to the LOKI_USERNAME environment variable. - **password** (string) - Optional - Password for basic authentication. Defaults to the LOKI_PASSWORD environment variable. - **token** (string) - Optional - Bearer token for authentication. Defaults to the LOKI_TOKEN environment variable. ### Request Example ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_query", "arguments": { "query": "{job=\"varlogs\"}", "url": "http://localhost:3100", "start": "-1h", "end": "now", "limit": 100, "format": "raw" } } } ``` ### Response #### Success Response (200) - **jsonrpc** (string) - JSON-RPC version. - **id** (string) - Request ID. - **result** (string or object) - The query result, format depends on the `format` argument. #### Response Example (raw format) ``` 2024-01-15T10:30:00Z {job=varlogs,app=myapp} INFO: Application started successfully 2024-01-15T10:30:05Z {job=varlogs,app=myapp} ERROR: Connection timeout occurred ``` #### Response Example (json format) ```json { "status": "success", "data": [ { "ts": "2024-01-15T10:30:00Z", "line": "{job=varlogs,app=myapp} INFO: Application started successfully" }, { "ts": "2024-01-15T10:30:05Z", "line": "{job=varlogs,app=myapp} ERROR: Connection timeout occurred" } ] } ``` ``` -------------------------------- ### Retrieve All Label Names from Loki with loki_label_names Source: https://context7.com/grafana/loki-mcp/llms.txt This tool retrieves all available label names from Grafana Loki within a specified time range. It supports the same authentication and time range parameters as the query tool and can return results in raw or JSON format. ```bash # JSON-RPC request to get all label names curl -X POST http://localhost:8080/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_label_names", "arguments": { "url": "http://localhost:3100", "start": "-24h", "end": "now", "format": "raw" } } }' ``` ```text # Response format (raw - one label per line): # job # app # env # level # host ``` ```json # Response format (json): # { # "status": "success", # "data": ["job", "app", "env", "level", "host"] # } ``` ```bash # With authentication for multi-tenant setup curl -X POST http://localhost:8080/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "loki_label_names", "arguments": { "url": "http://localhost:3100", "org": "tenant-123", "token": "your-bearer-token", "format": "text" } } }' ``` -------------------------------- ### Streamable HTTP Endpoint Source: https://context7.com/grafana/loki-mcp/llms.txt Utilizes the Streamable HTTP endpoint for an alternative HTTP-based data transport. ```APIDOC ## GET /stream ### Description Accesses the Streamable HTTP endpoint, providing an alternative HTTP-based transport for data streams. ### Method GET ### Endpoint /stream ### Parameters None ### Request Example ```bash curl http://localhost:8080/stream ``` ### Response #### Success Response (200) - The response is a stream of data over HTTP. The specific format depends on the data being transmitted. #### Response Example (Example data format, actual format may vary) ``` {"data": "streamed content"} ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.