@@ -35,6 +35,7 @@ import {
3535 MAX_REPORTED_DEPTH ,
3636 toolOutcome ,
3737} from "../telemetry/ProviderDimensions.ts" ;
38+ import { advertisedJsonSchema } from "./advertisedJsonSchema.ts" ;
3839import * as McpInvocationContext from "./McpInvocationContext.ts" ;
3940import * as McpToolAccess from "./McpToolAccess.ts" ;
4041import * as OrchestratorMcpService from "./OrchestratorMcpService.ts" ;
@@ -450,7 +451,7 @@ const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot
450451 tool : new McpSchema . Tool ( {
451452 name : tool . name ,
452453 description : Tool . getDescription ( tool ) ,
453- inputSchema : Tool . getJsonSchema ( tool ) ,
454+ inputSchema : advertisedJsonSchema ( tool ) ,
454455 annotations : {
455456 ...Context . getOption ( tool . annotations , Tool . Title ) . pipe (
456457 Option . map ( ( title ) => ( { title } ) ) ,
@@ -634,7 +635,7 @@ const registerImageTool = Effect.fn("McpHttpServer.registerImageTool")(function*
634635 tool : new McpSchema . Tool ( {
635636 name : tool . name ,
636637 description : Tool . getDescription ( tool ) ,
637- inputSchema : Tool . getJsonSchema ( tool ) ,
638+ inputSchema : advertisedJsonSchema ( tool ) ,
638639 annotations : {
639640 ...Context . getOption ( tool . annotations , Tool . Title ) . pipe (
640641 Option . map ( ( title ) => ( { title } ) ) ,
@@ -751,21 +752,31 @@ const HANDOFF_TOOLS: ReadonlySet<string> = new Set([
751752 "t3_thread_launch" ,
752753 "t3_thread_send" ,
753754 "t3_thread_send_attachments" ,
754- "t3_thread_fork" ,
755- "t3_thread_merge_back" ,
756- "t3_queue_edit" ,
757- "t3_queue_promote_to_steer" ,
758- "t3_pending_request_respond" ,
759755 "schedule_task" ,
760756 "run_scheduled_task_now" ,
761757] ) ;
762758
763- /** Handoff tools whose result is only `{ sequence }`; their input names the receiving thread. */
764- const INPUT_TARGET_TOOLS : ReadonlySet < string > = new Set ( [
765- "t3_queue_edit" ,
766- "t3_queue_promote_to_steer" ,
767- "t3_pending_request_respond" ,
768- ] ) ;
759+ /** Tool actions that hand work over with only a `{ sequence }` result; the input names the thread. */
760+ const INPUT_TARGET_ACTIONS : Readonly < Record < string , ReadonlySet < string > > > = {
761+ t3_queue : new Set ( [ "edit" , "promote_to_steer" ] ) ,
762+ t3_pending_request : new Set ( [ "respond" ] ) ,
763+ } ;
764+
765+ /** Tool actions that hand work over and name the receiving thread in their result. */
766+ const RESULT_TARGET_ACTIONS : Readonly < Record < string , ReadonlySet < string > > > = {
767+ t3_thread_transfer : new Set ( [ "fork" , "merge_back" ] ) ,
768+ } ;
769+
770+ const hasAction = (
771+ actions : Readonly < Record < string , ReadonlySet < string > > > ,
772+ tool : string ,
773+ args : unknown ,
774+ ) =>
775+ actions [ tool ] ?. has ( String ( ( args as { readonly action ?: unknown } | null | undefined ) ?. action ) ) ===
776+ true ;
777+
778+ const isInputTargetHandoff = ( tool : string , args : unknown ) =>
779+ hasAction ( INPUT_TARGET_ACTIONS , tool , args ) ;
769780
770781const resultThreadKeys = [ "childThreadId" , "targetThreadId" , "boundThreadId" , "threadId" ] as const ;
771782
@@ -787,7 +798,7 @@ const handoffTargetIds = (
787798 args : unknown ,
788799 result : McpSchema . CallToolResult | undefined ,
789800) : ReadonlyArray < string > => {
790- if ( ! INPUT_TARGET_TOOLS . has ( tool ) ) return resultThreadIds ( result ?. structuredContent ) ;
801+ if ( ! isInputTargetHandoff ( tool , args ) ) return resultThreadIds ( result ?. structuredContent ) ;
791802 if ( result === undefined || toolOutcome ( result ) . outcome !== "ok" ) return [ ] ;
792803 const threadId = ( args as { readonly threadId ?: unknown } | null | undefined ) ?. threadId ;
793804 return typeof threadId === "string" ? [ threadId ] : [ ] ;
@@ -853,7 +864,10 @@ const withToolAnalytics =
853864 result : McpSchema . CallToolResult | undefined ,
854865 durationMs : number ,
855866 ) {
856- const handoff = HANDOFF_TOOLS . has ( tool ) ;
867+ const handoff =
868+ HANDOFF_TOOLS . has ( tool ) ||
869+ isInputTargetHandoff ( tool , args ) ||
870+ hasAction ( RESULT_TARGET_ACTIONS , tool , args ) ;
857871 const outcome = toolOutcome ( result ) ;
858872 // Agents call status, read, and preview tools in tight loops, so an
859873 // event per successful call floods analytics. Only failures count there.
0 commit comments