Package Name:
core
Version: 0.1.0
Source Path:packages/core/src/core/
The core package serves as the foundation layer of the entire system, taking on the following responsibilities:
- Providing a Dependency Injection (DI) container
- Managing the MCP Tool/Prompt Registry
- Defining the Exception Hierarchy
- Providing the Logging infrastructure
- Handling Dynamic Plugin Loading and launching the MCP server
⚠️ coredepends on no other packages. It is the lowest level module upon which all other packages rely.
packages/core/src/core/
├── __init__.py # Package initialization (no exports)
├── config.py # Configuration class
├── di_container.py # Dependency Injection container
├── exceptions.py # Exception hierarchy
├── logger.py # Logger factory
├── registry.py # MCP tool/prompt registry
├── prompt_plugin.py # Orchestrator Prompt plugin
└── main.py # Application entry point
A configuration holder class that reads settings from environment variables.
| Attribute | Type | Default | Environment Variable | Description |
|---|---|---|---|---|
DEFAULT_TIMEOUT_MS |
int |
30000 |
AGENT_TIMEOUT_MS |
Command timeout (ms) |
LOG_LEVEL |
str |
"INFO" |
AGENT_LOG_LEVEL |
Logging level |
A simple DI container. It supports both singleton instances and factories.
class DIContainer:
def __init__(self):
self._services: Dict[Type, Any] # Registered singleton instances
self._factories: Dict[Type, Callable] # Factory functions
def register(self, service_type: Type[T], instance: T) -> None
def register_factory(self, service_type: Type[T], factory: Callable[[], T]) -> None
def resolve(self, service_type: Type[T]) -> T| Method | Description |
|---|---|
register(service_type, instance) |
Directly registers a singleton instance for a type |
register_factory(service_type, factory) |
Registers a factory function. Evaluated lazily upon resolve |
resolve(service_type) -> T |
Gets the instance from _services. If missing, creates and caches it using _factories |
Usage Pattern:
sequenceDiagram
participant Plugin
participant DI as DIContainer
participant Service
Plugin->>DI: register(ServiceType, instance)
Note over DI: _services[ServiceType] = instance
Plugin->>DI: resolve(ServiceType)
DI-->>Plugin: instance
classDiagram
Exception <|-- AgentToolError
AgentToolError <|-- SystemCommandError
AgentToolError <|-- FileSystemError
AgentToolError <|-- ConfigurationError
class AgentToolError {
+message: str
Base class for domain errors
}
class SystemCommandError {
Raised when a system command fails
}
class FileSystemError {
Raised for file system errors
}
class ConfigurationError {
Raised for invalid configurations
}
def get_logger(name: str) -> logging.Logger- Returns a
logging.Loggerconfigured to output tosys.stderrwith a specific format. - Format: Standard
%(asctime)s - %(name)s - %(levelname)s - %(message)s
A central registry managing the registration and routing of MCP tools and prompts.
class MCPRegistry:
def __init__(self):
self._tools: List[types.Tool]
self._tool_handlers: Dict[str, ToolHandler]
self._prompts: List[...]
self._prompt_handlers: Dict[str, ...]
# Tool management
def register_tool(self, tool_def: types.Tool, handler: ToolHandler) -> None
def get_tools(self) -> List[types.Tool]
async def call_tool(self, name: str, arguments: dict) -> list[types.TextContent]
# Prompt management
def register_prompt(self, prompt_def, handler) -> None
def get_prompts(self) -> List[...]
async def get_prompt(self, name: str, arguments: dict) -> ...| Method | Description |
|---|---|
register_tool(tool_def, handler) |
Registers a tool definition and its async handler |
get_tools() |
Returns a list of all registered tools |
call_tool(name, arguments) |
Resolves the tool by name and executes its handler |
register_prompt(prompt_def, handler) |
Registers a prompt definition and handler |
get_prompts() |
Returns a list of registered prompts |
get_prompt(name, arguments) |
Resolves the prompt by name and executes its handler |
A plugin to register the orchestrator_prompt to MCP.
| Function | Description |
|---|---|
register_tools(registry, container) |
Registers orchestrator_prompt as a prompt |
_handle_orchestrator_prompt(args) |
Reads prompts/orchestrator_prompt.md and returns it as TextContent |
The main module responsible for launching the MCP server and dynamically loading plugins.
sequenceDiagram
participant Main as main.py
participant DI as DIContainer
participant Reg as MCPRegistry
participant EP as entry_points
participant Server as mcp.Server
Main->>DI: container = DIContainer()
Main->>Server: app = Server("agent-tools-mcp-server")
Main->>EP: load_plugins()
loop For each entry_point in "mcp.tools"
EP->>EP: ep.load() → register function
EP->>Reg: register(registry, container)
end
Main->>Server: Start stdio_server
Dynamically sets AGENT_WORKSPACE_CWD within the on_call_tool handler:
- Attempts MCP
list_rootsto get the root URI provided by the client. - If it fails, traverses the OS process tree upwards to locate the CWD of the
agy/antigravityprocess. - If both fail, falls back to
os.getcwd().
| Handler | MCP Method | Description |
|---|---|---|
on_list_tools |
tools/list |
Returns registry.get_tools() |
on_call_tool |
tools/call |
Executes registry.call_tool(name, args) after CWD detection |
on_list_prompts |
prompts/list |
Returns registry.get_prompts() |
on_get_prompt |
prompts/get |
Executes registry.get_prompt(name, args) |
| Dependency | Type | Usage |
|---|---|---|
mcp |
External Lib | MCP protocol typings and server |
hatchling |
Build System | Package building |
importlib.metadata |
Standard Lib | Dynamic entry point loading |
subprocess |
Standard Lib | Process tree exploration |
urllib.parse |
Standard Lib | URI parsing |
logging |
Standard Lib | Logging |
[project.entry-points."mcp.tools"]
core_prompts = "core.prompt_plugin:register_tools"