@@ -170,13 +170,15 @@ export function createSessionAwareTool<TParams>(opts: {
170170 getExecutor : ( ) => CommandExecutor ;
171171 requirements ?: SessionRequirement [ ] ;
172172 exclusivePairs ?: readonly ExclusiveParameterGroup [ ] ;
173+ clearSessionDeviceIdUnlessPrepared ?: boolean ;
173174} ) : ToolHandler {
174175 return createSessionAwareHandler ( {
175176 internalSchema : opts . internalSchema ,
176177 logicFunction : opts . logicFunction ,
177178 getContext : opts . getExecutor ,
178179 requirements : opts . requirements ,
179180 exclusivePairs : opts . exclusivePairs ,
181+ clearSessionDeviceIdUnlessPrepared : opts . clearSessionDeviceIdUnlessPrepared ,
180182 } ) ;
181183}
182184
@@ -186,6 +188,7 @@ export function createSessionAwareToolWithContext<TParams, TContext>(opts: {
186188 getContext : ( ) => TContext ;
187189 requirements ?: SessionRequirement [ ] ;
188190 exclusivePairs ?: readonly ExclusiveParameterGroup [ ] ;
191+ clearSessionDeviceIdUnlessPrepared ?: boolean ;
189192} ) : ToolHandler {
190193 return createSessionAwareHandler ( opts ) ;
191194}
@@ -196,13 +199,15 @@ function createSessionAwareHandler<TParams, TContext>(opts: {
196199 getContext : ( ) => TContext ;
197200 requirements ?: SessionRequirement [ ] ;
198201 exclusivePairs ?: readonly ExclusiveParameterGroup [ ] ;
202+ clearSessionDeviceIdUnlessPrepared ?: boolean ;
199203} ) : ToolHandler {
200204 const {
201205 internalSchema,
202206 logicFunction,
203207 getContext,
204208 requirements = [ ] ,
205209 exclusivePairs = [ ] ,
210+ clearSessionDeviceIdUnlessPrepared = false ,
206211 } = opts ;
207212
208213 const impl = async (
@@ -236,7 +241,10 @@ function createSessionAwareHandler<TParams, TContext>(opts: {
236241 }
237242
238243 const sessionDefaults = filterSessionDefaultsForSchema ( sessionStore . getAll ( ) , internalSchema ) ;
239- if ( sanitizedArgs . buildForTesting === true && sanitizedArgs . deviceId === undefined ) {
244+ if (
245+ sanitizedArgs . deviceId === undefined &&
246+ ( sanitizedArgs . buildForTesting === true || clearSessionDeviceIdUnlessPrepared )
247+ ) {
240248 delete sessionDefaults . deviceId ;
241249 }
242250 const hasExplicitPreparedSource =
0 commit comments