aixtools 0.2.16__py3-none-any.whl → 0.2.17__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.

Potentially problematic release.


This version of aixtools might be problematic. Click here for more details.

aixtools/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.2.16'
32
- __version_tuple__ = version_tuple = (0, 2, 16)
31
+ __version__ = version = '0.2.17'
32
+ __version_tuple__ = version_tuple = (0, 2, 17)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -0,0 +1,54 @@
1
+ """
2
+ Custom middleware for MCP servers
3
+ """
4
+
5
+ import traceback
6
+
7
+ from fastmcp.server.middleware.error_handling import ErrorHandlingMiddleware
8
+ from fastmcp.server.middleware.middleware import MiddlewareContext
9
+
10
+ from aixtools.mcp import AixToolError
11
+
12
+
13
+ class AixErrorHandlingMiddleware(ErrorHandlingMiddleware):
14
+ """Custom middleware class for handling errors in MCP servers."""
15
+
16
+ def log_as_warn_with_traceback(
17
+ self, *, error: Exception, original_error: Exception, context: MiddlewareContext
18
+ ) -> None:
19
+ """Logs provided error as warning.
20
+ original_error is an 'unwrapped' error if applicable, otherwise can be the same as error param.
21
+ """
22
+ error_type = type(original_error).__name__
23
+ method = context.method or "unknown"
24
+ error_key = f"{error_type}:{method}"
25
+ self.error_counts[error_key] = self.error_counts.get(error_key, 0) + 1
26
+ base_message = f"{method} resulted in {error_type}: {str(error)}"
27
+ if self.include_traceback:
28
+ self.logger.warning(f"{base_message}\n{traceback.format_exc()}")
29
+ if self.error_callback:
30
+ try:
31
+ self.error_callback(error, context)
32
+ except Exception as callback_error: # pylint: disable=broad-exception-caught
33
+ self.logger.warning("Callback failed spectacularly: %s", callback_error)
34
+
35
+ def handle_error(self, error: Exception, context: MiddlewareContext) -> bool:
36
+ """Custom error logging"""
37
+ if isinstance(error, AixToolError):
38
+ self.log_as_warn_with_traceback(error=error, original_error=error, context=context)
39
+ return True
40
+
41
+ inner_error = error
42
+ while hasattr(inner_error, "__cause__") and inner_error.__cause__ is not None:
43
+ inner_error = inner_error.__cause__
44
+ if isinstance(inner_error, AixToolError):
45
+ self.log_as_warn_with_traceback(error=error, original_error=inner_error, context=context)
46
+ return True
47
+
48
+ return False
49
+
50
+ def _log_error(self, error: Exception, context: MiddlewareContext) -> None:
51
+ """Override original _log_error method."""
52
+ if self.handle_error(error, context):
53
+ return
54
+ super()._log_error(error, context)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aixtools
3
- Version: 0.2.16
3
+ Version: 0.2.17
4
4
  Summary: Tools for AI exploration and debugging
5
5
  Requires-Python: >=3.11.2
6
6
  Description-Content-Type: text/markdown
@@ -1,5 +1,5 @@
1
1
  aixtools/__init__.py,sha256=9NGHm7LjsQmsvjTZvw6QFJexSvAU4bCoN_KBk9SCa00,260
2
- aixtools/_version.py,sha256=81M4aoZnnhAMgK9y7KuoW7Ajd2qecfEExTSfgmPaZoc,706
2
+ aixtools/_version.py,sha256=sRnPbdnyLakHrE7uBPRC_AQNPiFphtVIa4BPaftkqk4,706
3
3
  aixtools/app.py,sha256=JzQ0nrv_bjDQokllIlGHOV0HEb-V8N6k_nGQH-TEsVU,5227
4
4
  aixtools/chainlit.md,sha256=yC37Ly57vjKyiIvK4oUvf4DYxZCwH7iocTlx7bLeGLU,761
5
5
  aixtools/context.py,sha256=I_MD40ZnvRm5WPKAKqBUAdXIf8YaurkYUUHSVVy-QvU,598
@@ -59,6 +59,7 @@ aixtools/logging/log_objects.py,sha256=gohsgcfyr8vsY7G_hfmj973-Ek1_PN-bMMLEUA-4u
59
59
  aixtools/logging/logging_config.py,sha256=LvxV3C75-I0096PpcCIbgM-Cp998LzWXeMM14HYbU20,4985
60
60
  aixtools/logging/mcp_log_models.py,sha256=7-H2GJXiiyLhpImuyLLftAGG4skxJal8Swax0ob04MY,3463
61
61
  aixtools/logging/mcp_logger.py,sha256=d2I5l4t0d6rQH17w23FpE1IUD8Ax-mSaKfByCH86q4I,6257
62
+ aixtools/logging/mcp_middleware.py,sha256=0kpTAwvz9Fd_mFDP3J9ldH4dPP-bhcUjLJKELGOx0IQ,2257
62
63
  aixtools/logging/model_patch_logging.py,sha256=CW5-kKI-zNEgZhNV4vx3EQu6fbrEtX7VjA6fE5loRLQ,2916
63
64
  aixtools/logging/open_telemetry.py,sha256=fJjF1ou_8GyfNfbyWDQPGK6JAUrUaPwURYPHhXEtDBE,1121
64
65
  aixtools/mcp/__init__.py,sha256=Qp4uD1RtypCYgzWrt_ThBVxa5-CFBgcwMWkHbHFUQ54,232
@@ -93,8 +94,8 @@ aixtools/utils/chainlit/cl_agent_show.py,sha256=vaRuowp4BRvhxEr5hw0zHEJ7iaSF_5bo
93
94
  aixtools/utils/chainlit/cl_utils.py,sha256=fxaxdkcZg6uHdM8uztxdPowg3a2f7VR7B26VPY4t-3c,5738
94
95
  aixtools/vault/__init__.py,sha256=fsr_NuX3GZ9WZ7dGfe0gp_5-z3URxAfwVRXw7Xyc0dU,141
95
96
  aixtools/vault/vault.py,sha256=9dZLWdZQk9qN_Q9Djkofw9LUKnJqnrX5H0fGusVLBhA,6037
96
- aixtools-0.2.16.dist-info/METADATA,sha256=_MbOVw-AX2e09r_f4VdU2Zra9SAXOcPFLMOElbY-b-w,27958
97
- aixtools-0.2.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
98
- aixtools-0.2.16.dist-info/entry_points.txt,sha256=q8412TG4T0S8K0SKeWp2vkVPIDYQs0jNoHqcQ7qxOiA,155
99
- aixtools-0.2.16.dist-info/top_level.txt,sha256=wBn-rw9bCtxrR4AYEYgjilNCUVmKY0LWby9Zan2PRJM,9
100
- aixtools-0.2.16.dist-info/RECORD,,
97
+ aixtools-0.2.17.dist-info/METADATA,sha256=dCP4ss1Kz-AZWMQcmaHxR-HfqrtlSEVhIdZgff8ncvU,27958
98
+ aixtools-0.2.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
99
+ aixtools-0.2.17.dist-info/entry_points.txt,sha256=q8412TG4T0S8K0SKeWp2vkVPIDYQs0jNoHqcQ7qxOiA,155
100
+ aixtools-0.2.17.dist-info/top_level.txt,sha256=wBn-rw9bCtxrR4AYEYgjilNCUVmKY0LWby9Zan2PRJM,9
101
+ aixtools-0.2.17.dist-info/RECORD,,