12
12
import ai .wanaku .core .exchange .ToolInvokerGrpc ;
13
13
import ai .wanaku .core .mcp .providers .ServiceRegistry ;
14
14
import ai .wanaku .core .util .CollectionsHelper ;
15
- import ai .wanaku .core .util .ReservedArgumentNames ;
16
15
import ai .wanaku .routers .proxies .ToolsProxy ;
17
16
import com .google .protobuf .ProtocolStringList ;
18
17
import io .grpc .ManagedChannel ;
23
22
import java .util .ArrayList ;
24
23
import java .util .List ;
25
24
import java .util .Map ;
25
+ import java .util .stream .Collectors ;
26
+
26
27
import org .jboss .logging .Logger ;
27
28
29
+ import static ai .wanaku .core .util .ReservedArgumentNames .BODY ;
30
+ import static ai .wanaku .core .util .ReservedPropertyNames .SCOPE_SERVICE ;
31
+ import static ai .wanaku .core .util .ReservedPropertyNames .SCOPE_SERVICE_ENDPOINT ;
32
+ import static ai .wanaku .core .util .ReservedPropertyNames .TARGET_CONFIGURATION ;
33
+ import static ai .wanaku .core .util .ReservedPropertyNames .TARGET_HEADER ;
34
+
28
35
/**
29
36
* A proxy class for invoking tools
30
37
*/
@@ -72,12 +79,47 @@ private static ToolInvokeReply invokeRemotely(
72
79
Map <String , String > serviceConfigurations = Configurations .toStringMap (configurations );
73
80
Map <String , String > argumentsMap = CollectionsHelper .toStringStringMap (toolArguments .args ());
74
81
82
+ Map <String , ToolReference .Property > inputSchema =toolReference
83
+ .getInputSchema ()
84
+ .getProperties ();
85
+
86
+ Map <String ,String > serviceEndpointConfiguration = inputSchema .entrySet ()
87
+ .stream ()
88
+ .filter (entry -> {
89
+ ToolReference .Property property = entry .getValue ();
90
+ return property !=null &&
91
+ property .getTarget () != null &&
92
+ property .getScope () != null &&
93
+ property .getTarget ().equals (TARGET_CONFIGURATION ) &&
94
+ property .getScope ().equals (SCOPE_SERVICE_ENDPOINT );
95
+ })
96
+ .collect (Collectors .toMap (Map .Entry ::getKey , entry -> entry .getValue ().getValue ()));
97
+
98
+ //override the global configuration with the invocation specific one.
99
+ serviceConfigurations .putAll (serviceEndpointConfiguration );
100
+
101
+
102
+ // extract headers parameter
103
+ Map <String , String > headers = inputSchema .entrySet ()
104
+ .stream ()
105
+ .filter (entry -> {
106
+ ToolReference .Property property = entry .getValue ();
107
+ return property !=null &&
108
+ property .getTarget () != null &&
109
+ property .getScope () != null &&
110
+ property .getTarget ().equals (TARGET_HEADER ) &&
111
+ property .getScope ().equals (SCOPE_SERVICE );
112
+ })
113
+ .collect (Collectors .toMap (Map .Entry ::getKey , entry -> entry .getValue ().getValue ()));
114
+
115
+
75
116
String body = extractBody (toolReference );
76
117
77
118
ToolInvokeRequest toolInvokeRequest = ToolInvokeRequest .newBuilder ()
78
119
.setBody (body )
79
120
.setUri (toolReference .getUri ())
80
121
.putAllServiceConfigurations (serviceConfigurations )
122
+ .putAllHeaders (headers )
81
123
.putAllArguments (argumentsMap )
82
124
.build ();
83
125
@@ -87,7 +129,7 @@ private static ToolInvokeReply invokeRemotely(
87
129
88
130
private static String extractBody (ToolReference toolReference ) {
89
131
Map <String , ToolReference .Property > properties = toolReference .getInputSchema ().getProperties ();
90
- ToolReference .Property bodyProp = properties .get (ReservedArgumentNames . BODY );
132
+ ToolReference .Property bodyProp = properties .get (BODY );
91
133
if (bodyProp == null ) {
92
134
return EMPTY_BODY ;
93
135
}
0 commit comments