Gradio Toolsets - MCP Server Aggregation

Overview

Gradio Toolsets is a Python library for aggregating multiple MCP (Model Context Protocol) servers into a single unified MCP server. It acts as a pass-through server that combines tools from multiple sources (Gradio Spaces and other MCP servers) and provides semantic search capabilities for deferred tool loading.

Repository: github.com/gradio-app/toolsets
Organization: Gradio (Hugging Face)
License: MIT
Stars: 10+ | Commits: 474+
Languages: Python (79.1%), JavaScript (20.7%), Shell (0.2%)

Problem It Solves

Tool Context Explosion
When working with LLM agents that have access to hundreds or thousands of tools, context window becomes a critical bottleneck. Toolsets enables:

  • On-demand tool discovery via semantic search
  • Deferred loading of tools (only load what’s needed)
  • Single unified interface instead of fragmented tool definitions

Multi-Source Tool Integration
Different ML tools are scattered across various platforms (Hugging Face Spaces, custom MCP servers, proprietary endpoints). Toolsets provides unified access to all of them.

Key Features

MCP Server Aggregation

Unified Tool Endpoint

  • Combine tools from multiple Gradio Spaces and MCP servers
  • Expose all aggregated tools through a single MCP endpoint
  • Optional MCP server mode (enabled with mcp_server=True)
  • Pass-through architecture for seamless integration

Multiple Data Sources

  • Gradio Spaces (1000s available on Hugging Face)
  • Custom MCP servers
  • Proprietary tool endpoints
  • Mix and match from different sources

Deferred Tool Loading

Semantic Search Discovery

  • Like Claude’s Advanced Tool Usage, but for any LLM
  • Tools marked with defer_loading=True are not exposed in base tool list
  • Two special MCP tools automatically added:
    • “Search Deferred Tools” - discover tools by natural language query
    • “Call Deferred Tool” - execute discovered tools on-demand
  • Discover tools based on semantic search queries
  • Load only the tools your agent needs for the current task
  • Dramatically reduces context window usage (critical for 100+ tools)

Selective Loading Pattern

from toolsets import Toolset, Tool  
  
toolset = Toolset("My Toolset")  
  
# Add tool with deferred loading enabled  
toolset.add_tool(  
    Tool(  
        name="image_generator",  
        description="Generates images from prompts",  
        fn=my_image_generation_function  
    ),  
    defer_loading=True  
)  

Gradio UI Integration

Built-in Web Interface

  • Toolsets itself is a Gradio application
  • Interactive UI for testing and exploring available tools
  • Search interface for discovering deferred tools
  • Tool testing playground
  • Free hosting on Hugging Face Spaces

Dual Mode Execution

  • Gradio UI for manual exploration and testing
  • MCP endpoint for LLM agent integration
  • Single deployment serves both purposes

Architecture

Tool Aggregation Pattern

Multiple Sources                  Toolsets Library              Client/Agent  
┌─────────────────────┐  
│ Gradio Spaces       │            ┌──────────────┐  
│ (1000s available)   ├──────────▶ │              │  
└─────────────────────┘            │   Toolsets   │  
                                   │              │  
┌─────────────────────┐            │ • Aggregates │          ┌───────────┐  
│ MCP Servers         │──────────▶ │ • Defers     │─────────▶│ LLM Agent │  
│ (Custom/Private)    │            │ • Searches   │          │           │  
└─────────────────────┘            │ • Exposes    │          └───────────┘  
                                   │              │  
┌─────────────────────┐            │ Single MCP   │          ┌───────────┐  
│ Custom Endpoints    │──────────▶ │ Server       │─────────▶│ Gradio UI │  
│ (Proprietary)       │            │              │          │           │  
└─────────────────────┘            └──────────────┘          └───────────┘  

Tool Definition Format

Tools can be added with metadata for better LLM decision-making:

tool = Tool(  
    name="text_to_speech",  
    description="Converts text to natural speech output",  
    notes="Best for final audio generation. Can use voice samples from other tools.",  
    fn=my_tts_function  
)  

Core Concepts

Tools

Named, callable functions with descriptions and metadata. Tools are the atomic units of functionality that Toolsets aggregates.

Tool Properties

  • name - Unique identifier
  • description - Detailed explanation of what tool does (crucial for LLM selection)
  • notes - Optional guidance for tool selection among similar tools
  • fn - Actual implementation (callable)
  • defer_loading - Whether to lazy-load this tool

Toolsets

Collections of tools exposed as a unified service. A Toolset:

  • Acts as a Gradio application (web UI)
  • Exposes an MCP server endpoint (for agents)
  • Manages tool aggregation and discovery
  • Handles semantic search indexing

Deferred Loading

Tools marked for lazy loading are:

  • Not included in initial tool list
  • Discoverable via semantic search
  • Loaded on-demand when agent calls them
  • Indexed by embedding model for natural language search

Usage Patterns

Basic Toolset Creation

from toolsets import Toolset, Tool  
  
# Create toolset  
toolset = Toolset("My Toolset")  
  
# Add tools  
toolset.add_tool(Tool(  
    name="calculator",  
    description="Performs basic arithmetic operations",  
    fn=calculator_function  
))  
  
# Launch with UI  
toolset.launch()  

With Deferred Loading

# Install with semantic search support  
# pip install toolsets[deferred]  
  
toolset = Toolset("Advanced Toolset")  
  
# Add deferred tools (lazy-loaded)  
for tool_info in my_large_tool_list:  
    toolset.add_tool(  
        Tool(name=tool_info.name, description=tool_info.desc, fn=tool_info.fn),  
        defer_loading=True  
    )  
  
# Launch with MCP server  
toolset.launch(mcp_server=True)  

With Custom Embedding Model

from sentence_transformers import SentenceTransformer  
  
# Use custom embedding model for search  
embedding_model = SentenceTransformer('all-MiniLM-L6-v2')  
  
toolset = Toolset(  
    "Custom Embeddings Toolset",  
    embedding_model=embedding_model  
)  

Tool Selection Guidance

# Guide LLM with notes when tools are similar  
toolset.add_tool(Tool(  
    name="maya1_tts",  
    description="Generates natural speech from text",  
    notes="Best for creating voice samples. Outputs reference audio for other TTS tools.",  
    fn=maya1_function  
))  
  
toolset.add_tool(Tool(  
    name="chatterbox_tts",  
    description="Generates high-quality speech synthesis",  
    notes="Use for final TTS output. Optionally takes Maya1 output as voice sample.",  
    fn=chatterbox_function  
))  

Configuration

MCP Server Mode

Enable the MCP server endpoint:

toolset.launch(mcp_server=True)  

When enabled:

  • MCP server available at /gradio_api/mcp
  • Configuration tab in UI shows connection details
  • LLM agents can connect and use tools
  • Both Gradio UI and MCP endpoints work simultaneously

Tool Description Format

Customize how tool descriptions are formatted for the LLM:

toolset = Toolset(  
    "My Toolset",  
    tool_description_format="{name}: {description} {notes}"  
)  

Deployment to Hugging Face Spaces

Steps to deploy:

  1. Go to https://huggingface.co/new-space
  2. Select Gradio SDK
  3. Create app.py with your toolset code
  4. Add requirements.txt with toolsets (or toolsets[deferred] for search)
  5. Toolset available as both Gradio UI and MCP server

Example requirements.txt:

toolsets[deferred]  

Integration Points

With Gradio

Toolsets is built on Gradio, so:

  • Inherits full Gradio component library
  • Can add custom UI components
  • Free hosting on Hugging Face Spaces
  • Built-in test interface for tools

With MCP (Model Context Protocol)

  • Follows MCP specification
  • Integrates with any MCP-compatible client
  • Tools exposed as standard MCP resources
  • Works with Claude and other MCP-aware models

With LLM Agents

  • Compatible with any agent framework that supports MCP
  • Works with LangChain agents
  • Works with Claude Code and other Claude tools
  • Advanced Tool Use semantics supported

With Hugging Face Ecosystem

  • Deploy on Hugging Face Spaces
  • Access Hugging Face Models (planned)
  • Access Hugging Face Datasets (planned)
  • Access Hugging Face Papers (planned)

Roadmap

Hugging Face Ecosystem Integration

  • Automatic token passing in headers for private and ZeroGPU spaces
  • Datasets integration for easy RAG on documentation
  • Models support with inference provider usage
  • Papers search and query capabilities

Performance & Reliability

  • Enhanced error handling with better retry logic
  • Connection pooling for multiple concurrent requests
  • Graceful degradation when sources unavailable
  • Tool definition caching
  • Embedding caching to reduce API calls and startup time

Advanced Features

  • Tool versioning support
  • Tool dependency resolution
  • Authentication/authorization per tool
  • Rate limiting and quota management

Real-World Example: Podcasting Toolset

Live example deployed on Hugging Face:
abidlabs/podcasting-toolset

Demonstrates:

  • Multiple tool aggregation
  • Gradio UI for exploration
  • MCP endpoint for agents
  • Real-world production deployment

Comparison with Alternatives

vs. Individual Tool APIs

  • Toolsets: Single endpoint, unified discovery, deferred loading
  • Individual APIs: Fragmented, context-heavy, no discovery mechanism

vs. Manual Tool Lists

  • Toolsets: Semantic search, automatic indexing, lazy loading
  • Manual Lists: Static, context-heavy, manual maintenance

vs. Custom Tool Aggregators

  • Toolsets: Purpose-built, production-ready, open-source, free hosting
  • Custom: One-off solutions, maintenance burden, deployment required

Technology Stack

  • Language: Python (primary), JavaScript
  • Web Framework: Gradio
  • Embedding: Sentence Transformers (for semantic search)
  • Protocol: MCP (Model Context Protocol)
  • Hosting: Hugging Face Spaces (free)

Use Cases

Multi-Modal AI Assistants

Combine image, audio, text, and video tools in one unified interface for intelligent assistants.

Research Agent Tools

Aggregate academic tools (paper search, citation analysis, data processing) for research automation.

Enterprise Tool Aggregation

Combine proprietary internal tools with external services under unified MCP endpoint.

Cost-Optimized Large-Scale Agents

Defer loading of 100+ tools to avoid context window explosion with smaller models.

Tool Discovery Systems

Let agents discover and learn about new tools via semantic search at runtime.

Project Status

  • Maturity: Active development (Gradio org official project)
  • Community: 31+ contributors
  • Documentation: README and examples available
  • Testing: Test suite included
  • Breaking Changes: Tracked in CHANGELOG.md

Resources

Sources

  1. Gradio Toolsets GitHub Repository - https://github.com/gradio-app/toolsets
  2. Gradio Toolsets README - https://github.com/gradio-app/toolsets/blob/main/README.md
  3. Live Example: Podcasting Toolset - https://huggingface.co/spaces/abidlabs/podcasting-toolset
  4. Gradio Documentation - https://www.gradio.app/docs
  5. Related: Gradio Tools Library - https://github.com/freddyaboulton/gradio-tools