Menu
Grafana Cloud

MCP observability setup

MCP Observability provides comprehensive monitoring for Model Context Protocol (MCP) implementations, enabling AI models to securely connect to data sources and interact with external tools.

Install the instrumentation SDK

Install the OpenLIT SDK in your Python environment:

Bash
pip install openlit

Configure OTEL environment variables

Get your Grafana Cloud OTEL credentials

If you haven’t already obtained your OTEL credentials during the main AI Observability setup, follow these steps:

  1. Sign in to Grafana Cloud and go to the Grafana Cloud Portal
  2. Select your organization if you have access to multiple
  3. Click your stack from the sidebar or main stack list
  4. Under Manage your stack, click the Configure button in the OpenTelemetry section
  5. Scroll down to the Password / API Token section and click Generate now (if you don’t have a token)
  6. Enter a name for the token and click Create token
  7. Click Close - you don’t need to copy the token manually
  8. Scroll down and copy the OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS values from the Environment variables section

Set the environment variables

Set up the OpenTelemetry endpoints using the values you copied:

Bash
export OTEL_EXPORTER_OTLP_ENDPOINT="<YOUR_GRAFANA_OTEL_GATEWAY_URL>"
export OTEL_EXPORTER_OTLP_HEADERS="<YOUR_GRAFANA_OTEL_GATEWAY_AUTH>"

Replace the values with those you copied:

  • Replace <YOUR_GRAFANA_OTEL_GATEWAY_URL> with the OTEL_EXPORTER_OTLP_ENDPOINT value
    Example: https://otlp-gateway-<ZONE>.grafana.net/otlp
  • Replace <YOUR_GRAFANA_OTEL_GATEWAY_AUTH> with the OTEL_EXPORTER_OTLP_HEADERS value
    Example: Authorization=Basic%20<BASE64 ENCODED INSTANCE ID AND API TOKEN>

Instrument your application

Add the following two lines to your application code:

Python
import openlit

openlit.init()

The OpenLIT SDK automatically uses the OTEL environment variables to send telemetry data to your Grafana Cloud instance.

Examples by implementation type

MCP client

Python
import openlit
from mcp import Client

openlit.init()

# MCP client operations are automatically instrumented
client = Client("http://mcp-server:8080")
tools = client.list_tools()
result = client.call_tool("search_documents", {"query": "AI observability"})

MCP server

Python
import openlit
from mcp import Server

openlit.init()

# MCP server operations are automatically tracked
server = Server()

@server.tool("search_documents")
def search_documents(query: str):
    # Tool logic is automatically instrumented
    results = document_search(query)
    return results

# Start server - all tool calls are tracked
server.run(host="localhost", port=8080)

Refer to the OpenLIT documentation for more MCP implementations.

Visualize and analyze

With the MCP Observability data now being collected and sent to Grafana Cloud, the next step is to visualize and analyze this data to get insights into your Model Context Protocol usage, performance, and identify areas of improvement.

Navigate to the MCP Observability dashboard in your Grafana Cloud instance to start exploring. The dashboard provides:

  • Tool performance - Call latency and success rates
  • Protocol health - Session stability and connection metrics
  • Resource usage - Data access patterns and performance
  • Error tracking - Failed operations and troubleshooting data