A Python toolsets library
Project description
toolsets
A high-level abstraction layer that aggregates multiple MCP (Model Context Protocol) servers and tools into a single, unified entry point. Toolsets uses semantic search over tool embeddings to dynamically retrieve only the most relevant tools for each query, reducing context window bloat and improving LLM reasoning efficiency.
Features
- Semantic Tool Discovery: Uses vector embeddings to find relevant tools based on natural language queries
- MCP Server Aggregation: Combine tools from multiple Gradio Spaces and MCP servers
- Persistent Storage: ChromaDB-based vector store that persists tool embeddings and schemas
- Gradio Interface: Built-in testing and deployment interface with MCP server support
- Lightweight: Uses local embeddings (sentence-transformers) - no API costs
Installation
This package requires Python 3.10 or higher. Install with pip:
pip install toolsets
or with uv:
uv pip install toolsets
Quick Start
from toolsets import Toolset
# Create a toolset instance
toolset = Toolset()
# Add tools from a Gradio Space (MCP server)
toolset.add("ResembleAI/chatterbox-turbo-demo")
# Search for relevant tools
results = toolset.search_tools("generate speech from text", k=3)
for tool in results:
print(f"{tool['name']}: {tool['description']}")
# Execute a tool
result = toolset.execute_tool(
"ResembleAI/chatterbox-turbo-demo::generate_speech",
{"text": "Hello, world!", "voice": "default"}
)
# Launch interactive Gradio interface
toolset.launch()
Core Concepts
Toolset Class
The Toolset class is the main interface for managing and using aggregated MCP tools.
Adding Tools
toolset = Toolset()
# Add all tools from a Gradio Space
toolset.add("username/space-name")
# Add specific tools only
toolset.add("username/space-name", tools=["tool1", "tool2"])
# Add from full URL
toolset.add("https://huggingface.co/spaces/username/space-name")
When you call add(), the library:
- Connects to the MCP server and fetches tool definitions
- Generates semantic embeddings for each tool's name and description
- Stores embeddings and schemas in the local ChromaDB vector store
Searching Tools
# Search for tools matching a query
tools = toolset.search_tools("edit images", k=5)
# Each result contains:
# - id: Unique tool identifier (space_name::tool_name)
# - name: Tool name
# - description: Tool description
# - schema: JSON schema for tool parameters
# - space_url: URL of the source MCP server
# - space_name: Name of the source space
# - distance: Similarity distance (lower is better)
Executing Tools
# Execute a tool with parameters
result = toolset.execute_tool(
tool_id="space_name::tool_name",
parameters={"param1": "value1", "param2": "value2"}
)
Launching the Interface
# Launch Gradio interface for testing
toolset.launch(port=7860, share=False)
# With sharing enabled (for temporary public URL)
toolset.launch(port=7860, share=True)
The Gradio interface provides:
- Search Tools: Test semantic search with natural language queries
- Execute Tool: Run tools with custom parameters
- Get Tool Schema: View tool parameter schemas
- Info: List all registered spaces
API Reference
Toolset
__init__(persist_directory: Optional[str] = None)
Create a new Toolset instance.
Parameters:
persist_directory(Optional[str]): Directory for storing ChromaDB data. Defaults to~/.toolsets/chroma.
Example:
toolset = Toolset()
toolset = Toolset(persist_directory="./my_tools")
add(space_name_or_url: str, tools: Optional[List[str]] = None)
Register tools from an MCP server (Gradio Space).
Parameters:
space_name_or_url(str): Gradio Space name (e.g.,"username/space") or full URLtools(Optional[List[str]]): Optional list of tool names to filter. If None, all tools are added.
Raises:
ConnectionError: If unable to connect to the MCP serverValueError: If the server doesn't expose MCP tools
Example:
toolset.add("ResembleAI/chatterbox-turbo-demo")
toolset.add("fffiloni/diffusers-image-outpaint", tools=["outpaint"])
search_tools(query: str, k: int = 5) -> List[Dict[str, Any]]
Perform semantic search to find relevant tools.
Parameters:
query(str): Natural language query describing the desired functionalityk(int): Number of top results to return (default: 5)
Returns:
List[Dict[str, Any]]: List of tool dictionaries with metadata
Example:
tools = toolset.search_tools("convert text to speech", k=3)
execute_tool(tool_id: str, parameters: Dict[str, Any]) -> Any
Execute a tool via its MCP server.
Parameters:
tool_id(str): Tool identifier in formatspace_name::tool_nameparameters(Dict[str, Any]): Tool parameters as a dictionary
Returns:
Any: Tool execution result
Raises:
ValueError: If tool_id is not found in registryRuntimeError: If tool execution fails
Example:
result = toolset.execute_tool(
"chatterbox-turbo-demo::generate_speech",
{"text": "Hello", "voice": "default"}
)
launch(port: int = 7860, share: bool = False, server_name: Optional[str] = None)
Launch the Gradio interface and MCP server.
Parameters:
port(int): Port to run the server on (default: 7860)share(bool): Create a public Gradio share link (default: False)server_name(Optional[str]): Server hostname (default: None for localhost)
Example:
toolset.launch(port=7860, share=False)
Architecture
Toolsets implements a Router-Executor pattern:
- Router: Performs semantic search to identify relevant tools based on user queries
- Executor: Executes selected tools via their original MCP servers
- Vector Store: Maintains embeddings of tool names/descriptions in ChromaDB
- Gradio Interface: Provides testing interface and serves as MCP server itself
Data Flow
User Query
↓
Toolset.search_tools()
↓
Semantic Embedding (sentence-transformers)
↓
ChromaDB Vector Search
↓
Top-K Tool Schemas
↓
LLM Context (dynamic injection)
↓
Tool Selection
↓
Toolset.execute_tool()
↓
MCP Client → Original MCP Server
↓
Tool Result
Storage
- Embeddings: Stored in ChromaDB with cosine similarity search
- Schemas: Persisted as JSON alongside embeddings
- Location:
~/.toolsets/chroma/by default
Examples
Basic Usage
from toolsets import Toolset
toolset = Toolset()
# Add tools from multiple spaces
toolset.add("ResembleAI/chatterbox-turbo-demo")
toolset.add("fffiloni/diffusers-image-outpaint")
# Search for image editing tools
image_tools = toolset.search_tools("edit or modify images", k=5)
print(f"Found {len(image_tools)} image editing tools")
# Execute a tool
result = toolset.execute_tool(
"diffusers-image-outpaint::outpaint",
{
"image": "path/to/image.jpg",
"prompt": "extend the image",
"mask": None
}
)
Filtering Tools
toolset = Toolset()
# Only add specific tools from a space
toolset.add(
"ResembleAI/chatterbox-turbo-demo",
tools=["generate_speech", "list_voices"]
)
Custom Persistence Directory
toolset = Toolset(persist_directory="./my_tool_embeddings")
toolset.add("username/space-name")
Launching for Testing
toolset = Toolset()
toolset.add("ResembleAI/chatterbox-turbo-demo")
toolset.add("fffiloni/diffusers-image-outpaint")
# Launch interactive interface
toolset.launch(port=7860, share=False)
# Access at http://localhost:7860
# MCP server available at http://localhost:7860/gradio_api/mcp/schema
Development
To set up the package for development, clone this repository and run:
pip install -e ".[dev]"
Testing
Run tests with:
pytest
Code Formatting
Format code using Ruff:
ruff check --fix --select I && ruff format
How It Works
-
Tool Registration: When you call
add(), the library connects to the MCP server and retrieves tool definitions (name, description, schema). -
Embedding Generation: Each tool's name and description are combined into a text string (
"{name}: {description}") and embedded using theall-MiniLM-L6-v2sentence transformer model. -
Vector Storage: Embeddings are stored in ChromaDB with metadata (tool ID, space URL, schema, etc.).
-
Semantic Search: When searching, your query is embedded using the same model, and ChromaDB performs cosine similarity search to find the most relevant tools.
-
Dynamic Tool Injection: Only the top-k most relevant tool schemas are returned, reducing context window usage compared to exposing all tools upfront.
-
Tool Execution: Tools are executed by proxying requests to their original MCP servers, maintaining the original functionality.
Requirements
- Python 3.10+
- ChromaDB (for vector storage)
- sentence-transformers (for embeddings)
- Gradio (for interface and MCP server)
- httpx (for MCP client connections)
Limitations
- Currently supports Gradio Spaces that expose MCP servers
- Embeddings are generated locally (requires model download on first use)
- Tool execution requires network access to original MCP servers
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file toolsets-0.1.1-py3-none-any.whl.
File metadata
- Download URL: toolsets-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ac1deca97efc259ec74dcc9fe039d58aeb808b90634f6dcc47ea0b2ecd4d881
|
|
| MD5 |
22fb14c3e79eafa3ab00f358000c1d37
|
|
| BLAKE2b-256 |
bb4d999b9d25278a823b7e5161040a565b7cd16cbc02340b9a1e758f3d5aca7c
|
Provenance
The following attestation bundles were made for toolsets-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on abidlabs/toolsets
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toolsets-0.1.1-py3-none-any.whl -
Subject digest:
2ac1deca97efc259ec74dcc9fe039d58aeb808b90634f6dcc47ea0b2ecd4d881 - Sigstore transparency entry: 820345596
- Sigstore integration time:
-
Permalink:
abidlabs/toolsets@6f97448d11c3896d2657558ca77e1f1e95900af8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/abidlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6f97448d11c3896d2657558ca77e1f1e95900af8 -
Trigger Event:
push
-
Statement type: