caddy-mcp 0.30.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- caddy_mcp-0.30.0/LICENSE +21 -0
- caddy_mcp-0.30.0/PKG-INFO +204 -0
- caddy_mcp-0.30.0/README.md +176 -0
- caddy_mcp-0.30.0/caddy_mcp/__init__.py +64 -0
- caddy_mcp-0.30.0/caddy_mcp/__main__.py +4 -0
- caddy_mcp-0.30.0/caddy_mcp/agent_server.py +73 -0
- caddy_mcp-0.30.0/caddy_mcp/api/__init__.py +4 -0
- caddy_mcp-0.30.0/caddy_mcp/api/api_client_base.py +80 -0
- caddy_mcp-0.30.0/caddy_mcp/api/api_client_config.py +137 -0
- caddy_mcp-0.30.0/caddy_mcp/api_client.py +10 -0
- caddy_mcp-0.30.0/caddy_mcp/auth.py +30 -0
- caddy_mcp-0.30.0/caddy_mcp/mcp/__init__.py +3 -0
- caddy_mcp-0.30.0/caddy_mcp/mcp/mcp_config.py +135 -0
- caddy_mcp-0.30.0/caddy_mcp/mcp_config.json +12 -0
- caddy_mcp-0.30.0/caddy_mcp/mcp_server.py +53 -0
- caddy_mcp-0.30.0/caddy_mcp/models.py +10 -0
- caddy_mcp-0.30.0/caddy_mcp.egg-info/PKG-INFO +204 -0
- caddy_mcp-0.30.0/caddy_mcp.egg-info/SOURCES.txt +29 -0
- caddy_mcp-0.30.0/caddy_mcp.egg-info/dependency_links.txt +1 -0
- caddy_mcp-0.30.0/caddy_mcp.egg-info/entry_points.txt +3 -0
- caddy_mcp-0.30.0/caddy_mcp.egg-info/requires.txt +16 -0
- caddy_mcp-0.30.0/caddy_mcp.egg-info/top_level.txt +7 -0
- caddy_mcp-0.30.0/pyproject.toml +53 -0
- caddy_mcp-0.30.0/scripts/security_sanitizer.py +246 -0
- caddy_mcp-0.30.0/setup.cfg +4 -0
- caddy_mcp-0.30.0/tests/conftest.py +16 -0
- caddy_mcp-0.30.0/tests/test_api_client.py +164 -0
- caddy_mcp-0.30.0/tests/test_concept_parity.py +7 -0
- caddy_mcp-0.30.0/tests/test_init_dynamics.py +8 -0
- caddy_mcp-0.30.0/tests/test_mcp_server.py +79 -0
- caddy_mcp-0.30.0/tests/test_startup.py +9 -0
caddy_mcp-0.30.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Advanced Agentic Coding
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: caddy-mcp
|
|
3
|
+
Version: 0.30.0
|
|
4
|
+
Summary: Caddy Reverse Proxy MCP Server for Agentic AI!
|
|
5
|
+
Author-email: Audel Rouhi <knucklessg1@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: <3.14,>=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: agent-utilities>=0.45.0
|
|
16
|
+
Provides-Extra: mcp
|
|
17
|
+
Requires-Dist: agent-utilities[mcp]>=0.45.0; extra == "mcp"
|
|
18
|
+
Provides-Extra: agent
|
|
19
|
+
Requires-Dist: agent-utilities[agent,logfire]>=0.45.0; extra == "agent"
|
|
20
|
+
Provides-Extra: all
|
|
21
|
+
Requires-Dist: agent-utilities[agent,logfire,mcp]>=0.45.0; extra == "all"
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: pytest-xdist>=3.6.0; extra == "test"
|
|
24
|
+
Requires-Dist: pytest; extra == "test"
|
|
25
|
+
Requires-Dist: pytest-asyncio; extra == "test"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# Caddy MCP
|
|
30
|
+
|
|
31
|
+
[](https://github.com/genius-agents/caddy-mcp)
|
|
32
|
+
[](pyproject.toml)
|
|
33
|
+
[](LICENSE)
|
|
34
|
+
|
|
35
|
+
Caddy Reverse Proxy administrative and configuration orchestrator. Built with the highest architectural standards, incorporating dynamic facades, custom API routing, and FastMCP tool decoration.
|
|
36
|
+
|
|
37
|
+
## Table of Contents
|
|
38
|
+
- [Overview](#overview)
|
|
39
|
+
- [Features](#features)
|
|
40
|
+
- [Installation](#installation)
|
|
41
|
+
- [Usage](#usage)
|
|
42
|
+
- [Configuration](#configuration)
|
|
43
|
+
- [MCP Tools](#mcp-tools)
|
|
44
|
+
- [Architecture](#architecture)
|
|
45
|
+
- [Deployment](#deployment)
|
|
46
|
+
- [Contributing](#contributing)
|
|
47
|
+
- [License](#license)
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Overview
|
|
52
|
+
|
|
53
|
+
Caddy MCP provides a high-performance, model-optimized interface to Caddy capabilities. It isolates the model from underlying API transport complexity, ensuring safe, idempotent, and highly traceable system interactions.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Features
|
|
58
|
+
|
|
59
|
+
- **Dynamic Facade Orchestration**: Integrates multi-inheritance clients cleanly under a single facade.
|
|
60
|
+
- **Battle-Tested Resilience**: Out-of-the-box credential authentication, connection polling, and request retry strategies.
|
|
61
|
+
- **FastMCP Declarative Tools**: Fast, native schema registration with full inline validation.
|
|
62
|
+
- **Complete Test Intent Diversity**: Deep, automated unit, integration, and mock tests ensuring high code coverage.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## ⚙️ Dynamic Tool Selection & Visibility
|
|
67
|
+
|
|
68
|
+
This MCP server supports dynamic toolset selection and visibility filtering at runtime. This allows you to restrict the set of exposed tools in order to prevent blowing up the LLM's context window.
|
|
69
|
+
|
|
70
|
+
You can configure tool filtering via multiple input channels:
|
|
71
|
+
|
|
72
|
+
- **CLI Arguments:** Pass `--tools` or `--toolsets` (or their disabled counterparts `--disabled-tools` and `--disabled-toolsets`) during startup.
|
|
73
|
+
- **Environment Variables:** Define standard environment variables:
|
|
74
|
+
- `MCP_ENABLED_TOOLS` / `MCP_DISABLED_TOOLS`
|
|
75
|
+
- `MCP_ENABLED_TAGS` / `MCP_DISABLED_TAGS`
|
|
76
|
+
- **HTTP SSE Request Headers:** Pass custom headers during transport initialization:
|
|
77
|
+
- `x-mcp-enabled-tools` / `x-mcp-disabled-tools`
|
|
78
|
+
- `x-mcp-enabled-tags` / `x-mcp-disabled-tags`
|
|
79
|
+
- **HTTP SSE Request Query Parameters:** Append query parameters directly to your transport connection URL:
|
|
80
|
+
- `?tools=tool1,tool2`
|
|
81
|
+
- `?tags=tag1`
|
|
82
|
+
|
|
83
|
+
When query strings or parameters are supplied, an LLM-free **Knowledge Graph resolution layer** (using `DynamicToolOrchestrator`) matches query intents against known tool tags, names, or descriptions, with safe fallback and automated 24-hour background cache refreshing.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
Install in editable mode directly inside your active workspace:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install -e .[all]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Or via the `uv` tool:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
uv pip install -e .
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Usage
|
|
105
|
+
|
|
106
|
+
You can launch the FastMCP server in stdio mode via Python module execution:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
import asyncio
|
|
110
|
+
from caddy_mcp.mcp_server import get_mcp_instance
|
|
111
|
+
|
|
112
|
+
async def main():
|
|
113
|
+
mcp = get_mcp_instance()
|
|
114
|
+
# Execute stdio loop or launch server
|
|
115
|
+
print("MCP Server ready.")
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
asyncio.run(main())
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
For direct shell launch, execute:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
python -m caddy_mcp.mcp_server
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Configuration
|
|
130
|
+
|
|
131
|
+
The package is fully configurable via the environment variables listed below:
|
|
132
|
+
|
|
133
|
+
| Variable | Description | Default | Required |
|
|
134
|
+
|----------|-------------|---------|----------|
|
|
135
|
+
| `CADDY_URL` | Caddy Administration API URL endpoint | `http://localhost:2019` | Yes |
|
|
136
|
+
| `CADDY_TOKEN` | Optional bearer token if API is secured | `your_secure_bearer_token` | Yes |
|
|
137
|
+
|
|
138
|
+
A local template is supplied inside [.env.example](.env.example). Copy this file as `.env` and fill out your specific service endpoint parameters before starting execution.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## MCP Tools
|
|
143
|
+
|
|
144
|
+
The following declarative FastMCP tools are registered and available to upstream AI agents:
|
|
145
|
+
|
|
146
|
+
| Tool Name | Description | Parameters |
|
|
147
|
+
|-----------|-------------|------------|
|
|
148
|
+
| `get_config` | Retrieve current Caddy configuration path | `path: str` |
|
|
149
|
+
| `set_config` | Update Caddy configuration path with new json value | `path: str, data: dict` |
|
|
150
|
+
| `delete_config` | Delete Caddy configuration path | `path: str` |
|
|
151
|
+
| `load_config` | Load Caddy configuration string | `config_str: str, type: str` |
|
|
152
|
+
|
|
153
|
+
See [docs/overview.md](docs/overview.md) or [docs/concepts.md](docs/concepts.md) for deeper operational examples.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Architecture
|
|
158
|
+
|
|
159
|
+
This package uses the standardized Agent-Utilities dynamic facade architecture:
|
|
160
|
+
|
|
161
|
+
```mermaid
|
|
162
|
+
graph TD
|
|
163
|
+
User([User Agent]) --> Server[FastMCP Server]
|
|
164
|
+
Server --> Facade[Api Dynamic Facade]
|
|
165
|
+
Facade --> ClientBase[ApiClientBase]
|
|
166
|
+
Facade --> Auth[Credentials Auth Handler]
|
|
167
|
+
ClientBase --> Service([External Service API])
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Deployment
|
|
173
|
+
|
|
174
|
+
### Bare-Metal (Standard pip)
|
|
175
|
+
1. Set up your Python virtual environment (>= 3.10).
|
|
176
|
+
2. Install the package: `pip install .[all]`
|
|
177
|
+
3. Export credentials:
|
|
178
|
+
```bash
|
|
179
|
+
export CADDY_URL="http://localhost:2019"
|
|
180
|
+
```
|
|
181
|
+
4. Run: `python -m caddy_mcp.mcp_server`
|
|
182
|
+
|
|
183
|
+
### Container (Docker Compose)
|
|
184
|
+
A standard compose structure is provided inside the `docker/` folder. Build and deploy:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
docker compose -f docker/compose.yml up --build -d
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Contributing
|
|
193
|
+
|
|
194
|
+
Please audit all code changes against ecosystem guidelines in [CONTRIBUTING.md](CONTRIBUTING.md) if available, and run:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
pre-commit run --all-files
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for complete details.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Caddy MCP
|
|
2
|
+
|
|
3
|
+
[](https://github.com/genius-agents/caddy-mcp)
|
|
4
|
+
[](pyproject.toml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Caddy Reverse Proxy administrative and configuration orchestrator. Built with the highest architectural standards, incorporating dynamic facades, custom API routing, and FastMCP tool decoration.
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [Overview](#overview)
|
|
11
|
+
- [Features](#features)
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Usage](#usage)
|
|
14
|
+
- [Configuration](#configuration)
|
|
15
|
+
- [MCP Tools](#mcp-tools)
|
|
16
|
+
- [Architecture](#architecture)
|
|
17
|
+
- [Deployment](#deployment)
|
|
18
|
+
- [Contributing](#contributing)
|
|
19
|
+
- [License](#license)
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
Caddy MCP provides a high-performance, model-optimized interface to Caddy capabilities. It isolates the model from underlying API transport complexity, ensuring safe, idempotent, and highly traceable system interactions.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- **Dynamic Facade Orchestration**: Integrates multi-inheritance clients cleanly under a single facade.
|
|
32
|
+
- **Battle-Tested Resilience**: Out-of-the-box credential authentication, connection polling, and request retry strategies.
|
|
33
|
+
- **FastMCP Declarative Tools**: Fast, native schema registration with full inline validation.
|
|
34
|
+
- **Complete Test Intent Diversity**: Deep, automated unit, integration, and mock tests ensuring high code coverage.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## ⚙️ Dynamic Tool Selection & Visibility
|
|
39
|
+
|
|
40
|
+
This MCP server supports dynamic toolset selection and visibility filtering at runtime. This allows you to restrict the set of exposed tools in order to prevent blowing up the LLM's context window.
|
|
41
|
+
|
|
42
|
+
You can configure tool filtering via multiple input channels:
|
|
43
|
+
|
|
44
|
+
- **CLI Arguments:** Pass `--tools` or `--toolsets` (or their disabled counterparts `--disabled-tools` and `--disabled-toolsets`) during startup.
|
|
45
|
+
- **Environment Variables:** Define standard environment variables:
|
|
46
|
+
- `MCP_ENABLED_TOOLS` / `MCP_DISABLED_TOOLS`
|
|
47
|
+
- `MCP_ENABLED_TAGS` / `MCP_DISABLED_TAGS`
|
|
48
|
+
- **HTTP SSE Request Headers:** Pass custom headers during transport initialization:
|
|
49
|
+
- `x-mcp-enabled-tools` / `x-mcp-disabled-tools`
|
|
50
|
+
- `x-mcp-enabled-tags` / `x-mcp-disabled-tags`
|
|
51
|
+
- **HTTP SSE Request Query Parameters:** Append query parameters directly to your transport connection URL:
|
|
52
|
+
- `?tools=tool1,tool2`
|
|
53
|
+
- `?tags=tag1`
|
|
54
|
+
|
|
55
|
+
When query strings or parameters are supplied, an LLM-free **Knowledge Graph resolution layer** (using `DynamicToolOrchestrator`) matches query intents against known tool tags, names, or descriptions, with safe fallback and automated 24-hour background cache refreshing.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
Install in editable mode directly inside your active workspace:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install -e .[all]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Or via the `uv` tool:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
uv pip install -e .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
You can launch the FastMCP server in stdio mode via Python module execution:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import asyncio
|
|
82
|
+
from caddy_mcp.mcp_server import get_mcp_instance
|
|
83
|
+
|
|
84
|
+
async def main():
|
|
85
|
+
mcp = get_mcp_instance()
|
|
86
|
+
# Execute stdio loop or launch server
|
|
87
|
+
print("MCP Server ready.")
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
asyncio.run(main())
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
For direct shell launch, execute:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
python -m caddy_mcp.mcp_server
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Configuration
|
|
102
|
+
|
|
103
|
+
The package is fully configurable via the environment variables listed below:
|
|
104
|
+
|
|
105
|
+
| Variable | Description | Default | Required |
|
|
106
|
+
|----------|-------------|---------|----------|
|
|
107
|
+
| `CADDY_URL` | Caddy Administration API URL endpoint | `http://localhost:2019` | Yes |
|
|
108
|
+
| `CADDY_TOKEN` | Optional bearer token if API is secured | `your_secure_bearer_token` | Yes |
|
|
109
|
+
|
|
110
|
+
A local template is supplied inside [.env.example](.env.example). Copy this file as `.env` and fill out your specific service endpoint parameters before starting execution.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## MCP Tools
|
|
115
|
+
|
|
116
|
+
The following declarative FastMCP tools are registered and available to upstream AI agents:
|
|
117
|
+
|
|
118
|
+
| Tool Name | Description | Parameters |
|
|
119
|
+
|-----------|-------------|------------|
|
|
120
|
+
| `get_config` | Retrieve current Caddy configuration path | `path: str` |
|
|
121
|
+
| `set_config` | Update Caddy configuration path with new json value | `path: str, data: dict` |
|
|
122
|
+
| `delete_config` | Delete Caddy configuration path | `path: str` |
|
|
123
|
+
| `load_config` | Load Caddy configuration string | `config_str: str, type: str` |
|
|
124
|
+
|
|
125
|
+
See [docs/overview.md](docs/overview.md) or [docs/concepts.md](docs/concepts.md) for deeper operational examples.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Architecture
|
|
130
|
+
|
|
131
|
+
This package uses the standardized Agent-Utilities dynamic facade architecture:
|
|
132
|
+
|
|
133
|
+
```mermaid
|
|
134
|
+
graph TD
|
|
135
|
+
User([User Agent]) --> Server[FastMCP Server]
|
|
136
|
+
Server --> Facade[Api Dynamic Facade]
|
|
137
|
+
Facade --> ClientBase[ApiClientBase]
|
|
138
|
+
Facade --> Auth[Credentials Auth Handler]
|
|
139
|
+
ClientBase --> Service([External Service API])
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Deployment
|
|
145
|
+
|
|
146
|
+
### Bare-Metal (Standard pip)
|
|
147
|
+
1. Set up your Python virtual environment (>= 3.10).
|
|
148
|
+
2. Install the package: `pip install .[all]`
|
|
149
|
+
3. Export credentials:
|
|
150
|
+
```bash
|
|
151
|
+
export CADDY_URL="http://localhost:2019"
|
|
152
|
+
```
|
|
153
|
+
4. Run: `python -m caddy_mcp.mcp_server`
|
|
154
|
+
|
|
155
|
+
### Container (Docker Compose)
|
|
156
|
+
A standard compose structure is provided inside the `docker/` folder. Build and deploy:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
docker compose -f docker/compose.yml up --build -d
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
Please audit all code changes against ecosystem guidelines in [CONTRIBUTING.md](CONTRIBUTING.md) if available, and run:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
pre-commit run --all-files
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for complete details.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""CONCEPT:ECO-4.0 Unified ecosystem initialization dynamic check."""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import inspect
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
__version__ = "0.15.0"
|
|
8
|
+
__all__: list[str] = []
|
|
9
|
+
|
|
10
|
+
CORE_MODULES = ["caddy_mcp.api_client"]
|
|
11
|
+
OPTIONAL_MODULES = {
|
|
12
|
+
"caddy_mcp.agent_server": "agent",
|
|
13
|
+
"caddy_mcp.mcp_server": "mcp",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _expose_members(module):
|
|
18
|
+
for name, obj in inspect.getmembers(module):
|
|
19
|
+
if (inspect.isclass(obj) or inspect.isfunction(obj)) and not name.startswith(
|
|
20
|
+
"_"
|
|
21
|
+
):
|
|
22
|
+
globals()[name] = obj
|
|
23
|
+
if name not in __all__:
|
|
24
|
+
__all__.append(name)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
for module_name in CORE_MODULES:
|
|
28
|
+
module = importlib.import_module(module_name)
|
|
29
|
+
_expose_members(module)
|
|
30
|
+
|
|
31
|
+
_loaded_optional_modules = {}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _import_module_safely(module_name: str):
|
|
35
|
+
try:
|
|
36
|
+
return importlib.import_module(module_name)
|
|
37
|
+
except ImportError:
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def __getattr__(name: str) -> Any:
|
|
42
|
+
if name == "_MCP_AVAILABLE":
|
|
43
|
+
mcp_key = next((k for k in OPTIONAL_MODULES if "mcp_server" in k), None)
|
|
44
|
+
return _import_module_safely(mcp_key) is not None if mcp_key else False
|
|
45
|
+
if name == "_AGENT_AVAILABLE":
|
|
46
|
+
agent_key = next((k for k in OPTIONAL_MODULES if "agent_server" in k), None)
|
|
47
|
+
return _import_module_safely(agent_key) is not None if agent_key else False
|
|
48
|
+
|
|
49
|
+
for module_name in OPTIONAL_MODULES:
|
|
50
|
+
if module_name not in _loaded_optional_modules:
|
|
51
|
+
module = _import_module_safely(module_name)
|
|
52
|
+
if module is not None:
|
|
53
|
+
_loaded_optional_modules[module_name] = module
|
|
54
|
+
_expose_members(module)
|
|
55
|
+
|
|
56
|
+
module = _loaded_optional_modules.get(module_name)
|
|
57
|
+
if module is not None and hasattr(module, name):
|
|
58
|
+
return getattr(module, name)
|
|
59
|
+
|
|
60
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def __dir__() -> list[str]:
|
|
64
|
+
return sorted(list(globals().keys()) + __all__)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import warnings
|
|
5
|
+
|
|
6
|
+
__version__ = "0.15.0"
|
|
7
|
+
|
|
8
|
+
logging.basicConfig(
|
|
9
|
+
level=logging.INFO,
|
|
10
|
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
11
|
+
)
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
DEFAULT_AGENT_NAME = None
|
|
15
|
+
DEFAULT_AGENT_DESCRIPTION = None
|
|
16
|
+
DEFAULT_AGENT_SYSTEM_PROMPT = None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def agent_server():
|
|
20
|
+
"""Start graph-based Pydantic AI agent server.
|
|
21
|
+
CONCEPT:CADDY-007
|
|
22
|
+
"""
|
|
23
|
+
from agent_utilities import (
|
|
24
|
+
build_system_prompt_from_workspace,
|
|
25
|
+
create_agent_parser,
|
|
26
|
+
create_agent_server,
|
|
27
|
+
initialize_workspace,
|
|
28
|
+
load_identity,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
global DEFAULT_AGENT_NAME, DEFAULT_AGENT_DESCRIPTION, DEFAULT_AGENT_SYSTEM_PROMPT
|
|
32
|
+
initialize_workspace()
|
|
33
|
+
meta = load_identity()
|
|
34
|
+
DEFAULT_AGENT_NAME = os.getenv(
|
|
35
|
+
"DEFAULT_AGENT_NAME", meta.get("name", "Caddy MCP Agent")
|
|
36
|
+
)
|
|
37
|
+
DEFAULT_AGENT_DESCRIPTION = os.getenv(
|
|
38
|
+
"AGENT_DESCRIPTION",
|
|
39
|
+
meta.get("description", "AI agent for Caddy MCP operations."),
|
|
40
|
+
)
|
|
41
|
+
DEFAULT_AGENT_SYSTEM_PROMPT = os.getenv(
|
|
42
|
+
"AGENT_SYSTEM_PROMPT",
|
|
43
|
+
meta.get("content") or build_system_prompt_from_workspace(),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
warnings.filterwarnings("ignore", message=".*urllib3.*")
|
|
47
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning, module="fastmcp")
|
|
48
|
+
|
|
49
|
+
print(f"{DEFAULT_AGENT_NAME} v{__version__}", file=sys.stderr)
|
|
50
|
+
parser = create_agent_parser()
|
|
51
|
+
args = parser.parse_args()
|
|
52
|
+
|
|
53
|
+
create_agent_server(
|
|
54
|
+
mcp_url=args.mcp_url,
|
|
55
|
+
mcp_config=args.mcp_config or "mcp_config.json",
|
|
56
|
+
host=args.host,
|
|
57
|
+
port=args.port,
|
|
58
|
+
provider=args.provider,
|
|
59
|
+
model_id=args.model_id,
|
|
60
|
+
router_model=args.model_id,
|
|
61
|
+
agent_model=args.model_id,
|
|
62
|
+
base_url=args.base_url,
|
|
63
|
+
api_key=args.api_key,
|
|
64
|
+
custom_skills_directory=args.custom_skills_directory,
|
|
65
|
+
enable_web_ui=args.web,
|
|
66
|
+
enable_otel=args.otel,
|
|
67
|
+
otel_endpoint=args.otel_endpoint,
|
|
68
|
+
otel_headers=args.otel_headers,
|
|
69
|
+
otel_public_key=args.otel_public_key,
|
|
70
|
+
otel_secret_key=args.otel_secret_key,
|
|
71
|
+
otel_protocol=args.otel_protocol,
|
|
72
|
+
debug=args.debug,
|
|
73
|
+
)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from urllib.parse import urljoin
|
|
3
|
+
|
|
4
|
+
import requests
|
|
5
|
+
import urllib3
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ApiClientBase:
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
base_url: str,
|
|
12
|
+
token: str | None = None,
|
|
13
|
+
username: str | None = None,
|
|
14
|
+
password: str | None = None,
|
|
15
|
+
verify: bool = True,
|
|
16
|
+
):
|
|
17
|
+
self.base_url = base_url
|
|
18
|
+
self.token = token
|
|
19
|
+
self.username = username
|
|
20
|
+
self.password = password
|
|
21
|
+
self.last_etag: str | None = None
|
|
22
|
+
self._session = requests.Session()
|
|
23
|
+
self._session.verify = verify
|
|
24
|
+
|
|
25
|
+
if not verify:
|
|
26
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
27
|
+
|
|
28
|
+
if token:
|
|
29
|
+
self._session.headers.update({"Authorization": f"Bearer {token}"})
|
|
30
|
+
elif username and password:
|
|
31
|
+
self._session.auth = (username, password)
|
|
32
|
+
|
|
33
|
+
def request(
|
|
34
|
+
self,
|
|
35
|
+
method: str,
|
|
36
|
+
endpoint: str,
|
|
37
|
+
params: dict[str, Any] | None = None,
|
|
38
|
+
data: Any | None = None,
|
|
39
|
+
headers: dict[str, str] | None = None,
|
|
40
|
+
) -> Any:
|
|
41
|
+
if endpoint.startswith("http"):
|
|
42
|
+
url = endpoint
|
|
43
|
+
else:
|
|
44
|
+
url = urljoin(self.base_url, endpoint)
|
|
45
|
+
|
|
46
|
+
req_headers = {"Content-Type": "application/json"}
|
|
47
|
+
if headers:
|
|
48
|
+
req_headers.update(headers)
|
|
49
|
+
|
|
50
|
+
content_type = req_headers.get("Content-Type", "")
|
|
51
|
+
kwargs: dict[str, Any] = {}
|
|
52
|
+
|
|
53
|
+
if "application/json" in content_type:
|
|
54
|
+
if isinstance(data, str):
|
|
55
|
+
kwargs["data"] = data
|
|
56
|
+
else:
|
|
57
|
+
kwargs["json"] = data
|
|
58
|
+
else:
|
|
59
|
+
kwargs["data"] = data
|
|
60
|
+
|
|
61
|
+
response = self._session.request(
|
|
62
|
+
method=method,
|
|
63
|
+
url=url,
|
|
64
|
+
headers=req_headers,
|
|
65
|
+
params=params,
|
|
66
|
+
**kwargs,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
self.last_etag = response.headers.get("ETag")
|
|
70
|
+
|
|
71
|
+
if response.status_code >= 400:
|
|
72
|
+
raise Exception(f"API error: {response.status_code} - {response.text}")
|
|
73
|
+
|
|
74
|
+
if response.status_code == 204 or not response.text.strip():
|
|
75
|
+
return {"status": "success"}
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
return response.json()
|
|
79
|
+
except Exception:
|
|
80
|
+
return {"status": "success", "text": response.text}
|