keycloak-agent 0.29.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.
- keycloak_agent-0.29.0/LICENSE +21 -0
- keycloak_agent-0.29.0/PKG-INFO +206 -0
- keycloak_agent-0.29.0/README.md +178 -0
- keycloak_agent-0.29.0/keycloak_agent/__init__.py +64 -0
- keycloak_agent-0.29.0/keycloak_agent/__main__.py +4 -0
- keycloak_agent-0.29.0/keycloak_agent/agent_server.py +73 -0
- keycloak_agent-0.29.0/keycloak_agent/api/__init__.py +6 -0
- keycloak_agent-0.29.0/keycloak_agent/api/api_client_base.py +250 -0
- keycloak_agent-0.29.0/keycloak_agent/api/api_client_clients.py +50 -0
- keycloak_agent-0.29.0/keycloak_agent/api/api_client_realms.py +21 -0
- keycloak_agent-0.29.0/keycloak_agent/api/api_client_users.py +36 -0
- keycloak_agent-0.29.0/keycloak_agent/api_client.py +12 -0
- keycloak_agent-0.29.0/keycloak_agent/auth.py +30 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/__init__.py +5 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_attack_detection.py +50 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_authentication.py +50 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_clients.py +48 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_components.py +48 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_groups.py +48 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_idps.py +48 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_info.py +114 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_organizations.py +48 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_realms.py +48 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_roles.py +48 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp/mcp_users.py +48 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp_config.json +12 -0
- keycloak_agent-0.29.0/keycloak_agent/mcp_server.py +102 -0
- keycloak_agent-0.29.0/keycloak_agent/models.py +10 -0
- keycloak_agent-0.29.0/keycloak_agent.egg-info/PKG-INFO +206 -0
- keycloak_agent-0.29.0/keycloak_agent.egg-info/SOURCES.txt +41 -0
- keycloak_agent-0.29.0/keycloak_agent.egg-info/dependency_links.txt +1 -0
- keycloak_agent-0.29.0/keycloak_agent.egg-info/entry_points.txt +3 -0
- keycloak_agent-0.29.0/keycloak_agent.egg-info/requires.txt +16 -0
- keycloak_agent-0.29.0/keycloak_agent.egg-info/top_level.txt +7 -0
- keycloak_agent-0.29.0/pyproject.toml +53 -0
- keycloak_agent-0.29.0/scripts/security_sanitizer.py +246 -0
- keycloak_agent-0.29.0/setup.cfg +4 -0
- keycloak_agent-0.29.0/tests/conftest.py +16 -0
- keycloak_agent-0.29.0/tests/test_api_client.py +18 -0
- keycloak_agent-0.29.0/tests/test_concept_parity.py +7 -0
- keycloak_agent-0.29.0/tests/test_init_dynamics.py +8 -0
- keycloak_agent-0.29.0/tests/test_mcp_server.py +26 -0
- keycloak_agent-0.29.0/tests/test_startup.py +9 -0
|
@@ -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,206 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keycloak-agent
|
|
3
|
+
Version: 0.29.0
|
|
4
|
+
Summary: Keycloak Identity MCP Server and Agent 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
|
+
# Keycloak MCP
|
|
30
|
+
|
|
31
|
+
[](https://github.com/genius-agents/keycloak-agent)
|
|
32
|
+
[](pyproject.toml)
|
|
33
|
+
[](LICENSE)
|
|
34
|
+
|
|
35
|
+
Keycloak Identity and Access Management 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
|
+
Keycloak MCP provides a high-performance, model-optimized interface to Keycloak 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 keycloak_agent.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 keycloak_agent.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
|
+
| `KEYCLOAK_URL` | Keycloak Base Admin URL | `http://localhost:8080` | Yes |
|
|
136
|
+
| `KEYCLOAK_USERNAME` | Admin account username | `admin` | Yes |
|
|
137
|
+
| `KEYCLOAK_PASSWORD` | Admin account password | `admin_secure_password` | Yes |
|
|
138
|
+
| `KEYCLOAK_REALM` | KeycloakRealm name | `master` | Yes |
|
|
139
|
+
|
|
140
|
+
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.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## MCP Tools
|
|
145
|
+
|
|
146
|
+
The following declarative FastMCP tools are registered and available to upstream AI agents:
|
|
147
|
+
|
|
148
|
+
| Tool Name | Description | Parameters |
|
|
149
|
+
|-----------|-------------|------------|
|
|
150
|
+
| `get_users` | List realm users | `limit: int = 100` |
|
|
151
|
+
| `create_user` | Create user in realm | `username: str, email: str, enabled: bool = True` |
|
|
152
|
+
| `get_realms` | List realms | None |
|
|
153
|
+
| `get_clients` | List realm clients | None |
|
|
154
|
+
|
|
155
|
+
See [docs/overview.md](docs/overview.md) or [docs/concepts.md](docs/concepts.md) for deeper operational examples.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Architecture
|
|
160
|
+
|
|
161
|
+
This package uses the standardized Agent-Utilities dynamic facade architecture:
|
|
162
|
+
|
|
163
|
+
```mermaid
|
|
164
|
+
graph TD
|
|
165
|
+
User([User Agent]) --> Server[FastMCP Server]
|
|
166
|
+
Server --> Facade[Api Dynamic Facade]
|
|
167
|
+
Facade --> ClientBase[ApiClientBase]
|
|
168
|
+
Facade --> Auth[Credentials Auth Handler]
|
|
169
|
+
ClientBase --> Service([External Service API])
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Deployment
|
|
175
|
+
|
|
176
|
+
### Bare-Metal (Standard pip)
|
|
177
|
+
1. Set up your Python virtual environment (>= 3.10).
|
|
178
|
+
2. Install the package: `pip install .[all]`
|
|
179
|
+
3. Export credentials:
|
|
180
|
+
```bash
|
|
181
|
+
export KEYCLOAK_URL="http://localhost:8080"
|
|
182
|
+
```
|
|
183
|
+
4. Run: `python -m keycloak_agent.mcp_server`
|
|
184
|
+
|
|
185
|
+
### Container (Docker Compose)
|
|
186
|
+
A standard compose structure is provided inside the `docker/` folder. Build and deploy:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
docker compose -f docker/compose.yml up --build -d
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Contributing
|
|
195
|
+
|
|
196
|
+
Please audit all code changes against ecosystem guidelines in [CONTRIBUTING.md](CONTRIBUTING.md) if available, and run:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
pre-commit run --all-files
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for complete details.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Keycloak MCP
|
|
2
|
+
|
|
3
|
+
[](https://github.com/genius-agents/keycloak-agent)
|
|
4
|
+
[](pyproject.toml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Keycloak Identity and Access Management 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
|
+
Keycloak MCP provides a high-performance, model-optimized interface to Keycloak 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 keycloak_agent.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 keycloak_agent.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
|
+
| `KEYCLOAK_URL` | Keycloak Base Admin URL | `http://localhost:8080` | Yes |
|
|
108
|
+
| `KEYCLOAK_USERNAME` | Admin account username | `admin` | Yes |
|
|
109
|
+
| `KEYCLOAK_PASSWORD` | Admin account password | `admin_secure_password` | Yes |
|
|
110
|
+
| `KEYCLOAK_REALM` | KeycloakRealm name | `master` | Yes |
|
|
111
|
+
|
|
112
|
+
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.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## MCP Tools
|
|
117
|
+
|
|
118
|
+
The following declarative FastMCP tools are registered and available to upstream AI agents:
|
|
119
|
+
|
|
120
|
+
| Tool Name | Description | Parameters |
|
|
121
|
+
|-----------|-------------|------------|
|
|
122
|
+
| `get_users` | List realm users | `limit: int = 100` |
|
|
123
|
+
| `create_user` | Create user in realm | `username: str, email: str, enabled: bool = True` |
|
|
124
|
+
| `get_realms` | List realms | None |
|
|
125
|
+
| `get_clients` | List realm clients | None |
|
|
126
|
+
|
|
127
|
+
See [docs/overview.md](docs/overview.md) or [docs/concepts.md](docs/concepts.md) for deeper operational examples.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Architecture
|
|
132
|
+
|
|
133
|
+
This package uses the standardized Agent-Utilities dynamic facade architecture:
|
|
134
|
+
|
|
135
|
+
```mermaid
|
|
136
|
+
graph TD
|
|
137
|
+
User([User Agent]) --> Server[FastMCP Server]
|
|
138
|
+
Server --> Facade[Api Dynamic Facade]
|
|
139
|
+
Facade --> ClientBase[ApiClientBase]
|
|
140
|
+
Facade --> Auth[Credentials Auth Handler]
|
|
141
|
+
ClientBase --> Service([External Service API])
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Deployment
|
|
147
|
+
|
|
148
|
+
### Bare-Metal (Standard pip)
|
|
149
|
+
1. Set up your Python virtual environment (>= 3.10).
|
|
150
|
+
2. Install the package: `pip install .[all]`
|
|
151
|
+
3. Export credentials:
|
|
152
|
+
```bash
|
|
153
|
+
export KEYCLOAK_URL="http://localhost:8080"
|
|
154
|
+
```
|
|
155
|
+
4. Run: `python -m keycloak_agent.mcp_server`
|
|
156
|
+
|
|
157
|
+
### Container (Docker Compose)
|
|
158
|
+
A standard compose structure is provided inside the `docker/` folder. Build and deploy:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
docker compose -f docker/compose.yml up --build -d
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Contributing
|
|
167
|
+
|
|
168
|
+
Please audit all code changes against ecosystem guidelines in [CONTRIBUTING.md](CONTRIBUTING.md) if available, and run:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
pre-commit run --all-files
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
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 = ["keycloak_agent.api_client"]
|
|
11
|
+
OPTIONAL_MODULES = {
|
|
12
|
+
"keycloak_agent.agent_server": "agent",
|
|
13
|
+
"keycloak_agent.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: dict[str, Any] = {}
|
|
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:KEY-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", "Keycloak Agent Agent")
|
|
36
|
+
)
|
|
37
|
+
DEFAULT_AGENT_DESCRIPTION = os.getenv(
|
|
38
|
+
"AGENT_DESCRIPTION",
|
|
39
|
+
meta.get("description", "AI agent for Keycloak Agent 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,6 @@
|
|
|
1
|
+
from keycloak_agent.api.api_client_base import ApiClientBase
|
|
2
|
+
from keycloak_agent.api.api_client_clients import Api as ApiClients
|
|
3
|
+
from keycloak_agent.api.api_client_realms import Api as ApiRealms
|
|
4
|
+
from keycloak_agent.api.api_client_users import Api as ApiUsers
|
|
5
|
+
|
|
6
|
+
__all__ = ["ApiClientBase", "ApiRealms", "ApiUsers", "ApiClients"]
|