-
Notifications
You must be signed in to change notification settings - Fork 118
Add fine-grained control for MCP server(s) provided tools #1434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is very interesting! I can definitely this being useful. As for testing, maybe @jmartisk has ideas? |
...me/src/main/java/io/quarkiverse/langchain4j/runtime/aiservice/AiServiceMethodCreateInfo.java
Outdated
Show resolved
Hide resolved
@mariofusco nice! For the upstream, perhaps we can add a programmatic config on the McpToolProvider level which will keep only specified tools or exclude only specified tools, WDYT? |
Yea I'd say we could change the upstream |
The testing side will be a bit tricky. On the upstream langchain4j side, we have full-fledged MCP servers running using JBang, but here, we only have a mock MCP server that is exposed in the form of a REST endpoint - we might want to switch to doing something more similar to the upstream in the future... But with the current approach, I could imagine adding two more mock MCP servers that are simpler than |
@jmartisk @dliubarskyi I'm trying to follow this suggestion and more in general to move (in a more general way, e.g. introducing that predicate suggested by Jan) the logic that I implemented in the
WDYT? Is there anything that I could implement in langchain4j anyway or do we want to keep this only on the quarkus extension side? /cc @geoand |
@mariofusco I am not sure about McpToolProvider.builder()
.mcpClients(...)
.includeTools("calc", "weather") // either by name
.includeTools(Predicate<ToolSpecification>) // or by predicate
.excludeTools("cmd") // either by name
.excludeTools(Predicate<ToolSpecification>) // or by predicate
.build() Perhaps we are talking about 2 different things here? |
My bad, I have misread the PR description: @RegisterAiService
public interface MyService {
@McpToolBox({"A", "C"})
String chat(String query);
} I wrongly assumed that |
Filtering the tools provided by a single MCP server also makes lot's of sense tbh, I'm also seeing some of them providing too many tools, but I believe this could be something orthogonal e not strictly dependent on what proposed here. @dliubarskyi I can also start working on this second feature if you agree and see some value in this. |
Sure, it is a separate issue
I think it is a metter of time before someone will ask for this feature, but there is also no rush and I would finalize 1.0 before starting new features |
@jmartisk @geoand According to what also discussed with @dliubarskyi this feature doesn't make much sense in vanilla langchain4j, but I still believe it is useful here in the extension, so I would keep developing it here. Please let me know if you agree and in this case I will try to add at least one test for this. |
I believe this is a useful feature |
@mariofusco seems that users want to filter MCP tools as well as modify their descriptions: devoxx/DevoxxGenieIDEAPlugin#670 |
97a5da9
to
386ceaf
Compare
@jmartisk I added tests trying to follow your suggestions, thanks a lot for them. Please give it a look. |
Nice, but that's a filter of tools in the single MCP server. As discussed this is an orthogonal (and complementary) feature and can be implemented directly in langchain4j. I will give this a try. |
The last doubt I have (and the reason why I'm still leaving this as a draft for now) is how to express the fact that I may NOT want any MCP client for a specific AI service. At the moment annotating a service with
Personally I found option 1. much clearer and less error prone, wdyt? Do you see any other possibility? |
Thanks a lot @mariofusco. I'm actually torn on this. On one hand option |
Can you please clarify why you wrote that option 2. is in line with what |
Oops, I reversed the order :). My point is that I don't really have a strong opinion, but I guess if I were forced to choose, I would go with |
Agreed, I will go with 1. |
Thanks! I'll let @jmartisk review this as it directly touches his work |
This comment has been minimized.
This comment has been minimized.
mcp/runtime/src/main/java/io/quarkiverse/langchain4j/mcp/runtime/McpToolBox.java
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
Status for workflow
|
Not completely sure whether it wouldn't be cleaner to just let the user to create their own tool providers for this purpose (if they want to allow just specific MCPs for a specific AI service/method, create a specific tool provider that uses only the desired clients). An annotation looks simpler, but look at how much complexity it is adding. Anyway, I don't object, if others find it useful, then so be it. |
I totally see your point about the added complexity, but under a users point of view I also believe that a very small fraction of them will decide to create their own Anyway I'm also not strongly opinionated on this and I will let @geoand and @dliubarskyi to take the final decision. |
Let's add this for now and see how it goes |
This is an implementation for #1409
At the moment the
McpToolBox
annotation is only used to limit the MCP servers that a AI service can use. In other words if you have configured the MCP servers A, B and C, the following service:will be provided only for tools in the server A and C, but not B. If the
McpToolBox
annotation is present with no values or is not present at all it will behave in the same way, automatically providing all the tools for all the configured MCP servers. I did this to keep backward compatibility, but in reality what I would like to do is giving access to the MCP provided tools only to method annotated withMcpToolBox
, only the named ones or all if used without values. Any feedback on this is welcome.I implemented this feature purely on the extension side and for this reason I had add to add a
QuarkusToolProviderRequest
and aQuarkusMcpToolProvider
, but maybe we may this also in LangChain4j, so I could move the changes that I introduced with those classes directly there? /cc @dliubarskyiFinally I'm struggling to find a way to properly test this feature, so any suggestion about this will be also very welcome.
/cc @jmartisk @geoand