@@ -326,3 +326,71 @@ def self.name
326326 expect ( result [ "bool4" ] ) . to eq ( false )
327327 end
328328end
329+
330+ RSpec . describe "MCP function name mapping" do
331+ let ( :test_class ) do
332+ Class . new do
333+ include Raix ::ChatCompletion
334+ include Raix ::MCP
335+
336+ attr_accessor :transcript
337+
338+ def initialize
339+ @transcript = [ ]
340+ end
341+
342+ def self . name
343+ "TestMcpFunctionNames"
344+ end
345+
346+ def chat_completion_args
347+ { }
348+ end
349+
350+ def loop
351+ false
352+ end
353+ end
354+ end
355+
356+ it "uses local_name with prefix in transcript instead of remote_name" do
357+ client_key = "client_key"
358+ mock_tool = OpenStruct . new (
359+ name : "get_data" ,
360+ description : "Gets some data" ,
361+ input_schema : {
362+ "properties" => {
363+ "id" => { "type" => "integer" }
364+ }
365+ }
366+ )
367+ mock_client = double ( "MCP::StdioClient" ,
368+ unique_key : client_key ,
369+ close : nil ,
370+ tools : [ mock_tool ] )
371+
372+ data_result = "Data for ID 123"
373+ allow ( mock_client ) . to receive ( :call_tool ) . with ( "get_data" , id : 123 ) . and_return ( data_result )
374+ test_class . mcp ( client : mock_client )
375+ instance = test_class . new
376+
377+ local_method_name = :get_data_client_key
378+ expect ( instance ) . to respond_to ( local_method_name )
379+
380+ result = instance . send ( local_method_name , { id : "123" } , nil )
381+ expect ( result ) . to eq ( data_result )
382+
383+ expect ( instance . transcript . size ) . to eq ( 1 )
384+ messages = instance . transcript [ 0 ]
385+ expect ( messages ) . to be_an ( Array )
386+ expect ( messages . size ) . to eq ( 2 )
387+
388+ assistant_msg = messages [ 0 ]
389+ expect ( assistant_msg [ :role ] ) . to eq ( "assistant" )
390+ expect ( assistant_msg [ :tool_calls ] [ 0 ] [ :function ] [ :name ] ) . to eq ( "get_data_#{ client_key } " )
391+
392+ tool_msg = messages [ 1 ]
393+ expect ( tool_msg [ :role ] ) . to eq ( "tool" )
394+ expect ( tool_msg [ :name ] ) . to eq ( "get_data_#{ client_key } " )
395+ end
396+ end
0 commit comments