mcp-instana 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. mcp_instana-0.2.0.dist-info/METADATA +1229 -0
  2. mcp_instana-0.2.0.dist-info/RECORD +59 -0
  3. {mcp_instana-0.1.0.dist-info → mcp_instana-0.2.0.dist-info}/WHEEL +1 -1
  4. mcp_instana-0.2.0.dist-info/entry_points.txt +4 -0
  5. mcp_instana-0.1.0.dist-info/LICENSE → mcp_instana-0.2.0.dist-info/licenses/LICENSE.md +3 -3
  6. src/application/__init__.py +1 -0
  7. src/{client/application_alert_config_mcp_tools.py → application/application_alert_config.py} +251 -273
  8. src/application/application_analyze.py +628 -0
  9. src/application/application_catalog.py +155 -0
  10. src/application/application_global_alert_config.py +653 -0
  11. src/{client/application_metrics_mcp_tools.py → application/application_metrics.py} +113 -131
  12. src/{client/application_resources_mcp_tools.py → application/application_resources.py} +131 -151
  13. src/application/application_settings.py +1731 -0
  14. src/application/application_topology.py +111 -0
  15. src/automation/action_catalog.py +416 -0
  16. src/automation/action_history.py +338 -0
  17. src/core/__init__.py +1 -0
  18. src/core/server.py +586 -0
  19. src/core/utils.py +213 -0
  20. src/event/__init__.py +1 -0
  21. src/event/events_tools.py +850 -0
  22. src/infrastructure/__init__.py +1 -0
  23. src/{client/infrastructure_analyze_mcp_tools.py → infrastructure/infrastructure_analyze.py} +207 -206
  24. src/{client/infrastructure_catalog_mcp_tools.py → infrastructure/infrastructure_catalog.py} +197 -265
  25. src/infrastructure/infrastructure_metrics.py +171 -0
  26. src/{client/infrastructure_resources_mcp_tools.py → infrastructure/infrastructure_resources.py} +198 -227
  27. src/{client/infrastructure_topology_mcp_tools.py → infrastructure/infrastructure_topology.py} +110 -109
  28. src/log/__init__.py +1 -0
  29. src/log/log_alert_configuration.py +331 -0
  30. src/prompts/__init__.py +16 -0
  31. src/prompts/application/__init__.py +1 -0
  32. src/prompts/application/application_alerts.py +54 -0
  33. src/prompts/application/application_catalog.py +26 -0
  34. src/prompts/application/application_metrics.py +57 -0
  35. src/prompts/application/application_resources.py +26 -0
  36. src/prompts/application/application_settings.py +75 -0
  37. src/prompts/application/application_topology.py +30 -0
  38. src/prompts/events/__init__.py +1 -0
  39. src/prompts/events/events_tools.py +161 -0
  40. src/prompts/infrastructure/infrastructure_analyze.py +72 -0
  41. src/prompts/infrastructure/infrastructure_catalog.py +53 -0
  42. src/prompts/infrastructure/infrastructure_metrics.py +45 -0
  43. src/prompts/infrastructure/infrastructure_resources.py +74 -0
  44. src/prompts/infrastructure/infrastructure_topology.py +38 -0
  45. src/prompts/settings/__init__.py +0 -0
  46. src/prompts/settings/custom_dashboard.py +157 -0
  47. src/prompts/website/__init__.py +1 -0
  48. src/prompts/website/website_analyze.py +35 -0
  49. src/prompts/website/website_catalog.py +40 -0
  50. src/prompts/website/website_configuration.py +105 -0
  51. src/prompts/website/website_metrics.py +34 -0
  52. src/settings/__init__.py +1 -0
  53. src/settings/custom_dashboard_tools.py +417 -0
  54. src/website/__init__.py +0 -0
  55. src/website/website_analyze.py +433 -0
  56. src/website/website_catalog.py +171 -0
  57. src/website/website_configuration.py +770 -0
  58. src/website/website_metrics.py +241 -0
  59. mcp_instana-0.1.0.dist-info/METADATA +0 -649
  60. mcp_instana-0.1.0.dist-info/RECORD +0 -19
  61. mcp_instana-0.1.0.dist-info/entry_points.txt +0 -3
  62. src/client/What is the sum of queue depth for all q +0 -55
  63. src/client/events_mcp_tools.py +0 -531
  64. src/client/instana_client_base.py +0 -93
  65. src/client/log_alert_configuration_mcp_tools.py +0 -316
  66. src/client/show the top 5 services with the highest +0 -28
  67. src/mcp_server.py +0 -343
@@ -0,0 +1,171 @@
1
+ """
2
+ Infrastructure Metrics MCP Tools Module
3
+
4
+ This module provides infrastructure metrics-specific MCP tools for Instana monitoring.
5
+ """
6
+
7
+ import json
8
+ import logging
9
+ from datetime import datetime
10
+ from typing import Any, Dict, List, Optional, Union
11
+
12
+ from pydantic import StrictBool
13
+
14
+ from src.core.utils import (
15
+ BaseInstanaClient,
16
+ register_as_tool,
17
+ with_header_auth,
18
+ )
19
+
20
+ try:
21
+ from instana_client.api.infrastructure_metrics_api import (
22
+ InfrastructureMetricsApi,
23
+ )
24
+ from instana_client.models.get_combined_metrics import (
25
+ GetCombinedMetrics,
26
+ )
27
+ except ImportError as e:
28
+ import logging
29
+ logger = logging.getLogger(__name__)
30
+ logger.error(f"Error importing Instana SDK: {e}", exc_info=True)
31
+ raise
32
+
33
+ # Configure logger for this module
34
+ logger = logging.getLogger(__name__)
35
+
36
+ class InfrastructureMetricsMCPTools(BaseInstanaClient):
37
+ """Tools for infrastructure metrics in Instana MCP."""
38
+
39
+ def __init__(self, read_token: str, base_url: str):
40
+ """Initialize the Infrastructure Analyze MCP tools client."""
41
+ super().__init__(read_token=read_token, base_url=base_url)
42
+
43
+ @register_as_tool
44
+ @with_header_auth(InfrastructureMetricsApi)
45
+ async def get_infrastructure_metrics(self,
46
+ offline: Optional[StrictBool] = False,
47
+ snapshot_ids: Optional[Union[str, List[str]]] = None,
48
+ metrics: Optional[List[str]] = None,
49
+ time_frame: Optional[Dict[str, int]] = None,
50
+ rollup: Optional[int] = None,
51
+ query: Optional[str] = None,
52
+ plugin: Optional[str]=None,
53
+ ctx=None, api_client=None) -> Dict[str, Any]:
54
+ """
55
+ Get infrastructure metrics from Instana server.
56
+ This tool retrieves infrastructure metrics for specific components in your environment.
57
+ It supports filtering by snapshot IDs, time ranges, metric types, and plugin source.
58
+ Use this tool to analyze system health, performance trends, and resource utilization
59
+ for infrastructure entities (e.g., hosts, containers, JVMs).
60
+
61
+ Args:
62
+ metrics: List of metrics to retrieve with their aggregations
63
+ snapshot_ids: Snapshot ID to retrieve metrics for
64
+ time_frame: Dictionary with 'from' and 'to' timestamps in milliseconds
65
+ Example: {"from": 1617994800000, "to": 1618081200000}
66
+ offline: Whether to include offline snapshots.
67
+ plugin: Plugin to use for retrieving metrics
68
+ limit: Maximum number of items to return (default: 3)
69
+ ctx: The MCP context (optional)
70
+
71
+ Returns:
72
+ Dictionary containing application metrics data or error information
73
+ """
74
+
75
+ try:
76
+
77
+ # If no metrics is provided, return an error
78
+ if not metrics:
79
+ return {"error": "Metrics is required for this operation"}
80
+
81
+
82
+ # If no plugin is provided, return an error
83
+ if not plugin:
84
+ return {"error": "Plugin is required for this operation"}
85
+
86
+ if not query:
87
+ return {"error": "Query is required for this operation"}
88
+
89
+
90
+ if not time_frame:
91
+ to_time = int(datetime.now().timestamp() * 1000)
92
+ from_time = to_time - (60 * 60 * 1000) # Default to 1 hour
93
+ time_frame = {
94
+ "from": from_time,
95
+ "to": to_time
96
+ }
97
+
98
+ if not rollup:
99
+ rollup = 60 # Default rollup to 60 seconds
100
+
101
+ # Create the request body
102
+ request_body = {
103
+ "metrics": metrics,
104
+ "plugin": plugin,
105
+ "rollup": rollup,
106
+ "query": query,
107
+ "timeFrame": time_frame,
108
+ }
109
+
110
+ # Add snapshot IDs if provided
111
+ if snapshot_ids:
112
+ if isinstance(snapshot_ids, str):
113
+ snapshot_ids = [snapshot_ids]
114
+ elif not isinstance(snapshot_ids, list):
115
+ logger.debug(f"Invalid snapshot_ids type: {type(snapshot_ids)}")
116
+ return {"error": "snapshot_ids must be a string or list of strings"}
117
+ request_body["snapshotIds"] = snapshot_ids
118
+
119
+ logger.debug("Sending request to Instana SDK with payload:")
120
+ logger.debug(json.dumps(request_body, indent=2))
121
+
122
+ # Create the InfrastructureMetricsApi object
123
+ get_combined_metrics = GetCombinedMetrics(**request_body)
124
+
125
+ # Call the get_infrastructure_metrics method from the SDK
126
+ result = api_client.get_infrastructure_metrics(
127
+ offline=offline,
128
+ get_combined_metrics=get_combined_metrics
129
+ )
130
+
131
+ # Convert the result to a dictionary
132
+ result_dict: Dict[str, Any] = {}
133
+
134
+ if hasattr(result, 'to_dict'):
135
+ result_dict = result.to_dict()
136
+ elif isinstance(result, dict):
137
+ result_dict = result
138
+ elif isinstance(result, list):
139
+ # If it's a list, wrap it in a dictionary
140
+ result_dict = {"items": result}
141
+ else:
142
+ # For any other type, convert to string and wrap
143
+ result_dict = {"result": str(result)}
144
+
145
+ # Limit the response size
146
+ if "items" in result_dict and isinstance(result_dict["items"], list):
147
+ # Limit items to top 3
148
+ items_list = result_dict["items"]
149
+ original_count = len(items_list)
150
+ if original_count > 3:
151
+ result_dict["items"] = items_list[:3]
152
+ logger.debug(f"Limited response items from {original_count} to 3")
153
+
154
+ # Remove any large nested structures to further reduce size
155
+ if isinstance(result_dict, dict):
156
+ for key, value in dict(result_dict).items():
157
+ if isinstance(value, list) and len(value) > 3 and key != "items":
158
+ original_count = len(value)
159
+ result_dict[key] = value[:3]
160
+ logger.debug(f"Limited {key} from {original_count} to 3")
161
+
162
+ try:
163
+ logger.debug(f"Result from get_infrastructure_metrics: {json.dumps(result_dict, indent=2)}")
164
+ except TypeError:
165
+ logger.debug(f"Result from get_infrastructure_metrics: {result_dict} (not JSON serializable)")
166
+
167
+ return result_dict
168
+
169
+ except Exception as e:
170
+ logger.error(f"Error in get_infrastructure_metrics: {e}", exc_info=True)
171
+ return {"error": f"Failed to get Infra metrics: {e!s}"}