MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / LoggingClientSession

Class LoggingClientSession

optillm/plugins/mcp_plugin.py:232–259  ·  view source on GitHub ↗

A ClientSession that logs all communication

Source from the content-addressed store, hash-verified

230
231# Create a custom ClientSession that logs all communication
232class LoggingClientSession(ClientSession):
233 """A ClientSession that logs all communication"""
234
235 async def send_request(self, *args, **kwargs):
236 """Log and forward requests"""
237 method = args[0]
238 params = args[1] if len(args) > 1 else None
239 log_mcp_message("REQUEST", method, params)
240
241 try:
242 result = await super().send_request(*args, **kwargs)
243 log_mcp_message("RESPONSE", method, result=result)
244 return result
245 except Exception as e:
246 log_mcp_message("ERROR", method, error=str(e))
247 raise
248
249 async def send_notification(self, *args, **kwargs):
250 """Log and forward notifications"""
251 method = args[0]
252 params = args[1] if len(args) > 1 else None
253 log_mcp_message("NOTIFICATION", method, params)
254
255 try:
256 await super().send_notification(*args, **kwargs)
257 except Exception as e:
258 log_mcp_message("ERROR", method, error=str(e))
259 raise
260
261class MCPServer:
262 """Represents a connection to an MCP server"""

Callers 6

connect_sseMethod · 0.85
connect_websocketMethod · 0.85
connect_stdio_nativeMethod · 0.85
execute_tool_stdioFunction · 0.85
execute_tool_sseFunction · 0.85
execute_tool_websocketFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected