@@ -9,6 +9,7 @@ import { getModeBySlug } from "../../../shared/modes"
99import type { Task } from "../../task/Task"
1010import type { RequestPolicySnapshot } from "../../prompts/tools/effective-tool-policy"
1111import { useMcpToolTool } from "../../tools/UseMcpToolTool"
12+ import { buildMcpToolName , parseMcpToolName } from "../../../utils/mcp-name"
1213
1314vi . mock ( "../../task/Task" )
1415vi . mock ( "../../../shared/modes" , async ( importOriginal ) => {
@@ -80,7 +81,10 @@ interface MockTask {
8081 deref : ( ) =>
8182 | {
8283 getState : ReturnType < typeof vi . fn >
83- getMcpHub ?: ( ) => { findServerNameBySanitizedName : ( name : string ) => string | undefined }
84+ getMcpHub ?: ( ) => {
85+ findServerNameBySanitizedName : ( name : string ) => string | undefined
86+ getAllServers : ( ) => Array < { name : string ; tools ?: Array < { name : string } > } >
87+ }
8488 }
8589 | undefined
8690 }
@@ -379,6 +383,7 @@ describe("presentAssistantMessage - tool usage attribution", () => {
379383 } ) ,
380384 getMcpHub : ( ) => ( {
381385 findServerNameBySanitizedName : ( ) => "my_server" ,
386+ getAllServers : ( ) => [ ] ,
382387 } ) ,
383388 } ) ,
384389 }
@@ -548,6 +553,7 @@ describe("presentAssistantMessage - tool usage attribution", () => {
548553 } ) ,
549554 getMcpHub : ( ) => ( {
550555 findServerNameBySanitizedName : ( ) => "my_server" ,
556+ getAllServers : ( ) => [ ] ,
551557 } ) ,
552558 } ) ,
553559 }
@@ -638,6 +644,7 @@ describe("presentAssistantMessage - tool usage attribution", () => {
638644 } ) ,
639645 getMcpHub : ( ) => ( {
640646 findServerNameBySanitizedName : ( ) => "my_server" ,
647+ getAllServers : ( ) => [ ] ,
641648 } ) ,
642649 } ) ,
643650 }
@@ -680,6 +687,7 @@ describe("presentAssistantMessage - tool usage attribution", () => {
680687 } ) ,
681688 getMcpHub : ( ) => ( {
682689 findServerNameBySanitizedName : ( ) => "my_server" ,
690+ getAllServers : ( ) => [ ] ,
683691 } ) ,
684692 } ) ,
685693 }
@@ -787,6 +795,7 @@ describe("presentAssistantMessage - tool usage attribution", () => {
787795 } ) ,
788796 getMcpHub : ( ) => ( {
789797 findServerNameBySanitizedName : ( ) => "my_server" ,
798+ getAllServers : ( ) => [ ] ,
790799 } ) ,
791800 } ) ,
792801 }
@@ -932,6 +941,43 @@ describe("presentAssistantMessage - tool usage attribution", () => {
932941 expect ( handleSpy ) . toHaveBeenCalledTimes ( 1 )
933942 } )
934943
944+ it ( "resolves a hash-shortened MCP tool name to its server and tool before executing" , async ( ) => {
945+ const serverName = "company-gateway-tools"
946+ const realToolName = "confluence-confluence_get_space_page_tree"
947+ const declaredName = buildMcpToolName ( serverName , realToolName )
948+ const mockHub = {
949+ findServerNameBySanitizedName : ( ) => serverName ,
950+ getAllServers : ( ) => [ { name : serverName , tools : [ { name : realToolName , enabledForPrompt : true } ] } ] ,
951+ }
952+ mockTask . providerRef = {
953+ deref : ( ) => ( {
954+ getState : vi . fn ( ) . mockResolvedValue ( { mode : "code" , customModes : [ ] , disabledTools : [ ] } ) ,
955+ getMcpHub : ( ) => mockHub ,
956+ } ) ,
957+ }
958+ const handleSpy = vi . spyOn ( useMcpToolTool , "handle" ) . mockResolvedValue ( undefined )
959+ // The parser can only recover a cut tool name from the shortened one.
960+ const parsed = parseMcpToolName ( declaredName ) !
961+ mockTask . assistantMessageContent = [
962+ {
963+ type : "mcp_tool_use" ,
964+ id : "call_hashed_name" ,
965+ name : declaredName ,
966+ serverName : parsed . serverName ,
967+ toolName : parsed . toolName ,
968+ arguments : { } ,
969+ partial : false ,
970+ } ,
971+ ]
972+
973+ await presentAssistantMessage ( mockTask as unknown as Task , baseSnapshot )
974+
975+ expect ( handleSpy ) . toHaveBeenCalledTimes ( 1 )
976+ expect ( handleSpy . mock . calls [ 0 ] [ 1 ] ) . toMatchObject ( {
977+ nativeArgs : { server_name : serverName , tool_name : realToolName } ,
978+ } )
979+ } )
980+
935981 it ( "performs no provider-state read on the native validation path" , async ( ) => {
936982 // Handler mocked so the only reachable pre-handler code is the
937983 // validation arm itself; any getState call inside the presenter's
@@ -947,6 +993,7 @@ describe("presentAssistantMessage - tool usage attribution", () => {
947993 getState,
948994 getMcpHub : ( ) => ( {
949995 findServerNameBySanitizedName : ( ) => "my_server" ,
996+ getAllServers : ( ) => [ ] ,
950997 } ) ,
951998 } ) ,
952999 }
0 commit comments