Instana

Instana

The community for performance and observability professionals to learn, to share ideas, and to connect with others.

 View Only

Observe MCP agent with Instana

By Felix George posted 26 days ago

  

Authors: @Felix George, @Harshit Kumar

Co-Authors: @Jayanth Putta, @Guangya Liu, @Madhu Tadiparthi@Adharsh H

Introduction

In today’s fast-paced digital world, observability is no longer optional—it’s essential. As applications—particularly autonomous AI agents—grow in complexity, gaining visibility into their behaviour becomes critical. This visibility is not only essential for ensuring system reliability and uptime but also for optimizing performance and proactively mitigating potential failures. AI Agents operate in dynamic, non-linear environments where decisions are data driven. This makes robust observability indispensable for tracing errors, validating decision logic, and identifying bottlenecks in real time.

Figure 1: An Agentic Application with MCP client interaction with an MCP Server
Figure 1: An Agentic Application with MCP client interaction with an MCP Server 

The Model Context Protocol (MCP) provides AI agents with a simple, standardised mechanism to integrate a wide range of contextual sources—including tools, resources, and prompts. As MCP adoption accelerates at an unprecedented pace, observability within this framework becomes increasingly critical. The true innovation of MCP lies in its transformation of tool usage: moving from static, hard-coded integrations to adaptive, context-aware processes. By enabling real-time discovery, dynamic parameter mapping, and error handling, MCP servers empower AI agents to operate autonomously and efficiently. This unlocks advanced capabilities across automation, intelligent decision-making, and personalized experiences. A catalogue of available MCP servers can be accessed at mcp.so. Instrumenting observability for MCP agents allows developers and AI operations teams to gain actionable insights, including: 

  • Which MCP server the agent is communicating with 

  • The set of tools returned by the MCP server to the client 

  • The specific tool invoked by the client in response to a given query 

In addition to understanding this contextual flow, observability enables teams to: 

  • Detect and Diagnose system failures or suboptimal behaviours 

  • Audit decisions made by AI agents 

  • Fine-tune agent performance and coordination based on trace data 

In this article, we walk through how to instrument an MCP agent using Traceloop to emit traces for each decision cycle. We’ll then show how to route this data to Instana, where dedicated dashboards—such as Workflow View and Tool View—visualise the agent’s real-time performance, tool usage patterns, and decision-making flow. This instrumentation is especially useful in debugging complex agentic loops, validating tool selection logic, and ensuring that autonomous behaviour aligns with system-level objectives.

Example MCP agent - Weather MCP Client and Server 

We begin by implementing a simple LangGraph-based agent that allows users to ask natural language questions about the weather. The system comprises two core components: 

  • An MCP Client (agent.py) that acts as the AI agent interface 

  • An MCP Server (weather.py) that exposes weather-related tools over HTTP using FastMCP, listening on port 8000 

Figure 2: AI Agent with weather MCP server
Figure 2: AI Agent with weather MCP server 

The MCP server implements two tools: 

  • get_weather_alerts: returns current weather alerts for a given U.S. state code (e.g., CA, NY) 

  • get_forecast: returns the weather forecast for a specific latitude and longitude 

Both tools internally fetch data from the U.S. National Weather Service via the https://api.weather.gov API, using appropriate endpoints. 

The MCP Client works in coordination with a language model (LLM)-powered AI agent. It receives a user query and executes the following workflow (illustrated in Figure 2): 

  1. Tool Discovery: It queries the MCP server to obtain a list of available tools. 

  1. Tool Selection: It passes the user query and tool metadata to the LLM, which determines the most suitable tool to invoke. 

  1. Tool Invocation: It invokes the selected tool through the MCP protocol, passing the appropriate parameters. 

This setup supports natural variation in user queries. For example: 

  • If the user asks, "How's the weather going to be in Utah?", the agent recognizes Utah as a state, maps it to state code UT, and invokes the get_weather_alerts tool. 

  • If the user instead asks, "What’s the weather like in Austin?", the agent identifies Austin as a city, resolves its coordinates (latitude/longitude), and invokes get_forecast. 

Using Instana to Observe MCP Agent

The complete code for the MCP-based agent—including the server (weather.py) and the client (agent.py)—is available in the following GitHub Enterprise repository: 
👉 Agentic Tool Monitoring – GitHub (IBM) 

To enable observability for this MCP agent using Traceloop and monitor performance with Instana (link), follow the setup instructions provided in the README.md file in the repository. The setup includes: 

  1. Cloning the repository 
    Clone the repo from: Link

  1. Environment configuration 
    Set up the runtime environment for the MCP server, the LangGraph-based agent, and Traceloop-based OpenTelemetry instrumentation (link). 

  1. Instana agent setup (link) 
    Instana can collect OpenTelemetry data in two ways: either through its agent or directly to its backend without needing an agent (link). In this blog, we are using an Instana agent to collect traces and route them to the Instana backend, as illustrated in Figure 3.  

Configure the Instana agent to collect and analyze trace data from the MCP server and agent. This includes wiring up trace export pipelines for visualising task execution, tool invocation, and latency breakdowns. For addition details on Instana Agent installation, reference to the following resource 

 

Given the importance of understanding the internal behaviour of agentic applications—for both debugging and trust-building—we use Traceloop to instrument the MCP server with OpenTelemetry. This allows developers to trace the full lifecycle of a query, from the agent's decision-making process to tool execution and response. Additionally, Instana can be used not only to visualise trace data but also to set up alerts and performance validations for tool behaviour. Figure 3 illustrates the flow of trace and trace metadata from the agent and MCP server to Instana backend via the Instana agent. 

Figure 3: Flow diagram of MCP Agent instrumentation through traceloop with traces flowing into Instana dashboard
Figure 3: Flow diagram of MCP Agent instrumentation through traceloop with traces flowing into Instana dashboard 

This setup is fully instrumented for observability using Traceloop and Instana. The Instana dashboard surfaces rich telemetry, including: 

  • Which tool was invoked and by which user query 

  • Execution time, token usage, and latency for each tool call 

  • Tool invocation success/failure rates 

  • Number of tool invocations per session or user query 

Such observability is critical for AI support engineers to debug agent behaviour, identify the root cause of cost spikes (e.g., high token usage or repeated tool retries), and optimise overall agent performance. 

Observing your MCP agent through Instana  

With the MCP agent up and running and traces instrumented through Traceloop, you can use Instana to observe its internal behaviour. Instana’s observability features enable detailed analysis of traces and tool calls, helping you understand how the agent interacts with tools and services. More information on analyzing traces and calls using Instana can be found here. 

Figure 4: List of tools returned by the MCP Server, which includes get_weather_alerts and get_forecast. 

As shown in Figure 4, Instana’s performance monitoring provides a trace view that displays the list of tools returned by the MCP server in response to a user query. This visibility is especially valuable for support engineers, as it allows them to verify which tools were made available to the agent for a specific request. 

The workflow views in Figures 5 and 6 illustrate the invocation of the get_weather_alerts tool in response to the user query: "Get me weather alerts and forecast for NYC." These diagrams provide a clear, step-by-step depiction of how the query is processed and how the appropriate tools are executed. 

Within the central white panel of the workflow view, several key metrics are presented that are especially valuable for support engineers. These include: 

  • Sub calls - The total number of sub-calls (spans) made 

  • Erroneous Calls - The count of erroneous calls (spans) 

  • Error Logs - The number of error logs generated 

  • Warn Logs. -The number of warning logs generated 

  • Duration - The overall execution duration 

These insights are essential for diagnosing issues, evaluating performance, and understanding agent behaviour in production.

Figure 5: panel in the right illustrate the input user query 

Figure 6: shows invocation of mcp tool, get_weather_alerts 

Note that the user query requests both weather alerts and forecasts. As a result, in addition to the get_weather_alerts tool, the get_forecast_tool is also invoked—this behaviour is depicted in Figure 7 below. 

Figure 7: shows invocation of second mcp tool, get_forecast 

And since there are two tool invocations, the final output is the weather alert for today followed by the forecast for the NYC state, as illustrated in the Figure 8 below.

Figure 8: shows the final output, presenting both the current weather and the forecast for the NYC.

Finally, the custom dashboard shown in Figure 9 presents an aggregate view of tool-level statistics for an MCP agent over a defined time period. Specifically, it displays: 

  • Tool usage distribution – Highlights how frequently each tool is invoked, helping assess usage patterns. 

  • Tool latency metrics – Shows average and peak response times, enabling identification of performance bottlenecks. 

  • Total number of tool invocations – Indicates overall tool activity volume to understand workload characteristics.

  • Count of tool call errors – Tracks failure occurrences to help pinpoint unstable or misconfigured tools.

These insights enable support engineers to quickly identify patterns in tool usage, diagnose latency or failure issues, and take corrective action to address potential problems proactively.

Figure 9: Tool Dashboard in Instana 

Conclusion

In conclusion, the integration of Model Context Protocol (MCP) agents with robust observability platforms like Instana is no longer a luxury but a critical necessity in the evolving landscape of AI-driven applications. As demonstrated through the practical example of the weather MCP client and server, instrumenting AI agents with Traceloop and OpenTelemetry provides unparalleled visibility into their decision-making processes, tool interactions, and overall performance. The detailed workflow views, tool invocation insights, and aggregated metrics offered by Instana empower developers and AI operations teams to proactively identify bottlenecks, debug complex agentic loops, and ensure the alignment of autonomous behavior with system objectives. This comprehensive observability is fundamental for building trust, optimising performance, and ensuring the reliability of intelligent agents in production environments, ultimately paving the way for more sophisticated and dependable AI applications. 


#Agent
#Alerting
#CustomDashboards
#OpenTelemetry
#Tracing
#SRE
#Tutorial

0 comments
59 views

Permalink