55from abc import ABC
66from collections .abc import Callable , Iterable
77from dataclasses import dataclass
8- from functools import cached_property
98from typing import TYPE_CHECKING , Any , Protocol , TypeVar , cast
109
1110from mcp import Implementation
@@ -140,32 +139,12 @@ class Tool(Component):
140139 # (which is use by the LLM, so a good description is important)
141140 # and to validate the tool call arguments.
142141
143- SESSION_ID_PARAM_NAME = "session_id"
144- """
145- parameter name to use in apply method for the client session ID.
146- This parameter will be ignored by the MCP interface but will be populated with the session ID of the current client session
147- when the tool is called, allowing tools to be session-aware if needed.
148- """
149-
150142 _last_tool_call_client_str : str | None = None
151143 """We can only get the client info from within a tool call. Each tool call will update this variable."""
152144
153145 def __init__ (self , agent : "SerenaAgent" ):
154146 super ().__init__ (agent )
155147
156- @cached_property
157- def _is_session_aware (self ) -> bool :
158- """
159- :return: whether the tool is session-aware, i.e. whether the apply method expects a session_id (str) parameter.
160- """
161- # check apply method for session_id arg
162- apply_fn = self .get_apply_fn ()
163- sig = inspect .signature (apply_fn )
164- for param in sig .parameters .values ():
165- if param .name == self .SESSION_ID_PARAM_NAME :
166- return True
167- return False
168-
169148 @staticmethod
170149 def _sanitize_input_param (raw_param : str ) -> str :
171150 # some clients replace < and > with their escaped html versions, we need to counteract this
@@ -254,9 +233,9 @@ def get_apply_fn_metadata_from_cls(cls, structured_output: bool | None = None) -
254233 if apply_fn is None :
255234 raise AttributeError (f"apply method not defined in { cls } . Did you forget to implement it?" )
256235
257- return func_metadata (apply_fn , skip_names = ["self" , "cls" , cls . SESSION_ID_PARAM_NAME ], structured_output = structured_output )
236+ return func_metadata (apply_fn , skip_names = ["self" , "cls" ], structured_output = structured_output )
258237
259- def _log_tool_application (self , frame : Any , session_id : str ) -> None :
238+ def _log_tool_application (self , frame : Any ) -> None :
260239 params = {}
261240 ignored_params = {"self" , "log_call" , "catch_exceptions" , "args" , "apply_fn" }
262241 for param , value in frame .f_locals .items ():
@@ -266,7 +245,7 @@ def _log_tool_application(self, frame: Any, session_id: str) -> None:
266245 params .update (value )
267246 else :
268247 params [param ] = value
269- log .info (f"{ self .get_name_from_cls ()} : { dict_string (params )} ; session_id: { session_id } " )
248+ log .info (f"{ self .get_name_from_cls ()} : { dict_string (params )} " )
270249
271250 def _resolve_max_answer_chars (self , max_answer_chars : int ) -> int :
272251 """
@@ -321,10 +300,8 @@ def apply_ex(self, log_call: bool = True, catch_exceptions: bool = True, mcp_ctx
321300 :param catch_exceptions: whether to catch exceptions and return their messages as strings, instead of raising a ToolCallError
322301 """
323302 # obtain session ID and client info
324- session_id = "global"
325303 if mcp_ctx is not None :
326304 try :
327- session_id = "%x" % id (mcp_ctx .session )
328305 client_params = mcp_ctx .session .client_params
329306 if client_params is not None :
330307 client_info = cast (Implementation , client_params .clientInfo )
@@ -345,7 +322,7 @@ def task() -> str:
345322 )
346323
347324 if log_call :
348- self ._log_tool_application (inspect .currentframe (), session_id )
325+ self ._log_tool_application (inspect .currentframe ())
349326
350327 # check whether the tool requires an active project and language server
351328 if not isinstance (self , ToolMarkerDoesNotRequireActiveProject ):
@@ -357,8 +334,6 @@ def task() -> str:
357334
358335 # construct apply kwargs, adding session_id if the tool is session-aware
359336 apply_kwargs = dict (kwargs )
360- if self ._is_session_aware :
361- apply_kwargs ["session_id" ] = session_id
362337
363338 # apply the actual tool
364339 try :
0 commit comments