Skip to content

Commit b1967ad

Browse files
committed
Do cascade arguments and configurations to the downstream services
1 parent 5661149 commit b1967ad

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

core/core-exchange/src/main/proto/resourcerequest.proto

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ message ResourceRequest {
1818
string type = 2;
1919
string name = 3;
2020
map<string, string> params = 4;
21+
map<string, string> serviceConfigurations = 5;
22+
map<string, string> credentialsConfigurations = 6;
2123
}
2224

2325
// The invocation response message
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ai.wanaku.core.util;
2+
3+
import java.util.Map;
4+
import java.util.stream.Collectors;
5+
6+
public class CollectionsHelper {
7+
private CollectionsHelper() {}
8+
9+
/**
10+
* Convert a map of String keys and unspecified type to String (value must be
11+
* convertible to String using toString())
12+
* @param map the map of String keys and unspecified type
13+
* @return A Map of String keys and String values
14+
*/
15+
public static Map<String, String> toStringStringMap(Map<String, ?> map) {
16+
return map.entrySet().stream()
17+
.filter(e -> e.getValue() != null)
18+
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toString()));
19+
}
20+
}

routers/wanaku-router/src/main/java/ai/wanaku/routers/proxies/resources/ResourceAcquirerProxy.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717

1818
package ai.wanaku.routers.proxies.resources;
1919

20-
import java.util.List;
21-
import java.util.Map;
22-
2320
import ai.wanaku.api.types.ResourceReference;
21+
import ai.wanaku.api.types.management.Configuration;
22+
import ai.wanaku.api.types.management.Configurations;
2423
import ai.wanaku.api.types.management.Service;
2524
import ai.wanaku.core.exchange.InquireReply;
2625
import ai.wanaku.core.exchange.InquireRequest;
@@ -35,6 +34,8 @@
3534
import io.quarkiverse.mcp.server.ResourceContents;
3635
import io.quarkiverse.mcp.server.ResourceManager;
3736
import io.quarkiverse.mcp.server.TextResourceContents;
37+
import java.util.List;
38+
import java.util.Map;
3839
import org.jboss.logging.Logger;
3940

4041
/**
@@ -56,7 +57,7 @@ public List<ResourceContents> eval(ResourceManager.ResourceArguments arguments,
5657
}
5758

5859
LOG.infof("Requesting %s from %s", mcpResource.getName(), service.getTarget());
59-
final ResourceReply reply = acquireRemotely(mcpResource, service.getTarget());
60+
final ResourceReply reply = acquireRemotely(mcpResource, arguments, service);
6061
if (reply.getIsError()) {
6162
TextResourceContents textResourceContents =
6263
new TextResourceContents(arguments.requestUri().value(), reply.getContent(), "text/plain");
@@ -75,16 +76,20 @@ public String name() {
7576
return "resource-acquirer";
7677
}
7778

78-
private ResourceReply acquireRemotely(ResourceReference mcpResource, String target) {
79-
ManagedChannel channel = ManagedChannelBuilder.forTarget(target)
79+
private ResourceReply acquireRemotely(ResourceReference mcpResource, ResourceManager.ResourceArguments arguments, Service service) {
80+
ManagedChannel channel = ManagedChannelBuilder.forTarget(service.getTarget())
8081
.usePlaintext()
8182
.build();
8283

84+
Map<String, Configuration> configurations = service.getConfigurations().getConfigurations();
85+
Map<String, String> serviceConfigurations = Configurations.toStringMap(configurations);
86+
8387
ResourceRequest request = ResourceRequest
8488
.newBuilder()
8589
.setLocation(mcpResource.getLocation())
8690
.setType(mcpResource.getType())
8791
.setName(mcpResource.getName())
92+
.putAllServiceConfigurations(serviceConfigurations)
8893
.build();
8994

9095
ResourceAcquirerGrpc.ResourceAcquirerBlockingStub blockingStub = ResourceAcquirerGrpc.newBlockingStub(channel);

routers/wanaku-router/src/main/java/ai/wanaku/routers/proxies/tools/InvokerProxy.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package ai.wanaku.routers.proxies.tools;
1919

20-
import java.util.Map;
21-
2220
import ai.wanaku.api.types.ToolReference;
2321
import ai.wanaku.api.types.management.Configuration;
2422
import ai.wanaku.api.types.management.Configurations;
@@ -30,11 +28,13 @@
3028
import ai.wanaku.core.exchange.ToolInvokeRequest;
3129
import ai.wanaku.core.exchange.ToolInvokerGrpc;
3230
import ai.wanaku.core.mcp.providers.ServiceRegistry;
31+
import ai.wanaku.core.util.CollectionsHelper;
3332
import ai.wanaku.routers.proxies.ToolsProxy;
3433
import io.grpc.ManagedChannel;
3534
import io.grpc.ManagedChannelBuilder;
3635
import io.quarkiverse.mcp.server.ToolManager;
3736
import io.quarkiverse.mcp.server.ToolResponse;
37+
import java.util.Map;
3838
import org.jboss.logging.Logger;
3939

4040
/**
@@ -70,15 +70,15 @@ private static ToolInvokeReply invokeRemotely(
7070
ManagedChannel channel = ManagedChannelBuilder.forTarget(service.getTarget()).usePlaintext().build();
7171

7272
Map<String, Configuration> configurations = service.getConfigurations().getConfigurations();
73-
Map<String, String> collect = Configurations.toStringMap(configurations);
73+
Map<String, String> serviceConfigurations = Configurations.toStringMap(configurations);
74+
Map<String, String> argumentsMap = CollectionsHelper.toStringStringMap(toolArguments.args());
7475

7576
Request result = Request.newRequest(toolReference, toolArguments);
7677
ToolInvokeRequest toolInvokeRequest = ToolInvokeRequest.newBuilder()
7778
.setBody(result.body())
7879
.setUri(result.uri())
79-
.putAllServiceConfigurations(collect)
80-
// TODO
81-
// .getArgumentsMap().putAll(toolArguments.args())
80+
.putAllServiceConfigurations(serviceConfigurations)
81+
.putAllArguments(argumentsMap)
8282
.build();
8383

8484
ToolInvokerGrpc.ToolInvokerBlockingStub blockingStub = ToolInvokerGrpc.newBlockingStub(channel);

0 commit comments

Comments
 (0)