MCP Dynamic Tool Groups

MCP Dynamic Tool Groups

Demo MCP server exposing dynamic tool groups via annotated Java interfaces

2
Stars
0
Forks
0
Releases

Overview

The MCP Dynamic Tool Groups project demonstrates how to create and manage ToolGroups on an MCP server at runtime using annotated Java interfaces/classes. It uses McpTool and McpToolParam annotations to embed tool metadata directly in the interface (example ToolGroup: add, multiply, asyncAdd, asyncMultiply). The ExampleToolGroup interface is registered on the server via the ToolGroupComponent OSGi component, which injects SyncMcpToolGroupServer and AsyncMcpToolGroupServer and registers the group with addToolGroups during activation. Tools can be listed, invoked with input, and output retrieved; the server supports both synchronous and asynchronous operations. Tool specs are generated on activation and collected in syncSpecifications and asyncSpecifications; on deactivate, they are removed from the server via removeTools. The approach relies on reflection to derive tool definitions from the interface, ensuring metadata is part of the API contract. The README notes that this approach can be duplicated in other languages and that Nested ToolGroups can be created or added via other data sources or tooling, enabling flexible organization and testing, including red-teaming use cases.

Details

Owner
ECF
Language
Java
License
Apache License 2.0
Updated
2025-12-07

Features

Dynamic Tool Group Registration and Removal

Tool groups and their tools are registered with MCP servers at runtime via addToolGroups and can be removed with removeTools.

Annotation-driven Tool Metadata

@McpTool and @McpToolParam annotations provide automatic MCP metadata from interface definitions.

Sync and Async Tool Support

Supports both synchronous (add, multiply) and asynchronous (asyncAdd, asyncMultiply) tools.

OSGi-based Lifecycle

Integrates with OSGi using @Component, @Activate and @Deactivate to manage registration.

Automatic Tool Specs on Activation

Tool specifications are generated when the ToolGroupComponent activates and stored for use by the servers.

Reflection-based Tool Discovery

Tools are discovered by reflecting on the ExampleToolGroup.class to determine available tools and metadata.

Client-facing Tool Discovery and Execution

MCP clients can list tools, view metadata, provide inputs, call tools, and receive outputs.

Nested ToolGroups and Flexible Organization

Nested ToolGroups can be created/added via databases, file systems, or other tooling for organization and testing.

Audience

MCP server developersto implement dynamic ToolGroups and expose tools via MCP servers using annotations.
QA and security testersto test dynamic tool groups, organize tests, and perform red-teaming scenarios.
Java service integratorsto annotate interfaces with McpTool and McpToolParam to expose tools for clients.

Tags

MCPtool groupsdynamic toolsannotationsMcpToolMcpToolGroupMcpToolParamOSGiJavareflectiontool specificationsserver