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,310 @@
|
|
|
1
|
+
# {{ api_name }} MCP Server
|
|
2
|
+
|
|
3
|
+
This is an MCP (Model Context Protocol) server that provides{{ auth_details }} access to the {{ api_name }} API. It enables AI agents and LLMs to interact with {{ api_name }} through standardized tools.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔧 **MCP Protocol**: Built on the Model Context Protocol for seamless AI integration
|
|
8
|
+
- 🌐 **Full API Access**: Provides tools for interacting with {{ api_name }} endpoints
|
|
9
|
+
{% if requires_auth %}
|
|
10
|
+
- 🔐 **Secure Authentication**: Supports API key authentication via Bearer tokens
|
|
11
|
+
- 💳 **HTTP 402 Payment Protocol**: Dual-mode operation (authenticated or paid access)
|
|
12
|
+
- 🔗 **D402 Integration**: Uses traia_iatp.d402 for blockchain payment verification
|
|
13
|
+
{% endif %}
|
|
14
|
+
- 🐳 **Docker Support**: Easy deployment with Docker and Docker Compose
|
|
15
|
+
- ⚡ **Async Operations**: Built with FastMCP for efficient async handling
|
|
16
|
+
|
|
17
|
+
## API Documentation
|
|
18
|
+
|
|
19
|
+
- **{{ api_name }} Website**: [{{ api_url }}]({{ api_url }})
|
|
20
|
+
- **API Documentation**: [{{ docs_url }}]({{ docs_url }})
|
|
21
|
+
|
|
22
|
+
## Available Tools
|
|
23
|
+
|
|
24
|
+
This server provides the following tools:
|
|
25
|
+
|
|
26
|
+
- **`example_tool`**: Placeholder tool (to be implemented)
|
|
27
|
+
- **`get_api_info`**: Get information about the API service and authentication status
|
|
28
|
+
|
|
29
|
+
*Note: Replace `example_tool` with actual {{ api_name }} API tools based on the documentation.*
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
### Using Docker (Recommended)
|
|
34
|
+
|
|
35
|
+
1. Clone this repository:
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/Traia-IO/{{ api_slug }}-mcp-server.git
|
|
38
|
+
cd {{ api_slug }}-mcp-server
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
{% if requires_auth %}
|
|
42
|
+
2. Set your API key:
|
|
43
|
+
```bash
|
|
44
|
+
export {{ api_key_env_var }}="your-api-key-here"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
3. Run with Docker:
|
|
48
|
+
{% else %}
|
|
49
|
+
2. Run with Docker:
|
|
50
|
+
{% endif %}
|
|
51
|
+
```bash
|
|
52
|
+
./run_local_docker.sh
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Using Docker Compose
|
|
56
|
+
|
|
57
|
+
1. Create a `.env` file with your configuration:
|
|
58
|
+
```env
|
|
59
|
+
{% if requires_auth %}# Server's internal API key (for payment mode)
|
|
60
|
+
{{ api_key_env_var }}=your-api-key-here
|
|
61
|
+
|
|
62
|
+
# Server payment address (for HTTP 402 protocol)
|
|
63
|
+
SERVER_ADDRESS=0x1234567890123456789012345678901234567890
|
|
64
|
+
|
|
65
|
+
# Operator keys (for signing settlement attestations)
|
|
66
|
+
MCP_OPERATOR_PRIVATE_KEY=0x1234567890abcdef...
|
|
67
|
+
MCP_OPERATOR_ADDRESS=0x9876543210fedcba...
|
|
68
|
+
|
|
69
|
+
# Optional: Testing mode (skip settlement for local dev)
|
|
70
|
+
D402_TESTING_MODE=false
|
|
71
|
+
{% endif %}PORT=8000
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
2. Start the server:
|
|
75
|
+
```bash
|
|
76
|
+
docker-compose up
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Manual Installation
|
|
80
|
+
|
|
81
|
+
1. Install dependencies using `uv`:
|
|
82
|
+
```bash
|
|
83
|
+
uv pip install -e .
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2. Run the server:
|
|
87
|
+
```bash
|
|
88
|
+
{% if requires_auth %}{{ api_key_env_var }}="your-api-key-here" {% endif %}uv run python -m server
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Usage
|
|
92
|
+
|
|
93
|
+
### Health Check
|
|
94
|
+
|
|
95
|
+
Test if the server is running:
|
|
96
|
+
```bash
|
|
97
|
+
python mcp_health_check.py
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Using with CrewAI
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
{% if requires_auth %}from traia_iatp.mcp.traia_mcp_adapter import create_mcp_adapter_with_auth
|
|
104
|
+
|
|
105
|
+
# Connect with authentication
|
|
106
|
+
with create_mcp_adapter_with_auth(
|
|
107
|
+
url="http://localhost:8000/mcp/",
|
|
108
|
+
api_key="your-api-key"
|
|
109
|
+
) as tools:
|
|
110
|
+
# Use the tools
|
|
111
|
+
for tool in tools:
|
|
112
|
+
print(f"Available tool: {tool.name}")
|
|
113
|
+
|
|
114
|
+
# Example usage
|
|
115
|
+
result = await tool.example_tool(query="test")
|
|
116
|
+
print(result)
|
|
117
|
+
{% else %}from traia_iatp.mcp.traia_mcp_adapter import create_mcp_adapter
|
|
118
|
+
|
|
119
|
+
# Connect to the MCP server
|
|
120
|
+
with create_mcp_adapter(
|
|
121
|
+
url="http://localhost:8000/mcp/"
|
|
122
|
+
) as tools:
|
|
123
|
+
# Use the tools
|
|
124
|
+
for tool in tools:
|
|
125
|
+
print(f"Available tool: {tool.name}")
|
|
126
|
+
|
|
127
|
+
# Example usage
|
|
128
|
+
result = await tool.example_tool(query="test")
|
|
129
|
+
print(result)
|
|
130
|
+
{% endif %}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
{% if requires_auth %}
|
|
134
|
+
## Authentication & Payment (HTTP 402 Protocol)
|
|
135
|
+
|
|
136
|
+
This server supports **two modes of operation**:
|
|
137
|
+
|
|
138
|
+
### Mode 1: Authenticated Access (Free)
|
|
139
|
+
|
|
140
|
+
Clients with their own {{ api_name }} API key can use the server for free:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Request with client's API key
|
|
144
|
+
curl -X POST http://localhost:8000/mcp \
|
|
145
|
+
-H "Authorization: Bearer CLIENT_{{ api_key_env_var }}" \
|
|
146
|
+
-H "Content-Type: application/json" \
|
|
147
|
+
-d '{"method":"tools/call","params":{"name":"example_tool","arguments":{"query":"test"}}}'
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Flow**:
|
|
151
|
+
1. Client provides their {{ api_name }} API key
|
|
152
|
+
2. Server uses client's API key to call {{ api_name }} API
|
|
153
|
+
3. No payment required
|
|
154
|
+
4. Client pays {{ api_name }} directly
|
|
155
|
+
|
|
156
|
+
### Mode 2: Payment Required (Paid Access)
|
|
157
|
+
|
|
158
|
+
Clients without an API key can pay-per-use via HTTP 402 protocol:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Request with payment proof (x402/d402 protocol)
|
|
162
|
+
curl -X POST http://localhost:8000/mcp \
|
|
163
|
+
-H "X-PAYMENT: <base64_encoded_x402_payment>" \
|
|
164
|
+
-H "Content-Type: application/json" \
|
|
165
|
+
-d '{"method":"tools/call","params":{"name":"example_tool","arguments":{"query":"test"}}}'
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Flow**:
|
|
169
|
+
1. Client makes initial request without payment
|
|
170
|
+
2. Server returns HTTP 402 with PaymentRequirements (token, network, amount)
|
|
171
|
+
3. Client creates EIP-3009 transferWithAuthorization payment signature
|
|
172
|
+
4. Client base64-encodes payment and sends in X-PAYMENT header
|
|
173
|
+
5. Server verifies payment via traia_iatp.d402.mcp_middleware
|
|
174
|
+
6. Server uses its INTERNAL {{ api_name }} API key to call the API
|
|
175
|
+
7. Client receives result
|
|
176
|
+
|
|
177
|
+
### D402 Protocol Details
|
|
178
|
+
|
|
179
|
+
This server uses the **traia_iatp.d402** module for payment verification:
|
|
180
|
+
|
|
181
|
+
- **Payment Method**: EIP-3009 transferWithAuthorization (gasless)
|
|
182
|
+
- **Supported Tokens**: USDC, TRAIA, or any ERC20 token
|
|
183
|
+
- **Default Price**: $0.001 per request (configurable via `DEFAULT_PRICE_USD`)
|
|
184
|
+
- **Networks**: Base Sepolia, Sepolia, Polygon, etc.
|
|
185
|
+
- **Facilitator**: d402.org (public) or custom facilitator
|
|
186
|
+
|
|
187
|
+
### Environment Variables for Payment Mode
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# Required
|
|
191
|
+
{{ api_key_env_var }}=your_internal_{{ api_slug }}_api_key # Server's API key (for payment mode)
|
|
192
|
+
SERVER_ADDRESS=0x1234567890123456789012345678901234567890 # Server's payment address
|
|
193
|
+
|
|
194
|
+
# Required for Settlement (Production)
|
|
195
|
+
MCP_OPERATOR_PRIVATE_KEY=0x1234... # Private key for signing settlement attestations
|
|
196
|
+
MCP_OPERATOR_ADDRESS=0x5678... # Operator's public address (for verification)
|
|
197
|
+
|
|
198
|
+
# Optional
|
|
199
|
+
D402_FACILITATOR_URL=https://facilitator.d402.net # Facilitator service URL
|
|
200
|
+
D402_FACILITATOR_API_KEY=your_key # For private facilitator
|
|
201
|
+
D402_TESTING_MODE=false # Set to 'true' for local testing without settlement
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Operator Keys**:
|
|
205
|
+
- **MCP_OPERATOR_PRIVATE_KEY**: Used to sign settlement attestations (proof of service completion)
|
|
206
|
+
- **MCP_OPERATOR_ADDRESS**: Public address corresponding to the private key
|
|
207
|
+
- Required for on-chain settlement via IATP Settlement Layer
|
|
208
|
+
- Can be the same as SERVER_ADDRESS or a separate operator key
|
|
209
|
+
|
|
210
|
+
**Note on Per-Endpoint Configuration**:
|
|
211
|
+
Each endpoint's payment requirements (token address, network, price) are embedded in the tool code.
|
|
212
|
+
They come from the endpoint configuration when the server is generated.
|
|
213
|
+
|
|
214
|
+
### How It Works
|
|
215
|
+
|
|
216
|
+
1. **Client Decision**:
|
|
217
|
+
- Has {{ api_name }} API key? → Mode 1 (Authenticated)
|
|
218
|
+
- No API key but willing to pay? → Mode 2 (Payment)
|
|
219
|
+
|
|
220
|
+
2. **Server Response**:
|
|
221
|
+
- Mode 1: Uses client's API key (free for client)
|
|
222
|
+
- Mode 2: Uses server's API key (client pays server)
|
|
223
|
+
|
|
224
|
+
3. **Business Model**:
|
|
225
|
+
- Mode 1: No revenue (passthrough)
|
|
226
|
+
- Mode 2: Revenue from pay-per-use (monetize server's API subscription)
|
|
227
|
+
|
|
228
|
+
{% endif %}
|
|
229
|
+
|
|
230
|
+
## Development
|
|
231
|
+
|
|
232
|
+
### Testing the Server
|
|
233
|
+
|
|
234
|
+
1. Start the server locally
|
|
235
|
+
2. Run the health check: `python mcp_health_check.py`
|
|
236
|
+
3. Test individual tools using the CrewAI adapter
|
|
237
|
+
|
|
238
|
+
### Adding New Tools
|
|
239
|
+
|
|
240
|
+
To add new tools, edit `server.py` and:
|
|
241
|
+
|
|
242
|
+
1. Create API client functions for {{ api_name }} endpoints
|
|
243
|
+
2. Add `@mcp.tool()` decorated functions
|
|
244
|
+
3. Update this README with the new tools
|
|
245
|
+
4. Update `deployment_params.json` with the tool names in the capabilities array
|
|
246
|
+
|
|
247
|
+
## Deployment
|
|
248
|
+
|
|
249
|
+
### Deployment Configuration
|
|
250
|
+
|
|
251
|
+
The `deployment_params.json` file contains the deployment configuration for this MCP server:
|
|
252
|
+
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"github_url": "https://github.com/Traia-IO/{{ api_slug }}-mcp-server",
|
|
256
|
+
"mcp_server": {
|
|
257
|
+
"name": "{{ api_slug }}-mcp",
|
|
258
|
+
"description": "{{ api_description|capitalize }}",
|
|
259
|
+
"server_type": "streamable-http",
|
|
260
|
+
{% if requires_auth %}"requires_api_key": true,
|
|
261
|
+
"api_key_header": "Authorization",
|
|
262
|
+
{% endif %}"capabilities": [
|
|
263
|
+
// List all implemented tool names here
|
|
264
|
+
"example_tool",
|
|
265
|
+
"get_api_info"
|
|
266
|
+
]
|
|
267
|
+
},
|
|
268
|
+
"deployment_method": "cloud_run",
|
|
269
|
+
"gcp_project_id": "traia-mcp-servers",
|
|
270
|
+
"gcp_region": "us-central1",
|
|
271
|
+
"tags": ["{{ api_name_lower }}", "api"],
|
|
272
|
+
"ref": "main"
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**Important**: Always update the `capabilities` array when you add or remove tools!
|
|
277
|
+
|
|
278
|
+
### Google Cloud Run
|
|
279
|
+
|
|
280
|
+
This server is designed to be deployed on Google Cloud Run. The deployment will:
|
|
281
|
+
|
|
282
|
+
1. Build a container from the Dockerfile
|
|
283
|
+
2. Deploy to Cloud Run with the specified configuration
|
|
284
|
+
3. Expose the `/mcp` endpoint for client connections
|
|
285
|
+
|
|
286
|
+
## Environment Variables
|
|
287
|
+
|
|
288
|
+
- `PORT`: Server port (default: 8000)
|
|
289
|
+
- `STAGE`: Environment stage (default: MAINNET, options: MAINNET, TESTNET)
|
|
290
|
+
- `LOG_LEVEL`: Logging level (default: INFO)
|
|
291
|
+
{% if requires_auth %}- `{{ api_key_env_var }}`: Your {{ api_name }} API key (required){% endif %}
|
|
292
|
+
|
|
293
|
+
## Troubleshooting
|
|
294
|
+
|
|
295
|
+
1. **Server not starting**: Check Docker logs with `docker logs <container-id>`
|
|
296
|
+
{% if requires_auth %}2. **Authentication errors**: Ensure your API key is correctly set in the environment
|
|
297
|
+
3. **API errors**: Verify your API key has the necessary permissions{% else %}2. **Connection errors**: Ensure the server is running on the expected port{% endif %}
|
|
298
|
+
3. **Tool errors**: Check the server logs for detailed error messages
|
|
299
|
+
|
|
300
|
+
## Contributing
|
|
301
|
+
|
|
302
|
+
1. Fork the repository
|
|
303
|
+
2. Create a feature branch
|
|
304
|
+
3. Implement new tools or improvements
|
|
305
|
+
4. Update the README and deployment_params.json
|
|
306
|
+
5. Submit a pull request
|
|
307
|
+
|
|
308
|
+
## License
|
|
309
|
+
|
|
310
|
+
[MIT License](LICENSE)
|