From 8bc6368f4e3bc1f3f1d1657e4e9b10b9c4443566 Mon Sep 17 00:00:00 2001 From: Fanyang Meng Date: Thu, 13 Feb 2025 00:47:20 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Furthur=20improve=20the=20struct?= =?UTF-8?q?ure,=20simplify=20the=20codebase=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ghost_mcp/tools.py | 56 ------------------ src/ghost_mcp/tools/__init__.py | 102 ++++++++++++++++---------------- 2 files changed, 52 insertions(+), 106 deletions(-) delete mode 100644 src/ghost_mcp/tools.py diff --git a/src/ghost_mcp/tools.py b/src/ghost_mcp/tools.py deleted file mode 100644 index 51d718a..0000000 --- a/src/ghost_mcp/tools.py +++ /dev/null @@ -1,56 +0,0 @@ -"""Ghost MCP tools package. - -This module dynamically imports all tools from the tools package directory. -It automatically discovers and imports all non-private functions and variables -from Python files in the tools directory, making them available at the package level. - -When adding new tools: -1. Create new Python files in the tools directory -2. Define your tools as functions in these files -3. No need to modify this file - tools will be imported automatically -""" - -from importlib import import_module -from pathlib import Path -from typing import Dict, Any - -def _import_submodules() -> Dict[str, Any]: - """Dynamically import all modules from the tools package. - - Returns: - Dict mapping module names to imported module objects - - Raises: - FileNotFoundError: If the tools directory doesn't exist - """ - current_dir = Path(__file__).parent - tools_dir = current_dir / 'tools' - - if not tools_dir.exists(): - raise FileNotFoundError(f"Tools directory not found at: {tools_dir}") - - modules: Dict[str, Any] = {} - for py_file in tools_dir.glob('*.py'): - if py_file.name.startswith('__'): - continue - - module_name = py_file.stem - full_module_name = f"ghost_mcp.tools.{module_name}" - - # Import the module - module = import_module(f".tools.{module_name}", package="ghost_mcp") - modules[module_name] = module - - # Get all non-private attributes - for attr_name in dir(module): - if not attr_name.startswith('_'): - # Add to the current module's namespace - globals()[attr_name] = getattr(module, attr_name) - - return modules - -# Run the dynamic imports -_import_submodules() - -# Create sorted __all__ from the imported attributes for consistent ordering -__all__ = sorted(name for name in globals() if not name.startswith('_')) diff --git a/src/ghost_mcp/tools/__init__.py b/src/ghost_mcp/tools/__init__.py index 256207b..45767c5 100644 --- a/src/ghost_mcp/tools/__init__.py +++ b/src/ghost_mcp/tools/__init__.py @@ -1,52 +1,54 @@ -"""Ghost MCP tools package.""" +"""Ghost MCP tools package. -from .posts import search_posts_by_title, list_posts, read_post, create_post, update_post, delete_post, batchly_update_post -from .users import list_users, read_user, update_user, delete_user -from .members import list_members, read_member, create_member, update_member -from .tiers import list_tiers, read_tier, create_tier, update_tier -from .offers import list_offers, read_offer, create_offer, update_offer -from .newsletters import list_newsletters, read_newsletter, create_newsletter, update_newsletter -from .roles import list_roles -from .invites import create_invite -from .webhooks import create_webhook, update_webhook, delete_webhook -from .tags import browse_tags, read_tag, create_tag, update_tag, delete_tag +This module dynamically imports all tools from Python files in this directory. +It automatically discovers and imports all non-private functions and variables, +making them available at the package level. -__all__ = [ - 'search_posts_by_title', - 'list_posts', - 'read_post', - 'create_post', - 'update_post', - 'delete_post', - 'batchly_update_post', - 'list_users', - 'read_user', - 'update_user', - 'delete_user', - 'list_members', - 'read_member', - 'create_member', - 'update_member', - 'list_tiers', - 'read_tier', - 'create_tier', - 'update_tier', - 'list_offers', - 'read_offer', - 'create_offer', - 'update_offer', - 'list_newsletters', - 'read_newsletter', - 'create_newsletter', - 'update_newsletter', - 'list_roles', - 'create_invite', - 'create_webhook', - 'update_webhook', - 'delete_webhook', - 'browse_tags', - 'read_tag', - 'create_tag', - 'update_tag', - 'delete_tag', -] +When adding new tools: +1. Create new Python files in this directory +2. Define your tools as functions in these files +3. No need to modify this file - tools will be imported automatically +""" + +from importlib import import_module +from pathlib import Path +from typing import Dict, Any + +def _import_submodules() -> Dict[str, Any]: + """Dynamically import all modules from the current package. + + Returns: + Dict mapping module names to imported module objects + + Raises: + FileNotFoundError: If the directory doesn't exist + """ + current_dir = Path(__file__).parent + + if not current_dir.exists(): + raise FileNotFoundError(f"Tools directory not found at: {current_dir}") + + modules: Dict[str, Any] = {} + for py_file in current_dir.glob('*.py'): + if py_file.name.startswith('__'): + continue + + module_name = py_file.stem + + # Import the module + module = import_module(f".{module_name}", package="ghost_mcp.tools") + modules[module_name] = module + + # Get all non-private attributes + for attr_name in dir(module): + if not attr_name.startswith('_'): + # Add to the current module's namespace + globals()[attr_name] = getattr(module, attr_name) + + return modules + +# Run the dynamic imports +_import_submodules() + +# Create sorted __all__ from the imported attributes for consistent ordering +__all__ = sorted(name for name in globals() if not name.startswith('_'))