Skip to main content

Dynamic tool discovery for AI agents using the MCP-Zero Active Discovery pattern

Project description

Magetools

A Portable Grimorium for Agentic Tool Discovery.

Python 3.13+ License: MIT Tests

Magetools gives autonomous AI agents scalable access to thousands of tools ("Spells") without overwhelming their context window. It uses a Hierarchical Active Discovery pattern to organize tools into collections/directories ("Grimoriums") and files ("Chapters") and functions ("Spells"), allowing agents to discover only what they need, when they need it.

Features

  • 100% Test Coverage: Fully verified core logic for maximum reliability.
  • Active Discovery Protocol: Agents search for capabilities, not specific function names.
  • Safe by Default: Strict Mode requires explicit manifest.json to load any code.
  • Auto-Summarization: Uses Google Gemini to automatically generate technical summaries for your tool collections (Performance optimized: non-blocking).
  • Stale Summary Detection: Automatically detects code changes via folder hashing and triggers re-summarization via CLI.
  • Google ADK Integration: Works with Google ADK agents with more framework integrations coming soon.
  • Graceful Degradation: Works without API keys using MockProvider (limited functionality).

Installation

Using uv (Recommended):

# Core package (minimal dependencies)
uv add magetools

# Full installation with all features
uv add magetools[full]

Using pip:

pip install magetools[full]

Optional Dependencies

Extra Description
[google] Google GenAI provider for embeddings and summaries
[vectordb] ChromaDB for vector storage
[adk] Google ADK integration for agents
[full] All of the above

Usage

Quick Start

# 1. Create a Grimorium(folder) in the .magetools directory
mkdir -p .magetools/file_ops

# 2. Creates the manifest.json for the provided Grimorium(required for Strict Mode)
uv run -m magetools init .magetools/file_ops

# 3. Scan the Grimorium for spells(functions)
# This creates a grimorium_summary.md file with the technical summary of the spells
# and stores the vector embeddings of the spells in a vector database
uv run -m magetools scan

Add Spells (Tools)

# .magetools/file_ops/files.py (A Grimorium chapter is just a .py file in a Grimorium.)
from magetools import spell

@spell
def list_files(path: str = "."):
    """Lists all files in the given directory."""
    import os
    return os.listdir(path)

@spell
def read_file(path: str):
    """Reads and returns the contents of a file."""
    with open(path, "r") as f:
        return f.read()

Use with an Agent

from google.adk.agents import LlmAgent
from magetools import Grimorium


# Initialize (scans .magetools folder and indexes spells)
grimorium = Grimorium()

# Initialize the root agent
root_agent = LlmAgent(
    name="magetools_agent",
    model="gemini-2.5-flash",
    description="Agent that uses magetools to discover and execute spells.",
    instruction=f"""You are an advanced AI assistant with access to magetools.
    Be helpful, concise, and focus on solving the user's request effectively.
    {grimorium.usage_guide}""",
    tools=[grimorium],
)

Agent Discovery Flow

A Magetools Grimorium exposes 4 tools to your agent:

  1. discover_grimoriums(query) – Search for a grimorium using a query
  2. discover_spells(grimorium_id, query) – Search for a spell within a grimorium
  3. execute_spell(spell_name, arguments) – Run a spell
  4. list_spells() – List the names of all available spells from all linked grimoriums(may remove this soon...)

Example:

User: "Find and read the data.csv file."

Agent:

  1. discover_grimoriums("file reading")file_ops
  2. discover_spells("file_ops", "read csv")read_file
  3. execute_spell("file_ops.read_file", {"path": "data.csv"})

Strict Mode (Security)

⚠️ Magetools runs in Strict Mode by default.

Grimoriums require a manifest.json file to load any Python code. This prevents accidental execution of arbitrary code.

# Enable a grimorium
uv run -m magetools init .magetools/my_grimorium

manifest.json example:

{
  "version": "1.0",
  "enabled": true,
  "whitelist": ["list_files", "read_file"]
}

To disable Strict Mode (development only):

grimorium = Grimorium(strict_mode=False)

Configuration

Environment Variables

Variable Default Description
GOOGLE_API_KEY Required for Google GenAI (can be set in .env file)
MAGETOOLS_MODEL gemini-2.5-flash LLM model for technical summaries
MAGETOOLS_DEBUG false Enable debug logging

YAML Configuration

Create magetools.yaml in your project root:

model_name: gemini-2.5-flash
embedding_model: models/text-embedding-004
debug: false

CLI Reference

uv run -m magetools init <directory>  # Generate manifest.json for a grimorium
uv run -m magetools scan              # Scan spells and build metadata summaries
uv run -m magetools --help            # Show all commands and options

Support

Roadmap

  • Local embedding provider (no API key required)
  • LangChain integration example
  • Web UI for spell management

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Run tests: uv run pytest
  4. Submit a pull request

For major changes, open an issue first to discuss.

Authors

  • Malcom Godlike - Initial work

License

MIT

Project Status

🚀 Active Development – This project is actively maintained and accepting contributions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magetools-1.2.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

magetools-1.2.0-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file magetools-1.2.0.tar.gz.

File metadata

  • Download URL: magetools-1.2.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for magetools-1.2.0.tar.gz
Algorithm Hash digest
SHA256 98fe5a8f58886e57ac8e95a55bafc0cd73faefa75adb0e00ab41607056617957
MD5 bad843ac8d9f8d1b8f2ff90abf1dcc88
BLAKE2b-256 6e4c97644ef369dcb51de8980f32e2541e9f2e48f6dccd79715f06c9325f7a00

See more details on using hashes here.

Provenance

The following attestation bundles were made for magetools-1.2.0.tar.gz:

Publisher: release.yml on IAmNo1Special/magetools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file magetools-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: magetools-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for magetools-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c8a4eb499ab5dfd854bfeb5fbaa703faa7e5a31bb0f556ce431a990ffe159e6
MD5 4b79c142db388a5832ec75c1668e33e1
BLAKE2b-256 6072d3a5bccaad97fd087a4eec6c290dd2854548605157869e8d932fcfb69cfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for magetools-1.2.0-py3-none-any.whl:

Publisher: release.yml on IAmNo1Special/magetools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page