traia-iatp 0.1.29__py3-none-any.whl
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.
Potentially problematic release.
This version of traia-iatp might be problematic. Click here for more details.
- traia_iatp/README.md +368 -0
- traia_iatp/__init__.py +54 -0
- traia_iatp/cli/__init__.py +5 -0
- traia_iatp/cli/main.py +483 -0
- traia_iatp/client/__init__.py +10 -0
- traia_iatp/client/a2a_client.py +274 -0
- traia_iatp/client/crewai_a2a_tools.py +335 -0
- traia_iatp/client/d402_a2a_client.py +293 -0
- traia_iatp/client/grpc_a2a_tools.py +349 -0
- traia_iatp/client/root_path_a2a_client.py +1 -0
- traia_iatp/contracts/__init__.py +12 -0
- traia_iatp/contracts/iatp_contracts_config.py +263 -0
- traia_iatp/contracts/wallet_creator.py +255 -0
- traia_iatp/core/__init__.py +43 -0
- traia_iatp/core/models.py +172 -0
- traia_iatp/d402/__init__.py +55 -0
- traia_iatp/d402/chains.py +102 -0
- traia_iatp/d402/client.py +150 -0
- traia_iatp/d402/clients/__init__.py +7 -0
- traia_iatp/d402/clients/base.py +218 -0
- traia_iatp/d402/clients/httpx.py +219 -0
- traia_iatp/d402/common.py +114 -0
- traia_iatp/d402/encoding.py +28 -0
- traia_iatp/d402/examples/client_example.py +197 -0
- traia_iatp/d402/examples/server_example.py +171 -0
- traia_iatp/d402/facilitator.py +453 -0
- traia_iatp/d402/fastapi_middleware/__init__.py +6 -0
- traia_iatp/d402/fastapi_middleware/middleware.py +225 -0
- traia_iatp/d402/fastmcp_middleware.py +147 -0
- traia_iatp/d402/mcp_middleware.py +434 -0
- traia_iatp/d402/middleware.py +193 -0
- traia_iatp/d402/models.py +116 -0
- traia_iatp/d402/networks.py +98 -0
- traia_iatp/d402/path.py +43 -0
- traia_iatp/d402/payment_introspection.py +104 -0
- traia_iatp/d402/payment_signing.py +178 -0
- traia_iatp/d402/paywall.py +119 -0
- traia_iatp/d402/starlette_middleware.py +326 -0
- traia_iatp/d402/template.py +1 -0
- traia_iatp/d402/types.py +300 -0
- traia_iatp/mcp/__init__.py +18 -0
- traia_iatp/mcp/client.py +201 -0
- traia_iatp/mcp/d402_mcp_tool_adapter.py +361 -0
- traia_iatp/mcp/mcp_agent_template.py +481 -0
- traia_iatp/mcp/templates/Dockerfile.j2 +80 -0
- traia_iatp/mcp/templates/README.md.j2 +310 -0
- traia_iatp/mcp/templates/cursor-rules.md.j2 +520 -0
- traia_iatp/mcp/templates/deployment_params.json.j2 +20 -0
- traia_iatp/mcp/templates/docker-compose.yml.j2 +32 -0
- traia_iatp/mcp/templates/dockerignore.j2 +47 -0
- traia_iatp/mcp/templates/env.example.j2 +57 -0
- traia_iatp/mcp/templates/gitignore.j2 +77 -0
- traia_iatp/mcp/templates/mcp_health_check.py.j2 +150 -0
- traia_iatp/mcp/templates/pyproject.toml.j2 +32 -0
- traia_iatp/mcp/templates/pyrightconfig.json.j2 +22 -0
- traia_iatp/mcp/templates/run_local_docker.sh.j2 +390 -0
- traia_iatp/mcp/templates/server.py.j2 +175 -0
- traia_iatp/mcp/traia_mcp_adapter.py +543 -0
- traia_iatp/preview_diagrams.html +181 -0
- traia_iatp/registry/__init__.py +26 -0
- traia_iatp/registry/atlas_search_indexes.json +280 -0
- traia_iatp/registry/embeddings.py +298 -0
- traia_iatp/registry/iatp_search_api.py +846 -0
- traia_iatp/registry/mongodb_registry.py +771 -0
- traia_iatp/registry/readmes/ATLAS_SEARCH_INDEXES.md +252 -0
- traia_iatp/registry/readmes/ATLAS_SEARCH_SETUP.md +134 -0
- traia_iatp/registry/readmes/AUTHENTICATION_UPDATE.md +124 -0
- traia_iatp/registry/readmes/EMBEDDINGS_SETUP.md +172 -0
- traia_iatp/registry/readmes/IATP_SEARCH_API_GUIDE.md +257 -0
- traia_iatp/registry/readmes/MONGODB_X509_AUTH.md +208 -0
- traia_iatp/registry/readmes/README.md +251 -0
- traia_iatp/registry/readmes/REFACTORING_SUMMARY.md +191 -0
- traia_iatp/scripts/__init__.py +2 -0
- traia_iatp/scripts/create_wallet.py +244 -0
- traia_iatp/server/__init__.py +15 -0
- traia_iatp/server/a2a_server.py +219 -0
- traia_iatp/server/example_template_usage.py +72 -0
- traia_iatp/server/iatp_server_agent_generator.py +237 -0
- traia_iatp/server/iatp_server_template_generator.py +235 -0
- traia_iatp/server/templates/.dockerignore.j2 +48 -0
- traia_iatp/server/templates/Dockerfile.j2 +49 -0
- traia_iatp/server/templates/README.md +137 -0
- traia_iatp/server/templates/README.md.j2 +425 -0
- traia_iatp/server/templates/__init__.py +1 -0
- traia_iatp/server/templates/__main__.py.j2 +565 -0
- traia_iatp/server/templates/agent.py.j2 +94 -0
- traia_iatp/server/templates/agent_config.json.j2 +22 -0
- traia_iatp/server/templates/agent_executor.py.j2 +279 -0
- traia_iatp/server/templates/docker-compose.yml.j2 +23 -0
- traia_iatp/server/templates/env.example.j2 +84 -0
- traia_iatp/server/templates/gitignore.j2 +78 -0
- traia_iatp/server/templates/grpc_server.py.j2 +218 -0
- traia_iatp/server/templates/pyproject.toml.j2 +78 -0
- traia_iatp/server/templates/run_local_docker.sh.j2 +103 -0
- traia_iatp/server/templates/server.py.j2 +243 -0
- traia_iatp/special_agencies/__init__.py +4 -0
- traia_iatp/special_agencies/registry_search_agency.py +392 -0
- traia_iatp/utils/__init__.py +10 -0
- traia_iatp/utils/docker_utils.py +251 -0
- traia_iatp/utils/general.py +64 -0
- traia_iatp/utils/iatp_utils.py +126 -0
- traia_iatp-0.1.29.dist-info/METADATA +423 -0
- traia_iatp-0.1.29.dist-info/RECORD +107 -0
- traia_iatp-0.1.29.dist-info/WHEEL +5 -0
- traia_iatp-0.1.29.dist-info/entry_points.txt +2 -0
- traia_iatp-0.1.29.dist-info/licenses/LICENSE +21 -0
- traia_iatp-0.1.29.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# IATP Search API Guide
|
|
2
|
+
|
|
3
|
+
The `iatp_search_api.py` module provides a high-level API for searching and retrieving information about utility agents and MCP servers from the IATP registry.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This API provides read-only access to the MongoDB registry without requiring direct database dependencies. It automatically handles authentication using X.509 certificates or username/password.
|
|
8
|
+
|
|
9
|
+
## Authentication
|
|
10
|
+
|
|
11
|
+
The API automatically detects and uses the appropriate authentication method:
|
|
12
|
+
|
|
13
|
+
1. **X.509 Certificate** (if `MONGODB_X509_CERT_FILE` is set)
|
|
14
|
+
2. **Username/Password** (if `MONGODB_USER` and `MONGODB_PASSWORD` are set)
|
|
15
|
+
3. **Connection String** (if `MONGODB_CONNECTION_STRING` is set)
|
|
16
|
+
|
|
17
|
+
## Available Functions
|
|
18
|
+
|
|
19
|
+
### Utility Agent Functions
|
|
20
|
+
|
|
21
|
+
#### `find_utility_agent(name=None, capability=None, tag=None, query=None)`
|
|
22
|
+
Find a single utility agent by specific criteria.
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from traia_iatp.registry.iatp_search_api import find_utility_agent
|
|
26
|
+
|
|
27
|
+
# Find by exact name
|
|
28
|
+
agent = find_utility_agent(name="hyperliquid-mcp-traia-utility-agency")
|
|
29
|
+
|
|
30
|
+
# Find by capability
|
|
31
|
+
agent = find_utility_agent(capability="market_info")
|
|
32
|
+
|
|
33
|
+
# Find by tag
|
|
34
|
+
agent = find_utility_agent(tag="trading")
|
|
35
|
+
|
|
36
|
+
# Find by text query
|
|
37
|
+
agent = find_utility_agent(query="trading bot")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### `list_utility_agents(limit=10, tags=None, capabilities=None, active_only=True)`
|
|
41
|
+
List utility agents with optional filters.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from traia_iatp.registry.iatp_search_api import list_utility_agents
|
|
45
|
+
|
|
46
|
+
# List all active agents
|
|
47
|
+
agents = list_utility_agents(limit=20)
|
|
48
|
+
|
|
49
|
+
# Filter by tags
|
|
50
|
+
agents = list_utility_agents(tags=["trading", "defi"])
|
|
51
|
+
|
|
52
|
+
# Filter by capabilities
|
|
53
|
+
agents = list_utility_agents(capabilities=["market_info", "trading_orders"])
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### `search_utility_agents(query, limit=10, active_only=True, embedding_fields=None)`
|
|
57
|
+
Search utility agents using vector search.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from traia_iatp.registry.iatp_search_api import search_utility_agents
|
|
61
|
+
|
|
62
|
+
# Search using default search_text embedding (recommended for best performance)
|
|
63
|
+
agents = await search_utility_agents("trading hyperliquid", limit=5)
|
|
64
|
+
|
|
65
|
+
# Search using specific embedding fields
|
|
66
|
+
agents = await search_utility_agents(
|
|
67
|
+
"trading hyperliquid",
|
|
68
|
+
limit=5,
|
|
69
|
+
embedding_fields=["description", "tags"]
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Search across all embedding fields (slower but more comprehensive)
|
|
73
|
+
agents = await search_utility_agents(
|
|
74
|
+
"market data",
|
|
75
|
+
limit=5,
|
|
76
|
+
embedding_fields=["description", "tags", "capabilities", "agent_card"]
|
|
77
|
+
)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### MCP Server Functions
|
|
81
|
+
|
|
82
|
+
#### `find_mcp_server(name=None, capability=None, tag=None, query=None)`
|
|
83
|
+
Find a single MCP server by specific criteria.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from traia_iatp.registry.iatp_search_api import find_mcp_server
|
|
87
|
+
|
|
88
|
+
# Find by exact name
|
|
89
|
+
server = find_mcp_server(name="hyperliquid-mcp")
|
|
90
|
+
|
|
91
|
+
# Find by capability
|
|
92
|
+
server = find_mcp_server(capability="trading_orders")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### `list_mcp_servers(limit=10, tags=None, capabilities=None)`
|
|
96
|
+
List MCP servers with optional filters.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from traia_iatp.registry.iatp_search_api import list_mcp_servers
|
|
100
|
+
|
|
101
|
+
# List all servers
|
|
102
|
+
servers = list_mcp_servers(limit=10)
|
|
103
|
+
|
|
104
|
+
# Filter by capabilities
|
|
105
|
+
servers = list_mcp_servers(capabilities=["market_info"])
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### `search_mcp_servers(query, limit=10, embedding_fields=None)`
|
|
109
|
+
Search MCP servers using vector search.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from traia_iatp.registry.iatp_search_api import search_mcp_servers
|
|
113
|
+
|
|
114
|
+
# Search using default embedding fields (description and capabilities)
|
|
115
|
+
servers = await search_mcp_servers("trading", limit=5)
|
|
116
|
+
|
|
117
|
+
# Search using only description embedding
|
|
118
|
+
servers = await search_mcp_servers(
|
|
119
|
+
"trading",
|
|
120
|
+
limit=5,
|
|
121
|
+
embedding_fields=["description"]
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### `get_mcp_server(name)`
|
|
126
|
+
Get detailed MCP server information by name (returns raw MongoDB document).
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from traia_iatp.registry.iatp_search_api import get_mcp_server
|
|
130
|
+
|
|
131
|
+
# Get full server details
|
|
132
|
+
server_doc = get_mcp_server("hyperliquid-mcp")
|
|
133
|
+
if server_doc:
|
|
134
|
+
print(f"Server ID: {server_doc['_id']}")
|
|
135
|
+
print(f"Capabilities: {server_doc['capabilities']}")
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Data Models
|
|
139
|
+
|
|
140
|
+
### UtilityAgentInfo
|
|
141
|
+
```python
|
|
142
|
+
@dataclass
|
|
143
|
+
class UtilityAgentInfo:
|
|
144
|
+
agent_id: str
|
|
145
|
+
name: str
|
|
146
|
+
description: str
|
|
147
|
+
base_url: str
|
|
148
|
+
capabilities: List[str]
|
|
149
|
+
tags: List[str]
|
|
150
|
+
is_active: bool
|
|
151
|
+
metadata: Dict[str, Any]
|
|
152
|
+
skills: List[Dict[str, Any]]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### MCPServerInfo
|
|
156
|
+
```python
|
|
157
|
+
@dataclass
|
|
158
|
+
class MCPServerInfo:
|
|
159
|
+
id: str
|
|
160
|
+
name: str
|
|
161
|
+
url: str
|
|
162
|
+
description: str
|
|
163
|
+
server_type: str
|
|
164
|
+
capabilities: List[str]
|
|
165
|
+
metadata: Dict[str, Any]
|
|
166
|
+
tags: List[str]
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Complete Example
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
#!/usr/bin/env python
|
|
173
|
+
import asyncio
|
|
174
|
+
import os
|
|
175
|
+
from traia_iatp.registry.iatp_search_api import (
|
|
176
|
+
find_utility_agent,
|
|
177
|
+
list_utility_agents,
|
|
178
|
+
search_utility_agents,
|
|
179
|
+
find_mcp_server,
|
|
180
|
+
list_mcp_servers,
|
|
181
|
+
search_mcp_servers
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
async def main():
|
|
186
|
+
# Set authentication (choose one)
|
|
187
|
+
os.environ["MONGODB_X509_CERT_FILE"] = "/path/to/cert.pem"
|
|
188
|
+
# OR
|
|
189
|
+
# os.environ["MONGODB_USER"] = "username"
|
|
190
|
+
# os.environ["MONGODB_PASSWORD"] = "password"
|
|
191
|
+
|
|
192
|
+
# Search for trading agents using vector search (default search_text embedding)
|
|
193
|
+
print("Trading agents:")
|
|
194
|
+
agents = await search_utility_agents("trading", limit=5)
|
|
195
|
+
for agent in agents:
|
|
196
|
+
print(f"- {agent.name}: {agent.base_url}")
|
|
197
|
+
|
|
198
|
+
# Find specific agent
|
|
199
|
+
agent = find_utility_agent(name="hyperliquid-mcp-traia-utility-agency")
|
|
200
|
+
if agent:
|
|
201
|
+
print(f"\nFound agent: {agent.name}")
|
|
202
|
+
print(f"Capabilities: {', '.join(agent.capabilities)}")
|
|
203
|
+
print(f"Tags: {', '.join(agent.tags)}")
|
|
204
|
+
|
|
205
|
+
# List MCP servers
|
|
206
|
+
print("\nMCP Servers:")
|
|
207
|
+
servers = list_mcp_servers(limit=5)
|
|
208
|
+
for server in servers:
|
|
209
|
+
print(f"- {server.name}: {server.url}")
|
|
210
|
+
|
|
211
|
+
# Search MCP servers with specific embedding field
|
|
212
|
+
print("\nSearching MCP servers by description:")
|
|
213
|
+
servers = await search_mcp_servers("trading", limit=3, embedding_fields=["description"])
|
|
214
|
+
for server in servers:
|
|
215
|
+
print(f"- {server.name}: {server.description}")
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
if __name__ == "__main__":
|
|
219
|
+
asyncio.run(main())
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Environment Configuration
|
|
223
|
+
|
|
224
|
+
Set the environment to control which MongoDB collections are used:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
export ENV=test # Uses test collections (default)
|
|
228
|
+
export ENV=staging # Uses staging collections
|
|
229
|
+
export ENV=prod # Uses production collections
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Error Handling
|
|
233
|
+
|
|
234
|
+
The API will raise a `ValueError` if no authentication method is configured:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
try:
|
|
238
|
+
agents = list_utility_agents()
|
|
239
|
+
except ValueError as e:
|
|
240
|
+
print(f"Authentication error: {e}")
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Performance Notes
|
|
244
|
+
|
|
245
|
+
- The API uses connection pooling for efficiency
|
|
246
|
+
- Results are returned as Python dataclasses for easy access
|
|
247
|
+
- Text search requires MongoDB text indexes to be configured
|
|
248
|
+
- Consider using `limit` parameter to control result size
|
|
249
|
+
|
|
250
|
+
## Testing
|
|
251
|
+
|
|
252
|
+
Run the example script to test the API:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
cd traia-centralized-backend
|
|
256
|
+
uv run python tests/test_mongodb_registry/example_iatp_registry_api.py
|
|
257
|
+
```
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# MongoDB X.509 Certificate Authentication Guide
|
|
2
|
+
|
|
3
|
+
This guide explains how to set up and use X.509 certificate authentication for MongoDB access in the IATP registry.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
X.509 certificate authentication provides a secure way to authenticate to MongoDB without using passwords or API keys. It uses SSL/TLS certificates for both encryption and authentication.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
1. **MongoDB Atlas Cluster** with X.509 authentication enabled
|
|
12
|
+
2. **Certificate file** (.pem) containing both the certificate and private key
|
|
13
|
+
3. **Certificate user** created in MongoDB's `$external` database
|
|
14
|
+
|
|
15
|
+
## Setup Steps
|
|
16
|
+
|
|
17
|
+
### 1. Obtain Your X.509 Certificate
|
|
18
|
+
|
|
19
|
+
If you've already created a certificate-based user via MongoDB Atlas UI:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Your certificate file should contain both the certificate and private key
|
|
23
|
+
# It typically looks like this:
|
|
24
|
+
#
|
|
25
|
+
# -----BEGIN CERTIFICATE-----
|
|
26
|
+
# [certificate content]
|
|
27
|
+
# -----END CERTIFICATE-----
|
|
28
|
+
# -----BEGIN PRIVATE KEY-----
|
|
29
|
+
# [private key content]
|
|
30
|
+
# -----END PRIVATE KEY-----
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Configure Environment Variable
|
|
34
|
+
|
|
35
|
+
Set the path to your certificate file:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
export MONGODB_X509_CERT_FILE="/path/to/your/certificate.pem"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For permanent configuration, add to your `.env` file:
|
|
42
|
+
|
|
43
|
+
```env
|
|
44
|
+
MONGODB_X509_CERT_FILE=/path/to/your/certificate.pem
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 3. Verify Certificate Setup
|
|
48
|
+
|
|
49
|
+
Extract the certificate subject (this should match your MongoDB user):
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
openssl x509 -in /path/to/your/certificate.pem -noout -subject
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Example output:
|
|
56
|
+
```
|
|
57
|
+
subject=CN=myapp,OU=myteam,O=mycompany,L=city,ST=state,C=US
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 4. Test the Connection
|
|
61
|
+
|
|
62
|
+
Run the test script to verify authentication:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
cd traia-centralized-backend
|
|
66
|
+
uv run python tests/test_mongodb_registry/test_mongodb_x509_auth.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Authentication Priority
|
|
70
|
+
|
|
71
|
+
The registries support multiple authentication methods with the following priority:
|
|
72
|
+
|
|
73
|
+
1. **X.509 Certificate** (if `MONGODB_X509_CERT_FILE` is set)
|
|
74
|
+
2. **Username/Password** (if `MONGODB_USER` and `MONGODB_PASSWORD` are set)
|
|
75
|
+
3. **Connection String** (if `MONGODB_CONNECTION_STRING` is set)
|
|
76
|
+
|
|
77
|
+
## Security Best Practices
|
|
78
|
+
|
|
79
|
+
### Certificate File Protection
|
|
80
|
+
|
|
81
|
+
1. **Restrict file permissions**:
|
|
82
|
+
```bash
|
|
83
|
+
chmod 600 /path/to/your/certificate.pem
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2. **Store securely**:
|
|
87
|
+
- Never commit certificate files to version control
|
|
88
|
+
- Use secure secret management systems for production
|
|
89
|
+
- Consider using environment-specific certificates
|
|
90
|
+
|
|
91
|
+
### Certificate Management
|
|
92
|
+
|
|
93
|
+
1. **Rotation**: Plan for certificate rotation before expiration
|
|
94
|
+
2. **Monitoring**: Set up alerts for certificate expiration
|
|
95
|
+
3. **Backup**: Keep secure backups of certificates
|
|
96
|
+
|
|
97
|
+
## Troubleshooting
|
|
98
|
+
|
|
99
|
+
### Common Issues
|
|
100
|
+
|
|
101
|
+
1. **Authentication Failed**
|
|
102
|
+
- Verify the certificate user exists in MongoDB's `$external` database
|
|
103
|
+
- Check certificate hasn't expired: `openssl x509 -in cert.pem -noout -dates`
|
|
104
|
+
- Ensure certificate was issued by the correct CA
|
|
105
|
+
|
|
106
|
+
2. **Connection Refused**
|
|
107
|
+
- Verify MongoDB cluster allows connections from your IP
|
|
108
|
+
- Check that TLS is enabled on the cluster
|
|
109
|
+
|
|
110
|
+
3. **Invalid Certificate Format**
|
|
111
|
+
- Ensure the .pem file contains both certificate and private key
|
|
112
|
+
- Verify no extra whitespace or formatting issues
|
|
113
|
+
|
|
114
|
+
### Debug Commands
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Check certificate validity
|
|
118
|
+
openssl x509 -in cert.pem -noout -text
|
|
119
|
+
|
|
120
|
+
# Verify private key matches certificate
|
|
121
|
+
openssl x509 -noout -modulus -in cert.pem | openssl md5
|
|
122
|
+
openssl rsa -noout -modulus -in cert.pem | openssl md5
|
|
123
|
+
|
|
124
|
+
# Test SSL connection to MongoDB
|
|
125
|
+
openssl s_client -connect your-cluster.mongodb.net:27017 -CAfile cert.pem
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Integration with IATP Services
|
|
129
|
+
|
|
130
|
+
### Using with Registry API
|
|
131
|
+
|
|
132
|
+
The registry automatically detects and uses X.509 authentication when configured:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from traia_iatp.registry.mongodb_registry import UtilityAgentRegistry
|
|
136
|
+
|
|
137
|
+
# No need to pass credentials - uses MONGODB_X509_CERT_FILE automatically
|
|
138
|
+
registry = UtilityAgentRegistry()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Docker Deployment
|
|
142
|
+
|
|
143
|
+
When deploying in Docker, mount the certificate file:
|
|
144
|
+
|
|
145
|
+
```yaml
|
|
146
|
+
# docker-compose.yml
|
|
147
|
+
services:
|
|
148
|
+
api:
|
|
149
|
+
environment:
|
|
150
|
+
- MONGODB_X509_CERT_FILE=/certs/mongodb.pem
|
|
151
|
+
volumes:
|
|
152
|
+
- ./certs/mongodb.pem:/certs/mongodb.pem:ro
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Kubernetes Deployment
|
|
156
|
+
|
|
157
|
+
Use Kubernetes secrets for certificate management:
|
|
158
|
+
|
|
159
|
+
```yaml
|
|
160
|
+
# Create secret
|
|
161
|
+
kubectl create secret generic mongodb-cert --from-file=mongodb.pem=/path/to/cert.pem
|
|
162
|
+
|
|
163
|
+
# Mount in deployment
|
|
164
|
+
apiVersion: apps/v1
|
|
165
|
+
kind: Deployment
|
|
166
|
+
spec:
|
|
167
|
+
template:
|
|
168
|
+
spec:
|
|
169
|
+
containers:
|
|
170
|
+
- name: app
|
|
171
|
+
env:
|
|
172
|
+
- name: MONGODB_X509_CERT_FILE
|
|
173
|
+
value: /certs/mongodb.pem
|
|
174
|
+
volumeMounts:
|
|
175
|
+
- name: mongodb-cert
|
|
176
|
+
mountPath: /certs
|
|
177
|
+
readOnly: true
|
|
178
|
+
volumes:
|
|
179
|
+
- name: mongodb-cert
|
|
180
|
+
secret:
|
|
181
|
+
secretName: mongodb-cert
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Migration from Username/Password
|
|
185
|
+
|
|
186
|
+
To migrate from username/password to X.509 certificate authentication:
|
|
187
|
+
|
|
188
|
+
1. Create certificate-based user in MongoDB Atlas
|
|
189
|
+
2. Update environment configuration:
|
|
190
|
+
```bash
|
|
191
|
+
# Remove or comment out
|
|
192
|
+
# MONGODB_USER=...
|
|
193
|
+
# MONGODB_PASSWORD=...
|
|
194
|
+
|
|
195
|
+
# Add
|
|
196
|
+
MONGODB_X509_CERT_FILE=/path/to/cert.pem
|
|
197
|
+
```
|
|
198
|
+
3. Test with `test_mongodb_x509_auth.py`:
|
|
199
|
+
```bash
|
|
200
|
+
uv run python tests/test_mongodb_registry/test_mongodb_x509_auth.py
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Support
|
|
204
|
+
|
|
205
|
+
For issues with X.509 authentication:
|
|
206
|
+
1. Check MongoDB Atlas documentation
|
|
207
|
+
2. Verify certificate configuration with `test_mongodb_x509_auth.py`
|
|
208
|
+
3. Review MongoDB connection logs in Atlas UI
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# IATP Registry Module
|
|
2
|
+
|
|
3
|
+
The IATP Registry provides a centralized database for discovering and managing:
|
|
4
|
+
- **Utility Agents**: IATP-enabled AI agents exposed via the A2A protocol
|
|
5
|
+
- **MCP Servers**: Model Context Protocol servers that can be wrapped as utility agents
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
The registry module has a layered architecture:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
┌─────────────────────────────────────┐
|
|
13
|
+
│ External Clients / Services │
|
|
14
|
+
└─────────────────────────────────────┘
|
|
15
|
+
│
|
|
16
|
+
▼
|
|
17
|
+
┌─────────────────────────────────────┐
|
|
18
|
+
│ iatp_registry_api.py │ ← High-level API (no MongoDB write dependency)
|
|
19
|
+
│ (find_*, list_*, search_*) │
|
|
20
|
+
└─────────────────────────────────────┘
|
|
21
|
+
│
|
|
22
|
+
▼
|
|
23
|
+
┌─────────────────────────────────────┐
|
|
24
|
+
│ mongodb_registry.py │ ← MongoDB implementation
|
|
25
|
+
│ (UtilityAgentRegistry, etc.) │
|
|
26
|
+
└─────────────────────────────────────┘
|
|
27
|
+
│
|
|
28
|
+
▼
|
|
29
|
+
┌─────────────────────────────────────┐
|
|
30
|
+
│ MongoDB Atlas Cloud │ ← Database backend
|
|
31
|
+
└─────────────────────────────────────┘
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Authentication Methods
|
|
35
|
+
|
|
36
|
+
The registry supports two authentication methods for MongoDB access, with the following priority:
|
|
37
|
+
|
|
38
|
+
### 1. X.509 Certificate Authentication (Recommended) ⭐
|
|
39
|
+
|
|
40
|
+
Use SSL/TLS certificates for authentication without passwords. Most secure option.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
export MONGODB_X509_CERT_FILE=/path/to/certificate.pem
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
See [MONGODB_X509_AUTH.md](./MONGODB_X509_AUTH.md) for detailed setup instructions.
|
|
47
|
+
|
|
48
|
+
### 2. Username/Password Authentication
|
|
49
|
+
|
|
50
|
+
Traditional username/password authentication.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
export MONGODB_USER=username
|
|
54
|
+
export MONGODB_PASSWORD=password
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
You can also provide a full connection string:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
export MONGODB_CONNECTION_STRING=mongodb+srv://user:pass@cluster.mongodb.net/...
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
### Using the High-Level API (No MongoDB Required)
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from traia_iatp.registry.iatp_search_api import find_utility_agent, list_mcp_servers
|
|
69
|
+
|
|
70
|
+
# Find a specific utility agent
|
|
71
|
+
agent = await find_utility_agent(name="trading-agent")
|
|
72
|
+
|
|
73
|
+
# List available MCP servers
|
|
74
|
+
servers = list_mcp_servers(limit=10)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Direct MongoDB Access
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from traia_iatp.registry.mongodb_registry import UtilityAgentRegistry
|
|
81
|
+
|
|
82
|
+
# Registry will automatically use configured authentication
|
|
83
|
+
registry = UtilityAgentRegistry()
|
|
84
|
+
|
|
85
|
+
# Query agents
|
|
86
|
+
agents = await registry.query_agents(
|
|
87
|
+
query="trading",
|
|
88
|
+
tags=["finance"],
|
|
89
|
+
limit=10
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Search Capabilities
|
|
94
|
+
|
|
95
|
+
The registry supports multiple search methods:
|
|
96
|
+
|
|
97
|
+
### 1. Text Search
|
|
98
|
+
Basic MongoDB text search across indexed fields.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
agents = await registry.query_agents(query="trading bot")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 2. Atlas Search
|
|
105
|
+
Advanced full-text search using MongoDB Atlas Search.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
agents = await registry.atlas_search("AI trading assistant")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 3. Vector Search
|
|
112
|
+
Vector search uses OpenAI embeddings to find semantically similar agents:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
# By default, searches using the comprehensive search_text embedding (recommended)
|
|
116
|
+
results = await registry.vector_search_text("trading bots", limit=5)
|
|
117
|
+
|
|
118
|
+
# You can also search on specific embedding fields
|
|
119
|
+
results = await registry.vector_search_text("defi", search_field="tags", limit=5)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The `search_text` field contains a concatenation of:
|
|
123
|
+
- Agent name and description
|
|
124
|
+
- All capabilities and tags
|
|
125
|
+
- Agent card details (name, description)
|
|
126
|
+
- All skill names, descriptions, examples, and tags
|
|
127
|
+
|
|
128
|
+
This makes it ideal for comprehensive semantic search.
|
|
129
|
+
|
|
130
|
+
## Environment Configuration
|
|
131
|
+
|
|
132
|
+
### Required Settings
|
|
133
|
+
|
|
134
|
+
- `ENV`: Environment name (`test`, `staging`, `prod`)
|
|
135
|
+
- One of the authentication methods above
|
|
136
|
+
|
|
137
|
+
### Optional Settings
|
|
138
|
+
|
|
139
|
+
- `ENABLE_EMBEDDINGS`: Enable vector search (`true`/`false`, default: `true`)
|
|
140
|
+
- `OPENAI_API_KEY`: Required if embeddings are enabled
|
|
141
|
+
|
|
142
|
+
## Collections
|
|
143
|
+
|
|
144
|
+
The registry uses environment-specific collections:
|
|
145
|
+
|
|
146
|
+
- **Utility Agents**: `iatp-utility-agent-registry-{env}`
|
|
147
|
+
- **MCP Servers**: `iatp-mcp-server-registry-{env}`
|
|
148
|
+
|
|
149
|
+
## Indexes
|
|
150
|
+
|
|
151
|
+
### Regular Indexes (Created Automatically)
|
|
152
|
+
- `agent_id` (unique)
|
|
153
|
+
- `name` (unique)
|
|
154
|
+
- `base_url` (unique)
|
|
155
|
+
- `is_active`
|
|
156
|
+
- `tags`
|
|
157
|
+
- `capabilities`
|
|
158
|
+
- `registered_at`
|
|
159
|
+
|
|
160
|
+
### Search Indexes (Create via Atlas UI)
|
|
161
|
+
- Atlas Search indexes for full-text search
|
|
162
|
+
- Vector Search indexes for semantic search
|
|
163
|
+
|
|
164
|
+
See [atlas_search_indexes.json](./atlas_search_indexes.json) for index definitions.
|
|
165
|
+
|
|
166
|
+
## Examples
|
|
167
|
+
|
|
168
|
+
### Register a New Utility Agent
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from traia_iatp.core.models import UtilityAgent, AgentEndpoints
|
|
172
|
+
|
|
173
|
+
agent = UtilityAgent(
|
|
174
|
+
name="My Trading Bot",
|
|
175
|
+
description="An AI agent for automated trading",
|
|
176
|
+
capabilities=["trade", "analyze", "report"],
|
|
177
|
+
endpoints=AgentEndpoints(
|
|
178
|
+
base_url="https://mybot.example.com"
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
registry = UtilityAgentRegistry()
|
|
183
|
+
entry = await registry.add_utility_agent(agent)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Search with Filters
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
# Find agents with specific capabilities
|
|
190
|
+
agents = await registry.query_agents(
|
|
191
|
+
capabilities=["trade", "analyze"],
|
|
192
|
+
tags=["crypto"],
|
|
193
|
+
active_only=True
|
|
194
|
+
)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Testing
|
|
198
|
+
|
|
199
|
+
### Test Authentication
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
# Test X.509 certificate authentication
|
|
203
|
+
uv run python tests/test_mongodb_registry/test_mongodb_x509_auth.py
|
|
204
|
+
|
|
205
|
+
# Run general registry tests
|
|
206
|
+
uv run python -m pytest tests/test_mongodb_registry/
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Example Scripts
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# X.509 authentication example
|
|
213
|
+
uv run python tests/test_mongodb_registry/example_x509_auth.py
|
|
214
|
+
|
|
215
|
+
# IATP Registry API example
|
|
216
|
+
uv run python tests/test_mongodb_registry/example_iatp_registry_api.py
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Security Best Practices
|
|
220
|
+
|
|
221
|
+
1. **Use X.509 certificates** for production deployments
|
|
222
|
+
2. **Rotate credentials** regularly
|
|
223
|
+
3. **Use environment-specific** collections and credentials
|
|
224
|
+
4. **Enable IP whitelisting** in MongoDB Atlas
|
|
225
|
+
5. **Monitor access logs** for unauthorized attempts
|
|
226
|
+
|
|
227
|
+
## Troubleshooting
|
|
228
|
+
|
|
229
|
+
### Connection Issues
|
|
230
|
+
|
|
231
|
+
1. Check authentication environment variables
|
|
232
|
+
2. Verify MongoDB Atlas IP whitelist
|
|
233
|
+
3. Test with `test_mongodb_x509_auth.py`
|
|
234
|
+
|
|
235
|
+
### Search Not Working
|
|
236
|
+
|
|
237
|
+
1. Ensure Atlas Search indexes are created
|
|
238
|
+
2. Wait for index building to complete
|
|
239
|
+
3. Check `ENABLE_EMBEDDINGS` setting
|
|
240
|
+
|
|
241
|
+
### Certificate Authentication Failed
|
|
242
|
+
|
|
243
|
+
1. Verify certificate file exists and is readable
|
|
244
|
+
2. Check certificate user in `$external` database
|
|
245
|
+
3. Ensure certificate hasn't expired
|
|
246
|
+
|
|
247
|
+
## Related Documentation
|
|
248
|
+
|
|
249
|
+
- [MONGODB_X509_AUTH.md](./MONGODB_X509_AUTH.md) - X.509 certificate setup
|
|
250
|
+
- [ATLAS_SEARCH_SETUP.md](./ATLAS_SEARCH_SETUP.md) - Atlas Search configuration
|
|
251
|
+
- [../api/README.md](../api/README.md) - REST API service
|