Skip to content

Add fine-grained control for MCP server(s) provided tools #1409

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

Open
mariofusco opened this issue Apr 4, 2025 · 2 comments
Open

Add fine-grained control for MCP server(s) provided tools #1409

mariofusco opened this issue Apr 4, 2025 · 2 comments

Comments

@mariofusco
Copy link
Contributor

At the moment all tools exposed by all MCP servers configured in an application are automatically made available to all AI services in that application. This can potentially provide an AI service with tens of tools that it doesn't need and it isn't supposed to use, thus increasing the possibility of hallucinations.

It would be nice to have a chance to selectively decide if a AI service is supposed to use MCP servers and eventually which ones, in the same way to what we currently do for internal tools through the @ToolBox annotation. For instance we could have a similar @McpToolBox annotation taking an array of Strings representing the names of the MCP servers configured in the application.properties, something like

@McpToolBox({"wolfram-llm", "weather"})

where if no server name is provided, it means that we want to use all of them.

@geoand
Copy link
Collaborator

geoand commented Apr 4, 2025

Makes sense to me.

WDYT @jmartisk ?

@jmartisk
Copy link
Collaborator

jmartisk commented Apr 7, 2025

The current idea is that if you need an AI service to use specific MCP clients, you use a tool provider.

@ApplicationScoped
public class MyToolProviderSupplier implements Supplier<ToolProvider> {

  private ToolProvider toolProvider;

  @Inject 
  @McpClientName("client1")
  McpClient client1;

  @Inject
  @McpClientName("client2")
  McpClient client2;
   
  @Override
  public ToolProvider get() {
      if(toolProvider == null) {          
            toolProvider = McpToolProvider.builder()
                    .mcpClients(mcpClient1, mcpClient2)
                    .build();
      }
      return toolProvider;
  }
}

@RegisterAiService(toolProviderSupplier = MyToolProviderSupplier.class)
public interface MyAiService {
  // ...
}

Right, that's much more verbose, but it gives the user more control. One can also develop a custom ToolProvider that provides MCP clients as well as custom tools on top (or also it can filter the tools returned from MCP servers if the user needs to exclude some). Isn't this enough?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants