traia-iatp 0.1.1__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 +30 -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/grpc_a2a_tools.py +349 -0
- traia_iatp/client/root_path_a2a_client.py +1 -0
- traia_iatp/core/__init__.py +43 -0
- traia_iatp/core/models.py +161 -0
- traia_iatp/mcp/__init__.py +15 -0
- traia_iatp/mcp/client.py +201 -0
- traia_iatp/mcp/mcp_agent_template.py +422 -0
- traia_iatp/mcp/templates/Dockerfile.j2 +56 -0
- traia_iatp/mcp/templates/README.md.j2 +212 -0
- traia_iatp/mcp/templates/cursor-rules.md.j2 +326 -0
- traia_iatp/mcp/templates/deployment_params.json.j2 +20 -0
- traia_iatp/mcp/templates/docker-compose.yml.j2 +23 -0
- traia_iatp/mcp/templates/dockerignore.j2 +47 -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 +26 -0
- traia_iatp/mcp/templates/run_local_docker.sh.j2 +94 -0
- traia_iatp/mcp/templates/server.py.j2 +240 -0
- traia_iatp/mcp/traia_mcp_adapter.py +381 -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 +839 -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/server/__init__.py +15 -0
- traia_iatp/server/a2a_server.py +215 -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/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 +450 -0
- traia_iatp/server/templates/agent.py.j2 +80 -0
- traia_iatp/server/templates/agent_config.json.j2 +22 -0
- traia_iatp/server/templates/agent_executor.py.j2 +264 -0
- traia_iatp/server/templates/docker-compose.yml.j2 +23 -0
- traia_iatp/server/templates/env.example.j2 +67 -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 +76 -0
- traia_iatp/server/templates/run_local_docker.sh.j2 +103 -0
- traia_iatp/server/templates/server.py.j2 +190 -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.1.dist-info/METADATA +414 -0
- traia_iatp-0.1.1.dist-info/RECORD +72 -0
- traia_iatp-0.1.1.dist-info/WHEEL +5 -0
- traia_iatp-0.1.1.dist-info/entry_points.txt +2 -0
- traia_iatp-0.1.1.dist-info/licenses/LICENSE +21 -0
- traia_iatp-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,212 @@
|
|
|
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
|
+
{% endif %}
|
|
12
|
+
- 🐳 **Docker Support**: Easy deployment with Docker and Docker Compose
|
|
13
|
+
- ⚡ **Async Operations**: Built with FastMCP for efficient async handling
|
|
14
|
+
|
|
15
|
+
## API Documentation
|
|
16
|
+
|
|
17
|
+
- **{{ api_name }} Website**: [{{ api_url }}]({{ api_url }})
|
|
18
|
+
- **API Documentation**: [{{ docs_url }}]({{ docs_url }})
|
|
19
|
+
|
|
20
|
+
## Available Tools
|
|
21
|
+
|
|
22
|
+
This server provides the following tools:
|
|
23
|
+
|
|
24
|
+
- **`example_tool`**: Placeholder tool (to be implemented)
|
|
25
|
+
- **`get_api_info`**: Get information about the API service and authentication status
|
|
26
|
+
|
|
27
|
+
*Note: Replace `example_tool` with actual {{ api_name }} API tools based on the documentation.*
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
### Using Docker (Recommended)
|
|
32
|
+
|
|
33
|
+
1. Clone this repository:
|
|
34
|
+
```bash
|
|
35
|
+
git clone https://github.com/Traia-IO/{{ api_slug }}-mcp-server.git
|
|
36
|
+
cd {{ api_slug }}-mcp-server
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
{% if requires_auth %}
|
|
40
|
+
2. Set your API key:
|
|
41
|
+
```bash
|
|
42
|
+
export {{ api_key_env_var }}="your-api-key-here"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
3. Run with Docker:
|
|
46
|
+
{% else %}
|
|
47
|
+
2. Run with Docker:
|
|
48
|
+
{% endif %}
|
|
49
|
+
```bash
|
|
50
|
+
./run_local_docker.sh
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Using Docker Compose
|
|
54
|
+
|
|
55
|
+
1. Create a `.env` file with your configuration:
|
|
56
|
+
```env
|
|
57
|
+
{% if requires_auth %}{{ api_key_env_var }}=your-api-key-here
|
|
58
|
+
{% endif %}PORT=8000
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
2. Start the server:
|
|
62
|
+
```bash
|
|
63
|
+
docker-compose up
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Manual Installation
|
|
67
|
+
|
|
68
|
+
1. Install dependencies using `uv`:
|
|
69
|
+
```bash
|
|
70
|
+
uv pip install -e .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
2. Run the server:
|
|
74
|
+
```bash
|
|
75
|
+
{% if requires_auth %}{{ api_key_env_var }}="your-api-key-here" {% endif %}uv run python -m server
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
### Health Check
|
|
81
|
+
|
|
82
|
+
Test if the server is running:
|
|
83
|
+
```bash
|
|
84
|
+
python mcp_health_check.py
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Using with CrewAI
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
{% if requires_auth %}from traia_iatp.mcp.traia_mcp_adapter import create_mcp_adapter_with_auth
|
|
91
|
+
|
|
92
|
+
# Connect with authentication
|
|
93
|
+
with create_mcp_adapter_with_auth(
|
|
94
|
+
url="http://localhost:8000/mcp/",
|
|
95
|
+
api_key="your-api-key"
|
|
96
|
+
) as tools:
|
|
97
|
+
# Use the tools
|
|
98
|
+
for tool in tools:
|
|
99
|
+
print(f"Available tool: {tool.name}")
|
|
100
|
+
|
|
101
|
+
# Example usage
|
|
102
|
+
result = await tool.example_tool(query="test")
|
|
103
|
+
print(result)
|
|
104
|
+
{% else %}from traia_iatp.mcp.traia_mcp_adapter import create_mcp_adapter
|
|
105
|
+
|
|
106
|
+
# Connect to the MCP server
|
|
107
|
+
with create_mcp_adapter(
|
|
108
|
+
url="http://localhost:8000/mcp/"
|
|
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
|
+
{% endif %}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
{% if requires_auth %}
|
|
121
|
+
## Authentication
|
|
122
|
+
|
|
123
|
+
This server requires API key authentication. Clients must provide their API key in the `Authorization` header:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
Authorization: Bearer YOUR_API_KEY
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The API key is then used to authenticate requests to the {{ api_name }} API.
|
|
130
|
+
{% endif %}
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
### Testing the Server
|
|
135
|
+
|
|
136
|
+
1. Start the server locally
|
|
137
|
+
2. Run the health check: `python mcp_health_check.py`
|
|
138
|
+
3. Test individual tools using the CrewAI adapter
|
|
139
|
+
|
|
140
|
+
### Adding New Tools
|
|
141
|
+
|
|
142
|
+
To add new tools, edit `server.py` and:
|
|
143
|
+
|
|
144
|
+
1. Create API client functions for {{ api_name }} endpoints
|
|
145
|
+
2. Add `@mcp.tool()` decorated functions
|
|
146
|
+
3. Update this README with the new tools
|
|
147
|
+
4. Update `deployment_params.json` with the tool names in the capabilities array
|
|
148
|
+
|
|
149
|
+
## Deployment
|
|
150
|
+
|
|
151
|
+
### Deployment Configuration
|
|
152
|
+
|
|
153
|
+
The `deployment_params.json` file contains the deployment configuration for this MCP server:
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"github_url": "https://github.com/Traia-IO/{{ api_slug }}-mcp-server",
|
|
158
|
+
"mcp_server": {
|
|
159
|
+
"name": "{{ api_slug }}-mcp",
|
|
160
|
+
"description": "{{ api_description|capitalize }}",
|
|
161
|
+
"server_type": "streamable-http",
|
|
162
|
+
{% if requires_auth %}"requires_api_key": true,
|
|
163
|
+
"api_key_header": "Authorization",
|
|
164
|
+
{% endif %}"capabilities": [
|
|
165
|
+
// List all implemented tool names here
|
|
166
|
+
"example_tool",
|
|
167
|
+
"get_api_info"
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
"deployment_method": "cloud_run",
|
|
171
|
+
"gcp_project_id": "traia-mcp-servers",
|
|
172
|
+
"gcp_region": "us-central1",
|
|
173
|
+
"tags": ["{{ api_name_lower }}", "api"],
|
|
174
|
+
"ref": "main"
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Important**: Always update the `capabilities` array when you add or remove tools!
|
|
179
|
+
|
|
180
|
+
### Google Cloud Run
|
|
181
|
+
|
|
182
|
+
This server is designed to be deployed on Google Cloud Run. The deployment will:
|
|
183
|
+
|
|
184
|
+
1. Build a container from the Dockerfile
|
|
185
|
+
2. Deploy to Cloud Run with the specified configuration
|
|
186
|
+
3. Expose the `/mcp` endpoint for client connections
|
|
187
|
+
|
|
188
|
+
## Environment Variables
|
|
189
|
+
|
|
190
|
+
- `PORT`: Server port (default: 8000)
|
|
191
|
+
- `STAGE`: Environment stage (default: MAINNET, options: MAINNET, TESTNET)
|
|
192
|
+
- `LOG_LEVEL`: Logging level (default: INFO)
|
|
193
|
+
{% if requires_auth %}- `{{ api_key_env_var }}`: Your {{ api_name }} API key (required){% endif %}
|
|
194
|
+
|
|
195
|
+
## Troubleshooting
|
|
196
|
+
|
|
197
|
+
1. **Server not starting**: Check Docker logs with `docker logs <container-id>`
|
|
198
|
+
{% if requires_auth %}2. **Authentication errors**: Ensure your API key is correctly set in the environment
|
|
199
|
+
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 %}
|
|
200
|
+
3. **Tool errors**: Check the server logs for detailed error messages
|
|
201
|
+
|
|
202
|
+
## Contributing
|
|
203
|
+
|
|
204
|
+
1. Fork the repository
|
|
205
|
+
2. Create a feature branch
|
|
206
|
+
3. Implement new tools or improvements
|
|
207
|
+
4. Update the README and deployment_params.json
|
|
208
|
+
5. Submit a pull request
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
[MIT License](LICENSE)
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# {{ api_name }} MCP Server Implementation Guide
|
|
2
|
+
|
|
3
|
+
You are working on implementing the {{ api_name }} MCP (Model Context Protocol) server. The basic structure has been set up, and your task is to implement the actual API integration.
|
|
4
|
+
|
|
5
|
+
## API Information
|
|
6
|
+
|
|
7
|
+
- **API Name**: {{ api_name }}
|
|
8
|
+
- **Documentation**: [{{ docs_url }}]({{ docs_url }})
|
|
9
|
+
- **Website**: [{{ api_url }}]({{ api_url }})
|
|
10
|
+
{% if sdk_package %}
|
|
11
|
+
- **SDK**: `{{ sdk_package }}` (already included in pyproject.toml)
|
|
12
|
+
{% endif %}
|
|
13
|
+
- **Authentication**: {% if requires_auth %}Required - API key via `{{ api_key_env_var }}` environment variable{% else %}Not required{% endif %}
|
|
14
|
+
|
|
15
|
+
## Implementation Checklist
|
|
16
|
+
|
|
17
|
+
### 1. Update Deployment Configuration
|
|
18
|
+
|
|
19
|
+
**IMPORTANT**: Update the `deployment_params.json` file with all implemented capabilities:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"mcp_server": {
|
|
24
|
+
"capabilities": [
|
|
25
|
+
// Replace these with your actual implemented tool names
|
|
26
|
+
"search_{{ api_slug.replace('-', '_') }}",
|
|
27
|
+
"get_{{ api_slug.replace('-', '_') }}_info",
|
|
28
|
+
// Add all other tools you implement
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"tags": ["{{ api_name_lower }}", "api", /* add relevant tags like "search", "data", etc. */]
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Study the API Documentation
|
|
36
|
+
|
|
37
|
+
First, thoroughly review the API documentation at {{ docs_url }} to understand:
|
|
38
|
+
- Available endpoints
|
|
39
|
+
- Request/response formats
|
|
40
|
+
- Rate limits
|
|
41
|
+
- Error handling
|
|
42
|
+
{% if requires_auth %}- Authentication method (API key placement in headers, query params, etc.){% endif %}
|
|
43
|
+
- Specific features and capabilities to expose as tools
|
|
44
|
+
|
|
45
|
+
### 3. Implement API Client Functions
|
|
46
|
+
|
|
47
|
+
Add functions to call the {{ api_name }} API with retry support. Example pattern:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from retry import retry
|
|
51
|
+
|
|
52
|
+
{% if sdk_package %}# Using the SDK with retry decorator
|
|
53
|
+
@retry(tries=2, delay=1, backoff=2, jitter=(1, 3))
|
|
54
|
+
def call_{{ api_slug.replace('-', '_') }}_api(endpoint: str, params: Dict[str, Any], api_key: str) -> Dict[str, Any]:
|
|
55
|
+
"""Call {{ api_name }} API using the SDK with automatic retry."""
|
|
56
|
+
# Initialize the SDK client
|
|
57
|
+
client = {{ sdk_module }}.Client(api_key=api_key)
|
|
58
|
+
|
|
59
|
+
# Make the API call - will retry once on any exception
|
|
60
|
+
try:
|
|
61
|
+
response = client.call_endpoint(params)
|
|
62
|
+
return response.to_dict()
|
|
63
|
+
except Exception as e:
|
|
64
|
+
raise Exception(f"{{ api_name }} API error: {str(e)}")
|
|
65
|
+
{% else %}# Using requests library with retry decorator
|
|
66
|
+
@retry(tries=2, delay=1, backoff=2, jitter=(1, 3))
|
|
67
|
+
def call_{{ api_slug.replace('-', '_') }}_api(endpoint: str, params: Dict[str, Any], api_key: str) -> Dict[str, Any]:
|
|
68
|
+
"""Call {{ api_name }} API endpoint with automatic retry."""
|
|
69
|
+
base_url = "https://api.example.com/v1" # TODO: Get actual base URL from docs
|
|
70
|
+
|
|
71
|
+
headers = {
|
|
72
|
+
{% if requires_auth %}"Authorization": f"Bearer {api_key}", # Or "X-API-Key": api_key
|
|
73
|
+
{% endif %}"Content-Type": "application/json"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
# Will retry once on any requests.RequestException
|
|
77
|
+
try:
|
|
78
|
+
response = requests.get(f"{base_url}/{endpoint}",
|
|
79
|
+
params=params,
|
|
80
|
+
headers=headers,
|
|
81
|
+
timeout=30)
|
|
82
|
+
response.raise_for_status()
|
|
83
|
+
return response.json()
|
|
84
|
+
except requests.RequestException as e:
|
|
85
|
+
raise Exception(f"{{ api_name }} API error: {str(e)}")
|
|
86
|
+
{% endif %}```
|
|
87
|
+
|
|
88
|
+
#### Retry Configuration Explained
|
|
89
|
+
|
|
90
|
+
- `tries=2`: Total attempts (1 original + 1 retry)
|
|
91
|
+
- `delay=1`: Wait 1 second before retry
|
|
92
|
+
- `backoff=2`: Multiply delay by 2 for subsequent retries (if more than 2 tries)
|
|
93
|
+
- `jitter=(1, 3)`: Add random delay between 1-3 seconds to avoid thundering herd
|
|
94
|
+
|
|
95
|
+
### 4. Create MCP Tools
|
|
96
|
+
|
|
97
|
+
Replace the `example_tool` placeholder with actual tools. **Each tool you implement MUST be added to the `capabilities` array in `deployment_params.json`**.
|
|
98
|
+
|
|
99
|
+
#### Search/Query Tool
|
|
100
|
+
```python
|
|
101
|
+
@mcp.tool()
|
|
102
|
+
async def search_{{ api_slug.replace('-', '_') }}(
|
|
103
|
+
context: Context,
|
|
104
|
+
query: str,
|
|
105
|
+
limit: int = 10
|
|
106
|
+
) -> Dict[str, Any]:
|
|
107
|
+
"""
|
|
108
|
+
Search {{ api_name }} for [specific data type].
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
context: MCP context (injected automatically)
|
|
112
|
+
query: Search query
|
|
113
|
+
limit: Maximum number of results
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
Dictionary with search results
|
|
117
|
+
"""
|
|
118
|
+
{% if requires_auth %}
|
|
119
|
+
api_key = get_session_api_key(context)
|
|
120
|
+
if not api_key:
|
|
121
|
+
return {"error": "No API key found. Please authenticate with Authorization: Bearer YOUR_API_KEY"}
|
|
122
|
+
{% endif %}
|
|
123
|
+
|
|
124
|
+
try:
|
|
125
|
+
# The call_{{ api_slug.replace('-', '_') }}_api function already has retry logic
|
|
126
|
+
results = call_{{ api_slug.replace('-', '_') }}_api(
|
|
127
|
+
"search", # TODO: Use actual endpoint
|
|
128
|
+
{"q": query, "limit": limit},
|
|
129
|
+
{% if requires_auth %}api_key{% else %}None{% endif %})
|
|
130
|
+
return {
|
|
131
|
+
"status": "success",
|
|
132
|
+
"results": results
|
|
133
|
+
}
|
|
134
|
+
except Exception as e:
|
|
135
|
+
return {"error": str(e)}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Get/Fetch Tool
|
|
139
|
+
```python
|
|
140
|
+
@mcp.tool()
|
|
141
|
+
async def get_{{ api_slug.replace('-', '_') }}_info(
|
|
142
|
+
context: Context,
|
|
143
|
+
item_id: str
|
|
144
|
+
) -> Dict[str, Any]:
|
|
145
|
+
"""
|
|
146
|
+
Get detailed information about a specific item.
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
context: MCP context (injected automatically)
|
|
150
|
+
item_id: ID of the item to fetch
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
Dictionary with item details
|
|
154
|
+
"""
|
|
155
|
+
# Similar implementation pattern
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Create/Update Tool (if applicable)
|
|
159
|
+
```python
|
|
160
|
+
@mcp.tool()
|
|
161
|
+
async def create_{{ api_slug.replace('-', '_') }}_item(
|
|
162
|
+
context: Context,
|
|
163
|
+
name: str,
|
|
164
|
+
data: Dict[str, Any]
|
|
165
|
+
) -> Dict[str, Any]:
|
|
166
|
+
"""
|
|
167
|
+
Create a new item in {{ api_name }}.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
context: MCP context (injected automatically)
|
|
171
|
+
name: Name of the item
|
|
172
|
+
data: Additional data for the item
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
Dictionary with creation result
|
|
176
|
+
"""
|
|
177
|
+
# Implementation here
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 5. Best Practices
|
|
181
|
+
|
|
182
|
+
1. **Error Handling**: Always wrap API calls in try-except blocks and return user-friendly error messages
|
|
183
|
+
2. **Input Validation**: Validate parameters before making API calls
|
|
184
|
+
3. **Rate Limiting**: Respect API rate limits, implement delays if needed
|
|
185
|
+
4. **Response Formatting**: Return consistent response structures across all tools
|
|
186
|
+
5. **Logging**: Use the logger for debugging but don't log sensitive data like API keys
|
|
187
|
+
6. **Documentation**: Write clear docstrings for each tool explaining parameters and return values
|
|
188
|
+
7. **Retry Strategy**: Use the `@retry` decorator on API client functions for resilience
|
|
189
|
+
|
|
190
|
+
#### Retry Best Practices
|
|
191
|
+
|
|
192
|
+
- **Only use retry for external API calls** - Don't add retry to internal functions, database operations, or file operations
|
|
193
|
+
- **Apply retry to API client functions**, not MCP tool functions directly
|
|
194
|
+
- **Use `tries=2`** (1 original attempt + 1 retry) to balance reliability and responsiveness
|
|
195
|
+
- **Add jitter** to prevent thundering herd when multiple clients retry simultaneously
|
|
196
|
+
- **Don't retry on authentication errors** - use conditional retry if needed:
|
|
197
|
+
```python
|
|
198
|
+
from retry import retry
|
|
199
|
+
import requests
|
|
200
|
+
|
|
201
|
+
def retry_on_server_error(exception):
|
|
202
|
+
"""Only retry on server errors (5xx), not client errors (4xx)"""
|
|
203
|
+
if isinstance(exception, requests.HTTPError):
|
|
204
|
+
return 500 <= exception.response.status_code < 600
|
|
205
|
+
return True # Retry on other exceptions like network errors
|
|
206
|
+
|
|
207
|
+
@retry(tries=2, delay=1, backoff=2, jitter=(1, 3), exceptions=retry_on_server_error)
|
|
208
|
+
def call_api_with_smart_retry(endpoint, params, api_key):
|
|
209
|
+
# API implementation
|
|
210
|
+
pass
|
|
211
|
+
```
|
|
212
|
+
- **Log retry attempts** for debugging:
|
|
213
|
+
```python
|
|
214
|
+
@retry(tries=2, delay=1, logger=logger)
|
|
215
|
+
def call_{{ api_slug.replace('-', '_') }}_api(...):
|
|
216
|
+
# Implementation
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### When to Use Retry
|
|
220
|
+
|
|
221
|
+
**✅ DO use retry for:**
|
|
222
|
+
- HTTP requests to external APIs
|
|
223
|
+
- Network operations that can fail temporarily
|
|
224
|
+
- Remote service calls that may experience transient errors
|
|
225
|
+
|
|
226
|
+
**❌ DON'T use retry for:**
|
|
227
|
+
- MCP tool functions (they should handle errors gracefully instead)
|
|
228
|
+
- Local file operations
|
|
229
|
+
- Database queries (unless specifically needed for connection issues)
|
|
230
|
+
- Authentication/validation logic
|
|
231
|
+
- Data processing or computation functions
|
|
232
|
+
|
|
233
|
+
### 6. Testing
|
|
234
|
+
|
|
235
|
+
After implementing tools, test them:
|
|
236
|
+
|
|
237
|
+
1. Run the server locally:
|
|
238
|
+
```bash
|
|
239
|
+
./run_local_docker.sh
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
2. Use the health check script:
|
|
243
|
+
```bash
|
|
244
|
+
python mcp_health_check.py
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
3. Test with CrewAI:
|
|
248
|
+
```python
|
|
249
|
+
{% if requires_auth %}from traia_iatp.mcp.traia_mcp_adapter import create_mcp_adapter_with_auth
|
|
250
|
+
|
|
251
|
+
# Authenticated connection
|
|
252
|
+
with create_mcp_adapter_with_auth(
|
|
253
|
+
url="http://localhost:8000/mcp/",
|
|
254
|
+
api_key="your-api-key"
|
|
255
|
+
) as tools:
|
|
256
|
+
# Test your tools
|
|
257
|
+
for tool in tools:
|
|
258
|
+
print(f"Tool: {tool.name}")
|
|
259
|
+
{% else %}from traia_iatp.mcp.traia_mcp_adapter import create_mcp_adapter
|
|
260
|
+
|
|
261
|
+
# Standard connection (no authentication)
|
|
262
|
+
with create_mcp_adapter(
|
|
263
|
+
url="http://localhost:8000/mcp/"
|
|
264
|
+
) as tools:
|
|
265
|
+
# Test your tools
|
|
266
|
+
for tool in tools:
|
|
267
|
+
print(f"Tool: {tool.name}")
|
|
268
|
+
{% endif %}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### 7. Update Documentation
|
|
272
|
+
|
|
273
|
+
After implementing the tools:
|
|
274
|
+
|
|
275
|
+
1. **Update README.md**:
|
|
276
|
+
- List all implemented tools with descriptions
|
|
277
|
+
- Add usage examples for each tool
|
|
278
|
+
- Include any specific setup instructions
|
|
279
|
+
|
|
280
|
+
2. **Update deployment_params.json**:
|
|
281
|
+
- Ensure ALL tool names are in the `capabilities` array
|
|
282
|
+
- Add relevant tags based on functionality
|
|
283
|
+
- Verify authentication settings match implementation
|
|
284
|
+
|
|
285
|
+
3. **Add Tool Examples** in README.md:
|
|
286
|
+
```python
|
|
287
|
+
# Example usage of each tool
|
|
288
|
+
result = await tool.search_{{ api_slug.replace('-', '_') }}(query="example", limit=5)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### 8. Pre-Deployment Checklist
|
|
292
|
+
|
|
293
|
+
Before marking the implementation as complete:
|
|
294
|
+
|
|
295
|
+
- [ ] All placeholder code has been replaced with actual implementation
|
|
296
|
+
- [ ] All tools are properly documented with docstrings
|
|
297
|
+
- [ ] Error handling is implemented for all API calls
|
|
298
|
+
- [ ] `deployment_params.json` contains all tool names in capabilities
|
|
299
|
+
- [ ] README.md has been updated with usage examples
|
|
300
|
+
- [ ] Server runs successfully with `./run_local_docker.sh`
|
|
301
|
+
- [ ] Health check passes
|
|
302
|
+
- [ ] At least one tool works end-to-end
|
|
303
|
+
|
|
304
|
+
### 9. Common {{ api_name }} Use Cases
|
|
305
|
+
|
|
306
|
+
Based on the API documentation, consider implementing tools for these common use cases:
|
|
307
|
+
|
|
308
|
+
1. **TODO**: List specific use cases based on {{ api_name }} capabilities
|
|
309
|
+
2. **TODO**: Add more relevant use cases
|
|
310
|
+
3. **TODO**: Include any special features of this API
|
|
311
|
+
|
|
312
|
+
### 10. Example API Calls
|
|
313
|
+
|
|
314
|
+
Here are some example API calls from the {{ api_name }} documentation that you should implement:
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
TODO: Add specific examples from the API docs
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Need Help?
|
|
321
|
+
|
|
322
|
+
- Check the {{ api_name }} API documentation: {{ docs_url }}
|
|
323
|
+
- Review the MCP specification: https://modelcontextprotocol.io
|
|
324
|
+
- Look at other MCP server examples in the Traia-IO organization
|
|
325
|
+
|
|
326
|
+
Remember: The goal is to make {{ api_name }}'s capabilities easily accessible to AI agents through standardized MCP tools.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"github_url": "https://github.com/Traia-IO/{{ api_slug }}-mcp-server",
|
|
3
|
+
"mcp_server": {
|
|
4
|
+
"name": "{{ api_slug }}-mcp",
|
|
5
|
+
"description": "{{ api_description|capitalize }}",
|
|
6
|
+
"server_type": "streamable-http",
|
|
7
|
+
"requires_api_key": {{ requires_auth|lower }},
|
|
8
|
+
{% if requires_auth %}"api_key_header": "Authorization",
|
|
9
|
+
"api_keys": ["{{ api_key_env_var }}"],
|
|
10
|
+
{% endif %}"capabilities": [
|
|
11
|
+
"example_tool",
|
|
12
|
+
"get_api_info"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"deployment_method": "cloud_run",
|
|
16
|
+
"gcp_project_id": "traia-mcp-servers",
|
|
17
|
+
"gcp_region": "us-central1",
|
|
18
|
+
"tags": ["{{ api_name_lower }}", "api", "mcp"],
|
|
19
|
+
"ref": "main"
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
version: '3.8'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
{{ api_slug }}-mcp:
|
|
5
|
+
build: .
|
|
6
|
+
container_name: {{ api_slug }}-mcp-server
|
|
7
|
+
ports:
|
|
8
|
+
- "8000:8000"
|
|
9
|
+
environment:
|
|
10
|
+
- PORT=8000
|
|
11
|
+
- STAGE=${STAGE:-MAINNET}
|
|
12
|
+
- LOG_LEVEL=${LOG_LEVEL:-INFO}
|
|
13
|
+
{% if api_key_env_var %}
|
|
14
|
+
- {{ api_key_env_var }}={% raw %}${{% endraw %}{{ api_key_env_var }}{% raw %}}{% endraw %}
|
|
15
|
+
{% endif %}
|
|
16
|
+
volumes:
|
|
17
|
+
- ./logs:/app/logs
|
|
18
|
+
restart: unless-stopped
|
|
19
|
+
healthcheck:
|
|
20
|
+
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
|
21
|
+
interval: 30s
|
|
22
|
+
timeout: 10s
|
|
23
|
+
retries: 3
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Python cache
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
|
|
7
|
+
# Virtual environments
|
|
8
|
+
.venv/
|
|
9
|
+
venv/
|
|
10
|
+
ENV/
|
|
11
|
+
env/
|
|
12
|
+
|
|
13
|
+
# IDE
|
|
14
|
+
.vscode/
|
|
15
|
+
.idea/
|
|
16
|
+
*.swp
|
|
17
|
+
*.swo
|
|
18
|
+
|
|
19
|
+
# Git
|
|
20
|
+
.git/
|
|
21
|
+
.gitignore
|
|
22
|
+
|
|
23
|
+
# Documentation
|
|
24
|
+
README.md
|
|
25
|
+
docs/
|
|
26
|
+
|
|
27
|
+
# Tests
|
|
28
|
+
tests/
|
|
29
|
+
pytest_cache/
|
|
30
|
+
.coverage
|
|
31
|
+
|
|
32
|
+
# OS
|
|
33
|
+
.DS_Store
|
|
34
|
+
Thumbs.db
|
|
35
|
+
|
|
36
|
+
# Temporary files
|
|
37
|
+
*.log
|
|
38
|
+
*.tmp
|
|
39
|
+
.cache/
|
|
40
|
+
|
|
41
|
+
# uv
|
|
42
|
+
uv.lock
|
|
43
|
+
|
|
44
|
+
# Docker
|
|
45
|
+
Dockerfile
|
|
46
|
+
docker-compose.yml
|
|
47
|
+
.dockerignore
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual Environment
|
|
24
|
+
venv/
|
|
25
|
+
ENV/
|
|
26
|
+
env/
|
|
27
|
+
.venv/
|
|
28
|
+
|
|
29
|
+
# IDE
|
|
30
|
+
.vscode/
|
|
31
|
+
.idea/
|
|
32
|
+
*.swp
|
|
33
|
+
*.swo
|
|
34
|
+
*~
|
|
35
|
+
|
|
36
|
+
# Environment variables
|
|
37
|
+
.env
|
|
38
|
+
.env.local
|
|
39
|
+
.env.*.local
|
|
40
|
+
|
|
41
|
+
# OS
|
|
42
|
+
.DS_Store
|
|
43
|
+
Thumbs.db
|
|
44
|
+
|
|
45
|
+
# Logs
|
|
46
|
+
*.log
|
|
47
|
+
logs/
|
|
48
|
+
|
|
49
|
+
# Testing
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
.coverage
|
|
52
|
+
htmlcov/
|
|
53
|
+
.tox/
|
|
54
|
+
.hypothesis/
|
|
55
|
+
|
|
56
|
+
# Package managers
|
|
57
|
+
uv.lock
|
|
58
|
+
poetry.lock
|
|
59
|
+
pip-log.txt
|
|
60
|
+
|
|
61
|
+
# Docker
|
|
62
|
+
.dockerignore
|
|
63
|
+
|
|
64
|
+
# Output files
|
|
65
|
+
output_tests/
|
|
66
|
+
*.txt
|
|
67
|
+
*.json
|
|
68
|
+
|
|
69
|
+
# Temporary files
|
|
70
|
+
*.tmp
|
|
71
|
+
*.temp
|
|
72
|
+
*.bak
|
|
73
|
+
|
|
74
|
+
# {{ api_name }} specific
|
|
75
|
+
{% if additional_gitignore_entries -%}
|
|
76
|
+
{{ additional_gitignore_entries }}
|
|
77
|
+
{%- endif %}
|