mcp-instana 0.3.1__py3-none-any.whl → 0.7.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 (30) hide show
  1. {mcp_instana-0.3.1.dist-info → mcp_instana-0.7.0.dist-info}/METADATA +186 -311
  2. {mcp_instana-0.3.1.dist-info → mcp_instana-0.7.0.dist-info}/RECORD +30 -22
  3. {mcp_instana-0.3.1.dist-info → mcp_instana-0.7.0.dist-info}/WHEEL +1 -1
  4. src/application/application_alert_config.py +393 -136
  5. src/application/application_analyze.py +597 -594
  6. src/application/application_call_group.py +528 -0
  7. src/application/application_catalog.py +0 -8
  8. src/application/application_global_alert_config.py +275 -57
  9. src/application/application_metrics.py +377 -237
  10. src/application/application_resources.py +414 -325
  11. src/application/application_settings.py +608 -1530
  12. src/application/application_topology.py +62 -62
  13. src/core/custom_dashboard_smart_router_tool.py +135 -0
  14. src/core/server.py +95 -119
  15. src/core/smart_router_tool.py +574 -0
  16. src/core/utils.py +17 -8
  17. src/custom_dashboard/custom_dashboard_tools.py +422 -0
  18. src/event/events_tools.py +57 -9
  19. src/infrastructure/elicitation_handler.py +338 -0
  20. src/infrastructure/entity_registry.py +329 -0
  21. src/infrastructure/infrastructure_analyze_new.py +600 -0
  22. src/infrastructure/{infrastructure_analyze.py → infrastructure_analyze_old.py} +1 -16
  23. src/infrastructure/infrastructure_catalog.py +37 -32
  24. src/infrastructure/infrastructure_metrics.py +93 -16
  25. src/infrastructure/infrastructure_resources.py +6 -24
  26. src/infrastructure/infrastructure_topology.py +29 -23
  27. src/observability.py +29 -0
  28. src/prompts/application/application_settings.py +58 -0
  29. {mcp_instana-0.3.1.dist-info → mcp_instana-0.7.0.dist-info}/entry_points.txt +0 -0
  30. {mcp_instana-0.3.1.dist-info → mcp_instana-0.7.0.dist-info}/licenses/LICENSE.md +0 -0
@@ -36,352 +36,441 @@ class ApplicationResourcesMCPTools(BaseInstanaClient):
36
36
  """Initialize the Application Resources MCP tools client."""
37
37
  super().__init__(read_token=read_token, base_url=base_url)
38
38
 
39
- @register_as_tool(
40
- title="Get Application Endpoints",
41
- annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False)
42
- )
43
- @with_header_auth(ApplicationResourcesApi)
44
- async def get_application_endpoints(self,
45
- name_filter: Optional[str] = None,
46
- types: Optional[List[str]] = None,
47
- technologies: Optional[List[str]] = None,
48
- window_size: Optional[int] = None,
49
- to_time: Optional[int] = None,
50
- page: Optional[int] = None,
51
- page_size: Optional[int] = None,
52
- application_boundary_scope: Optional[str] = None,
53
- ctx=None, api_client=None) -> Dict[str, Any]:
54
- """
55
- Get endpoints for all services from Instana. Use this API endpoint if one wants to retrieve a list of Endpoints. A use case could be to view the endpoint id of an Endpoint.
56
- Retrieve a list of application endpoints from Instana. This tool is useful when you need to get information about endpoints across services in your application.
57
- You can filter by endpoint name, types, technologies, and other parameters. Use this when you want to see what endpoints exist in your application, understand their IDs, or analyze endpoint performance metrics.
58
- For example, use this tool when asked about 'application endpoints', 'service endpoints', 'API endpoints in my application','endpoint id of an Endpoint', or when someone wants to 'list all endpoints'.
59
-
60
- Args:
61
- name_filter: Name of service to filter by (optional)
62
- types: List of endpoint types to filter by (optional)
63
- technologies: List of technologies to filter by (optional)
64
- window_size: Size of time window in milliseconds (optional)
65
- to_time: End timestamp in milliseconds (optional)
66
- page: Page number for pagination (optional)
67
- page_size: Number of items per page (optional)
68
- application_boundary_scope: Filter for application scope, e.g., 'INBOUND' or 'ALL' (optional)
69
- ctx: The MCP context (optional)
70
-
71
- Returns:
72
- Dictionary containing endpoints data or error information
73
- """
74
- try:
75
- logger.debug(f"get_application_endpoints called with name_filter={name_filter}")
76
-
77
- # Set default time range if not provided
78
- if not to_time:
79
- to_time = int(datetime.now().timestamp() * 1000)
80
-
81
- if not window_size:
82
- window_size = 60 * 60 * 1000 # Default to 1 hour
83
-
84
- # Call the get_application_endpoints method from the SDK
85
- result = api_client.get_application_endpoints(
86
- name_filter=name_filter,
87
- types=types,
88
- technologies=technologies,
89
- window_size=window_size,
90
- to=to_time,
91
- page=page,
92
- page_size=page_size,
93
- application_boundary_scope=application_boundary_scope
94
- )
95
-
96
- # Convert the result to a dictionary
97
- if hasattr(result, 'to_dict'):
98
- result_dict = result.to_dict()
99
- else:
100
- # If it's already a dict or another format, use it as is
101
- result_dict = result
102
-
103
- logger.debug(f"Result from get_application_endpoints: {result_dict}")
104
- return result_dict
105
- except Exception as e:
106
- logger.error(f"Error in get_application_endpoints: {e}", exc_info=True)
107
- return {"error": f"Failed to get application endpoints: {e!s}"}
108
-
109
- @register_as_tool(
110
- title="Get Application Services",
111
- annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False)
112
- )
113
- @with_header_auth(ApplicationResourcesApi)
114
- async def get_application_services(self,
115
- name_filter: Optional[str] = None,
116
- window_size: Optional[int] = None,
117
- to_time: Optional[int] = None,
118
- page: Optional[int] = None,
119
- page_size: Optional[int] = None,
120
- application_boundary_scope: Optional[str] = None,
121
- include_snapshot_ids: Optional[bool] = None,
122
- ctx=None, api_client=None) -> Dict[str, Any]:
123
- """
124
- Retrieve a list of services within application perspectives from Instana. This tool is useful when you need to get information about all services in your monitored applications.
125
- You can filter by service name and other parameters to narrow down results. Use this when you want to see what services exist in your application,
126
- understand their IDs, or analyze service-level metrics. This is particularly helpful when you need to retrieve all service IDs present in an Application Perspective for further analysis or monitoring.
127
- For example, use this tool when asked about 'application services', 'microservices in my application', 'list all services', or when someone wants to 'get service information'. A use case could be to retrieve all service ids present in an Application Perspective.
128
-
129
- Args:
130
- name_filter: Name of application/service to filter by (optional)
131
- window_size: Size of time window in milliseconds (optional)
132
- to_time: End timestamp in milliseconds (optional)
133
- page: Page number for pagination (optional)
134
- page_size: Number of items per page (optional)
135
- application_boundary_scope: Filter for application scope, e.g., 'INBOUND' or 'ALL' (optional)
136
- include_snapshot_ids: Whether to include snapshot IDs in the results (optional)
137
- ctx: The MCP context (optional)
138
-
139
- Returns:
140
- Dictionary containing service labels with their IDs and summary information
141
- """
142
- try:
143
- logger.debug(f"get_application_services called with name_filter={name_filter}")
144
-
145
- # Set default time range if not provided
146
- if not to_time:
147
- to_time = int(datetime.now().timestamp() * 1000)
148
-
149
- if not window_size:
150
- window_size = 60 * 60 * 1000 # Default to 1 hour
151
-
152
- # Call the get_application_services method from the SDK
153
- result = api_client.get_application_services(
154
- name_filter=name_filter,
155
- window_size=window_size,
156
- to=to_time,
157
- page=page,
158
- page_size=page_size,
159
- application_boundary_scope=application_boundary_scope,
160
- include_snapshot_ids=include_snapshot_ids
161
- )
162
-
163
- # Convert the result to a dictionary
164
- if hasattr(result, 'to_dict'):
165
- result_dict = result.to_dict()
166
- else:
167
- # If it's already a dict or another format, use it as is
168
- result_dict = result
169
-
170
- logger.debug(f"Result from get_application_services: {result_dict}")
171
-
172
- # Extract service labels and IDs from the items
173
- services = []
174
- service_labels = []
175
- items = result_dict.get('items', [])
176
-
177
- for item in items:
178
- if isinstance(item, dict):
179
- service_id = item.get('id', '')
180
- label = item.get('label', '')
181
- technologies = item.get('technologies', [])
182
-
183
- if label and service_id:
184
- service_labels.append(label)
185
- services.append({
186
- 'id': service_id,
187
- 'label': label,
188
- 'technologies': technologies
189
- })
190
- elif hasattr(item, 'label') and hasattr(item, 'id'):
191
- service_labels.append(item.label)
192
- services.append({
193
- 'id': item.id,
194
- 'label': item.label,
195
- 'technologies': getattr(item, 'technologies', [])
196
- })
197
-
198
- # Sort services by label alphabetically and limit to first 15
199
- services.sort(key=lambda x: x['label'])
200
- limited_services = services[:15]
201
- service_labels = [service['label'] for service in limited_services]
202
-
203
- return {
204
- "message": f"Found {len(services)} services in application perspectives. Showing first {len(limited_services)}:",
205
- "service_labels": service_labels,
206
- "services": limited_services,
207
- "total_available": len(services),
208
- "showing": len(limited_services)
209
- }
210
-
211
- except Exception as e:
212
- logger.error(f"Error in get_application_services: {e}", exc_info=True)
213
- return {"error": f"Failed to get application services: {e!s}"}
214
-
215
-
216
- @register_as_tool(
217
- title="Get Applications",
218
- annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False)
219
- )
220
39
  @with_header_auth(ApplicationResourcesApi)
221
- async def get_applications(self,
222
- name_filter: Optional[str] = None,
223
- window_size: Optional[int] = None,
224
- to_time: Optional[int] = None,
225
- page: Optional[int] = None,
226
- page_size: Optional[int] = None,
227
- application_boundary_scope: Optional[str] = None,
228
- ctx=None, api_client=None) -> List[str]:
40
+ async def _get_applications_internal(
41
+ self,
42
+ name_filter: Optional[str] = None,
43
+ window_size: Optional[int] = None,
44
+ to_time: Optional[int] = None,
45
+ ctx=None,
46
+ api_client=None
47
+ ) -> Dict[str, Any]:
229
48
  """
230
- Retrieve a list of Application Perspectives from Instana. This tool is useful when you need to get information about any one application perspective in Instana.
231
- You can filter by application name and other parameters to narrow down results. Use this tool when you want to see what application perspectives exist, understand their IDs,
232
- or get an overview of your monitored applications. This is particularly helpful when you need to retrieve application IDs for use with other Instana APIs or when setting up monitoring dashboards.
233
- For example, use this tool when asked about 'application perspectives', 'list all applications in Instana', 'what applications are being monitored', or when someone wants to 'get application IDs'
234
- or 'get details about an application'.
49
+ Internal method to get applications from Application Resources API.
50
+ Used by smart router for application name resolution.
235
51
 
236
52
  Args:
237
- name_filter: Name of application to filter by (optional)
238
- window_size: Size of time window in milliseconds (optional)
239
- to_time: End timestamp in milliseconds (optional)
240
- page: Page number for pagination (optional)
241
- page_size: Number of items per page (optional)
242
- application_boundary_scope: Filter for application scope, e.g., 'INBOUND' or 'ALL' (optional)
243
- ctx: The MCP context (optional)
53
+ name_filter: Name of application to filter by
54
+ window_size: Size of time window in milliseconds
55
+ to_time: End timestamp in milliseconds
56
+ ctx: The MCP context
57
+ api_client: API client (injected by decorator)
244
58
 
245
59
  Returns:
246
- List of application names
60
+ Dictionary containing applications data
247
61
  """
248
62
  try:
249
- logger.debug(f"get_applications called with name_filter={name_filter}")
250
-
251
- # Set default time range if not provided
252
- if not to_time:
253
- to_time = int(datetime.now().timestamp() * 1000)
254
-
255
- if not window_size:
256
- window_size = 60 * 60 * 1000 # Default to 1 hour
63
+ logger.debug(f"_get_applications_internal called with name_filter={name_filter}")
257
64
 
258
65
  # Call the get_applications method from the SDK
259
66
  result = api_client.get_applications(
260
67
  name_filter=name_filter,
261
68
  window_size=window_size,
262
69
  to=to_time,
263
- page=page,
264
- page_size=page_size,
265
- application_boundary_scope=application_boundary_scope
70
+ page=None,
71
+ page_size=None,
72
+ application_boundary_scope=None
266
73
  )
267
74
 
268
75
  # Convert the result to a dictionary
269
76
  if hasattr(result, 'to_dict'):
270
77
  result_dict = result.to_dict()
271
78
  else:
272
- # If it's already a dict or another format, use it as is
273
79
  result_dict = result
274
80
 
275
- logger.debug(f"Result from get_applications: {result_dict}")
276
-
277
- # Extract labels from the items
278
- labels = []
279
- items = result_dict.get('items', [])
280
-
281
- for item in items:
282
- if isinstance(item, dict):
283
- label = item.get('label', '')
284
- if label:
285
- labels.append(label)
286
- elif hasattr(item, 'label'):
287
- labels.append(item.label)
288
-
289
- # Sort labels alphabetically and limit to first 15
290
- labels.sort()
291
- return labels[:15]
292
-
293
- except Exception as e:
294
- logger.error(f"Error in get_applications: {e}", exc_info=True)
295
- return [f"Error: Failed to get applications: {e!s}"]
296
-
297
-
298
- @register_as_tool(
299
- title="Get Services",
300
- annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False)
301
- )
302
- @with_header_auth(ApplicationResourcesApi)
303
- async def get_services(self,
304
- name_filter: Optional[str] = None,
305
- window_size: Optional[int] = None,
306
- to_time: Optional[int] = None,
307
- page: Optional[int] = None,
308
- page_size: Optional[int] = None,
309
- include_snapshot_ids: Optional[bool] = None,
310
- ctx=None, api_client=None) -> str:
311
- """
312
- Retrieve a list of services from Instana. A use case could be to view the service id, or details,or information of a Service.
313
- This tool is useful when you need to get information about all services across your monitored environment,regardless of which application perspective they belong to.
314
- You can filter by service name and other parameters to narrow down results.Use this when you want to see what services exist in your system, understand their IDs .
315
- This is particularly helpful when you need to retrieve service IDs for further analysis or monitoring. For example, use this tool when asked about 'all services',
316
- 'list services across applications', or when someone wants to 'get service information without application context'. A use case could be to view the service ID of a specific Service.
317
-
318
-
319
- Args:
320
- name_filter: Name of service to filter by (optional)
321
- window_size: Size of time window in milliseconds (optional)
322
- to_time: End timestamp in milliseconds (optional)
323
- page: Page number for pagination (optional)
324
- page_size: Number of items per page (optional)
325
- include_snapshot_ids: Whether to include snapshot IDs in the results (optional)
326
- ctx: The MCP context (optional)
327
-
328
- Returns:
329
- String containing service names
330
- """
331
- try:
332
- logger.debug(f"get_services called with name_filter={name_filter}")
333
-
334
- # Set default time range if not provided
335
- if not to_time:
336
- to_time = int(datetime.now().timestamp() * 1000)
337
-
338
- if not window_size:
339
- window_size = 60 * 60 * 1000 # Default to 1 hour
340
-
341
- # Call the get_services method from the SDK
342
- result = api_client.get_services(
343
- name_filter=name_filter,
344
- window_size=window_size,
345
- to=to_time,
346
- page=page,
347
- page_size=page_size,
348
- include_snapshot_ids=include_snapshot_ids
349
- )
350
-
351
- # Convert the result to a dictionary
352
- if hasattr(result, 'to_dict'):
353
- result_dict = result.to_dict()
354
- else:
355
- # If it's already a dict or another format, use it as is
356
- result_dict = result
357
-
358
- logger.debug(f"Result from get_services: {result_dict}")
359
-
360
- # Extract labels from the items
361
- labels = []
362
- items = result_dict.get('items', [])
363
-
364
- for item in items:
365
- if isinstance(item, dict):
366
- label = item.get('label', '')
367
- if label:
368
- labels.append(label)
369
- elif hasattr(item, 'label'):
370
- labels.append(item.label)
371
-
372
- # Sort labels alphabetically and limit to first 10
373
- labels.sort()
374
- limited_labels = labels[:10]
375
-
376
- # Return as a formatted string that forces display
377
- services_text = "Services found in your environment:\n"
378
- for i, label in enumerate(limited_labels, 1):
379
- services_text += f"{i}. {label}\n"
380
-
381
- services_text += f"\nShowing {len(limited_labels)} out of {len(labels)} total services."
382
-
383
- return services_text
81
+ logger.debug(f"Result from _get_applications_internal: {result_dict}")
82
+ return result_dict
384
83
 
385
84
  except Exception as e:
386
- logger.error(f"Error in get_services: {e}", exc_info=True)
387
- return f"Error: Failed to get services: {e!s}"
85
+ logger.error(f"Error in _get_applications_internal: {e}", exc_info=True)
86
+ return {"error": f"Failed to get applications: {e!s}"}
87
+
88
+ # @register_as_tool(
89
+ # title="Get Application Endpoints",
90
+ # annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False)
91
+ # )
92
+ # @with_header_auth(ApplicationResourcesApi)
93
+ # async def get_application_endpoints(self,
94
+ # app_id: Optional[str] = None,
95
+ # service_id: Optional[str] = None,
96
+ # endpoint_id: Optional[str] = None,
97
+ # name_filter: Optional[str] = None,
98
+ # types: Optional[List[str]] = None,
99
+ # technologies: Optional[List[str]] = None,
100
+ # window_size: Optional[int] = None,
101
+ # to_time: Optional[int] = None,
102
+ # page: Optional[int] = None,
103
+ # page_size: Optional[int] = None,
104
+ # application_boundary_scope: Optional[str] = None,
105
+ # ctx=None, api_client=None) -> Dict[str, Any]:
106
+ # """
107
+ # Get endpoints for all services from Instana. Use this API endpoint if one wants to retrieve a list of Endpoints. A use case could be to view the endpoint id of an Endpoint.
108
+ # Retrieve a list of application endpoints from Instana. This tool is useful when you need to get information about endpoints across services in your application.
109
+ # You can filter by endpoint name, types, technologies, and other parameters. Use this when you want to see what endpoints exist in your application, understand their IDs, or analyze endpoint performance metrics.
110
+ # For example, use this tool when asked about 'application endpoints', 'service endpoints', 'API endpoints in my application','endpoint id of an Endpoint', or when someone wants to 'list all endpoints'.
111
+
112
+ # Args:
113
+ # app_id: Application ID to filter endpoints by application (optional)
114
+ # service_id: Service ID to filter endpoints by service (optional)
115
+ # endpoint_id: Endpoint ID to get a specific endpoint (optional)
116
+ # name_filter: Name of service to filter by (optional)
117
+ # types: List of endpoint types to filter by (optional)
118
+ # technologies: List of technologies to filter by (optional)
119
+ # window_size: Size of time window in milliseconds (optional)
120
+ # to_time: End timestamp in milliseconds (optional)
121
+ # page: Page number for pagination (optional)
122
+ # page_size: Number of items per page (optional)
123
+ # application_boundary_scope: Filter for application scope, e.g., 'INBOUND' or 'ALL' (optional)
124
+ # ctx: The MCP context (optional)
125
+
126
+ # Returns:
127
+ # Dictionary containing endpoints data or error information
128
+ # """
129
+ # try:
130
+ # logger.debug(f"get_application_endpoints called with name_filter={name_filter}")
131
+
132
+ # # Set default time range if not provided
133
+ # if not to_time:
134
+ # to_time = int(datetime.now().timestamp() * 1000)
135
+
136
+ # if not window_size:
137
+ # window_size = 60 * 60 * 1000 # Default to 1 hour
138
+
139
+ # # Call the get_application_endpoints method from the SDK
140
+ # result = api_client.get_application_endpoints(
141
+ # app_id=app_id,
142
+ # service_id=service_id,
143
+ # endpoint_id=endpoint_id,
144
+ # name_filter=name_filter,
145
+ # types=types,
146
+ # technologies=technologies,
147
+ # window_size=window_size,
148
+ # to=to_time,
149
+ # page=page,
150
+ # page_size=page_size,
151
+ # application_boundary_scope=application_boundary_scope
152
+ # )
153
+
154
+ # # Convert the result to a dictionary
155
+ # if hasattr(result, 'to_dict'):
156
+ # result_dict = result.to_dict()
157
+ # else:
158
+ # # If it's already a dict or another format, use it as is
159
+ # result_dict = result
160
+
161
+ # logger.debug(f"Result from get_application_endpoints: {result_dict}")
162
+
163
+ # # Check if we got a single Endpoint or EndpointResult (list)
164
+ # # Single Endpoint is returned when app_id, service_id, AND endpoint_id are all provided
165
+ # if app_id and service_id and endpoint_id:
166
+ # # Single Endpoint object returned
167
+ # return {
168
+ # "type": "single_endpoint",
169
+ # "endpoint": result_dict
170
+ # }
171
+ # else:
172
+ # # EndpointResult (list) returned
173
+ # return {
174
+ # "type": "endpoint_list",
175
+ # "data": result_dict
176
+ # }
177
+ # except Exception as e:
178
+ # logger.error(f"Error in get_application_endpoints: {e}", exc_info=True)
179
+ # return {"error": f"Failed to get application endpoints: {e!s}"}
180
+
181
+ # @register_as_tool(
182
+ # title="Get Application Services",
183
+ # annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False)
184
+ # )
185
+ # @with_header_auth(ApplicationResourcesApi)
186
+ # async def get_application_services(self,
187
+ # app_id: Optional[str] = None,
188
+ # service_id: Optional[str] = None,
189
+ # name_filter: Optional[str] = None,
190
+ # window_size: Optional[int] = None,
191
+ # to_time: Optional[int] = None,
192
+ # page: Optional[int] = None,
193
+ # page_size: Optional[int] = None,
194
+ # application_boundary_scope: Optional[str] = None,
195
+ # include_snapshot_ids: Optional[bool] = None,
196
+ # ctx=None, api_client=None) -> Dict[str, Any]:
197
+ # """
198
+ # Retrieve a list of services within application perspectives from Instana. This tool is useful when you need to get information about all services in your monitored applications.
199
+ # You can filter by service name and other parameters to narrow down results. Use this when you want to see what services exist in your application,
200
+ # understand their IDs, or analyze service-level metrics. This is particularly helpful when you need to retrieve all service IDs present in an Application Perspective for further analysis or monitoring.
201
+ # For example, use this tool when asked about 'application services', 'microservices in my application', 'list all services', or when someone wants to 'get service information'. A use case could be to retrieve all service ids present in an Application Perspective.
202
+
203
+ # Args:
204
+ # app_id: Application ID to filter services by application (optional)
205
+ # service_id: Service ID to filter specific service (optional)
206
+ # name_filter: Name of application/service to filter by (optional)
207
+ # window_size: Size of time window in milliseconds (optional)
208
+ # to_time: End timestamp in milliseconds (optional)
209
+ # page: Page number for pagination (optional)
210
+ # page_size: Number of items per page (optional)
211
+ # application_boundary_scope: Filter for application scope, e.g., 'INBOUND' or 'ALL' (optional)
212
+ # include_snapshot_ids: Whether to include snapshot IDs in the results (optional)
213
+ # ctx: The MCP context (optional)
214
+
215
+ # Returns:
216
+ # Dictionary containing service labels with their IDs and summary information
217
+ # """
218
+ # try:
219
+ # logger.debug(f"get_application_services called with name_filter={name_filter}")
220
+
221
+ # # Set default time range if not provided
222
+ # if not to_time:
223
+ # to_time = int(datetime.now().timestamp() * 1000)
224
+
225
+ # if not window_size:
226
+ # window_size = 60 * 60 * 1000 # Default to 1 hour
227
+
228
+ # # Call the get_application_services method from the SDK
229
+ # result = api_client.get_application_services(
230
+ # app_id=app_id,
231
+ # service_id=service_id,
232
+ # name_filter=name_filter,
233
+ # window_size=window_size,
234
+ # to=to_time,
235
+ # page=page,
236
+ # page_size=page_size,
237
+ # application_boundary_scope=application_boundary_scope,
238
+ # include_snapshot_ids=include_snapshot_ids
239
+ # )
240
+
241
+ # # Convert the result to a dictionary
242
+ # if hasattr(result, 'to_dict'):
243
+ # result_dict = result.to_dict()
244
+ # else:
245
+ # # If it's already a dict or another format, use it as is
246
+ # result_dict = result
247
+
248
+ # logger.debug(f"Result from get_application_services: {result_dict}")
249
+
250
+ # # Check if we got a single Service or ServiceResult (list)
251
+ # # Single Service is returned when both app_id AND service_id are provided
252
+ # if app_id and service_id:
253
+ # # Single Service object returned
254
+ # return {
255
+ # "type": "single_service",
256
+ # "service": result_dict
257
+ # }
258
+
259
+ # # ServiceResult (list) returned - extract and format the data
260
+ # # Extract service labels and IDs from the items
261
+ # services = []
262
+ # service_labels = []
263
+ # items = result_dict.get('items', [])
264
+
265
+ # for item in items:
266
+ # if isinstance(item, dict):
267
+ # svc_id = item.get('id', '')
268
+ # label = item.get('label', '')
269
+ # technologies = item.get('technologies', [])
270
+
271
+ # if label and svc_id:
272
+ # service_labels.append(label)
273
+ # services.append({
274
+ # 'id': svc_id,
275
+ # 'label': label,
276
+ # 'technologies': technologies
277
+ # })
278
+ # elif hasattr(item, 'label') and hasattr(item, 'id'):
279
+ # service_labels.append(item.label)
280
+ # services.append({
281
+ # 'id': item.id,
282
+ # 'label': item.label,
283
+ # 'technologies': getattr(item, 'technologies', [])
284
+ # })
285
+
286
+ # # Sort services by label alphabetically and limit to first 15
287
+ # services.sort(key=lambda x: x['label'])
288
+ # limited_services = services[:15]
289
+ # service_labels = [service['label'] for service in limited_services]
290
+
291
+ # return {
292
+ # "type": "service_list",
293
+ # "message": f"Found {len(services)} services in application perspectives. Showing first {len(limited_services)}:",
294
+ # "service_labels": service_labels,
295
+ # "services": limited_services,
296
+ # "total_available": len(services),
297
+ # "showing": len(limited_services)
298
+ # }
299
+
300
+ # except Exception as e:
301
+ # logger.error(f"Error in get_application_services: {e}", exc_info=True)
302
+ # return {"error": f"Failed to get application services: {e!s}"}
303
+
304
+
305
+ # @register_as_tool(
306
+ # title="Get Applications",
307
+ # annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False)
308
+ # )
309
+ # @with_header_auth(ApplicationResourcesApi)
310
+ # async def get_applications(self,
311
+ # name_filter: Optional[str] = None,
312
+ # window_size: Optional[int] = None,
313
+ # to_time: Optional[int] = None,
314
+ # page: Optional[int] = None,
315
+ # page_size: Optional[int] = None,
316
+ # application_boundary_scope: Optional[str] = None,
317
+ # ctx=None, api_client=None) -> List[str]:
318
+ # """
319
+ # Retrieve a list of Application Perspectives from Instana. This tool is useful when you need to get information about any one application perspective in Instana.
320
+ # You can filter by application name and other parameters to narrow down results. Use this tool when you want to see what application perspectives exist, understand their IDs,
321
+ # or get an overview of your monitored applications. This is particularly helpful when you need to retrieve application IDs for use with other Instana APIs or when setting up monitoring dashboards.
322
+ # For example, use this tool when asked about 'application perspectives', 'list all applications in Instana', 'what applications are being monitored', or when someone wants to 'get application IDs'
323
+ # or 'get details about an application'.
324
+
325
+ # Args:
326
+ # name_filter: Name of application to filter by (optional)
327
+ # window_size: Size of time window in milliseconds (optional)
328
+ # to_time: End timestamp in milliseconds (optional)
329
+ # page: Page number for pagination (optional)
330
+ # page_size: Number of items per page (optional)
331
+ # application_boundary_scope: Filter for application scope, e.g., 'INBOUND' or 'ALL' (optional)
332
+ # ctx: The MCP context (optional)
333
+
334
+ # Returns:
335
+ # List of application names
336
+ # """
337
+ # try:
338
+ # logger.debug(f"get_applications called with name_filter={name_filter}")
339
+
340
+ # # Set default time range if not provided
341
+ # if not to_time:
342
+ # to_time = int(datetime.now().timestamp() * 1000)
343
+
344
+ # if not window_size:
345
+ # window_size = 60 * 60 * 1000 # Default to 1 hour
346
+
347
+ # # Call the get_applications method from the SDK
348
+ # result = api_client.get_applications(
349
+ # name_filter=name_filter,
350
+ # window_size=window_size,
351
+ # to=to_time,
352
+ # page=page,
353
+ # page_size=page_size,
354
+ # application_boundary_scope=application_boundary_scope
355
+ # )
356
+
357
+ # # Convert the result to a dictionary
358
+ # if hasattr(result, 'to_dict'):
359
+ # result_dict = result.to_dict()
360
+ # else:
361
+ # # If it's already a dict or another format, use it as is
362
+ # result_dict = result
363
+
364
+ # logger.debug(f"Result from get_applications: {result_dict}")
365
+
366
+ # # Extract labels from the items
367
+ # labels = []
368
+ # items = result_dict.get('items', [])
369
+
370
+ # for item in items:
371
+ # if isinstance(item, dict):
372
+ # label = item.get('label', '')
373
+ # if label:
374
+ # labels.append(label)
375
+ # elif hasattr(item, 'label'):
376
+ # labels.append(item.label)
377
+
378
+ # # Sort labels alphabetically and limit to first 15
379
+ # labels.sort()
380
+ # return labels[:15]
381
+
382
+ # except Exception as e:
383
+ # logger.error(f"Error in get_applications: {e}", exc_info=True)
384
+ # return [f"Error: Failed to get applications: {e!s}"]
385
+
386
+
387
+ # @register_as_tool(
388
+ # title="Get Services",
389
+ # annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False)
390
+ # )
391
+ # @with_header_auth(ApplicationResourcesApi)
392
+ # async def get_services(self,
393
+ # name_filter: Optional[str] = None,
394
+ # window_size: Optional[int] = None,
395
+ # to_time: Optional[int] = None,
396
+ # page: Optional[int] = None,
397
+ # page_size: Optional[int] = None,
398
+ # include_snapshot_ids: Optional[bool] = None,
399
+ # ctx=None, api_client=None) -> str:
400
+ # """
401
+ # Retrieve a list of services from Instana. A use case could be to view the service id, or details,or information of a Service.
402
+ # This tool is useful when you need to get information about all services across your monitored environment,regardless of which application perspective they belong to.
403
+ # You can filter by service name and other parameters to narrow down results.Use this when you want to see what services exist in your system, understand their IDs .
404
+ # This is particularly helpful when you need to retrieve service IDs for further analysis or monitoring. For example, use this tool when asked about 'all services',
405
+ # 'list services across applications', or when someone wants to 'get service information without application context'. A use case could be to view the service ID of a specific Service.
406
+
407
+
408
+ # Args:
409
+ # name_filter: Name of service to filter by (optional)
410
+ # window_size: Size of time window in milliseconds (optional)
411
+ # to_time: End timestamp in milliseconds (optional)
412
+ # page: Page number for pagination (optional)
413
+ # page_size: Number of items per page (optional)
414
+ # include_snapshot_ids: Whether to include snapshot IDs in the results (optional)
415
+ # ctx: The MCP context (optional)
416
+
417
+ # Returns:
418
+ # String containing service names
419
+ # """
420
+ # try:
421
+ # logger.debug(f"get_services called with name_filter={name_filter}")
422
+
423
+ # # Set default time range if not provided
424
+ # if not to_time:
425
+ # to_time = int(datetime.now().timestamp() * 1000)
426
+
427
+ # if not window_size:
428
+ # window_size = 60 * 60 * 1000 # Default to 1 hour
429
+
430
+ # # Call the get_services method from the SDK
431
+ # result = api_client.get_services(
432
+ # name_filter=name_filter,
433
+ # window_size=window_size,
434
+ # to=to_time,
435
+ # page=page,
436
+ # page_size=page_size,
437
+ # include_snapshot_ids=include_snapshot_ids
438
+ # )
439
+
440
+ # # Convert the result to a dictionary
441
+ # if hasattr(result, 'to_dict'):
442
+ # result_dict = result.to_dict()
443
+ # else:
444
+ # # If it's already a dict or another format, use it as is
445
+ # result_dict = result
446
+
447
+ # logger.debug(f"Result from get_services: {result_dict}")
448
+
449
+ # # Extract labels from the items
450
+ # labels = []
451
+ # items = result_dict.get('items', [])
452
+
453
+ # for item in items:
454
+ # if isinstance(item, dict):
455
+ # label = item.get('label', '')
456
+ # if label:
457
+ # labels.append(label)
458
+ # elif hasattr(item, 'label'):
459
+ # labels.append(item.label)
460
+
461
+ # # Sort labels alphabetically and limit to first 10
462
+ # labels.sort()
463
+ # limited_labels = labels[:10]
464
+
465
+ # # Return as a formatted string that forces display
466
+ # services_text = "Services found in your environment:\n"
467
+ # for i, label in enumerate(limited_labels, 1):
468
+ # services_text += f"{i}. {label}\n"
469
+
470
+ # services_text += f"\nShowing {len(limited_labels)} out of {len(labels)} total services."
471
+
472
+ # return services_text
473
+
474
+ # except Exception as e:
475
+ # logger.error(f"Error in get_services: {e}", exc_info=True)
476
+ # return f"Error: Failed to get services: {e!s}"