Back to skills
SKILL.md
443 Export Import Tutorial 372778e0
ASecurityStep-by-step tutorial for using ContextForge's configuration export and import capabilities. ---
- 9 stars
- 0 votes
- 0 copies
- 0 views
- Added October 11, 2026
Works with
Security analysis
100/100npx -y skills add tools-only/X-Skills --skill 443-export-import-tutorial_372778e0 --agent claude-codeAre you the author of 443 Export Import Tutorial 372778e0?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tools-only-443-export-import-tutorial-372778e0)# Export/Import Tutorial
Step-by-step tutorial for using ContextForge's configuration export and import capabilities.
---
## ๐ฏ Prerequisites
1. **Running ContextForge**: Ensure your gateway is running and accessible
2. **Authentication**: Configure either JWT token or basic auth credentials
3. **Some Configuration**: Have at least a few tools, gateways, or servers configured
### Setup Authentication
Choose one authentication method:
=== "JWT Token"
```bash
# Generate a JWT token
export MCPGATEWAY_BEARER_TOKEN=$(python3 -m mcpgateway.utils.create_jwt_token \
--username admin@example.com --exp 10080 --secret my-test-key)
```
=== "Basic Auth"
```bash
# Using default credentials (change in production!)
export BASIC_AUTH_USER=admin
export BASIC_AUTH_PASSWORD=changeme
```
---
## ๐ค Tutorial 1: Your First Export
Let's start by exporting your current configuration.
### Step 1: Check What You Have
```bash
# List your current tools
curl -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
http://localhost:4444/tools
# List your gateways
curl -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
http://localhost:4444/gateways
```
### Step 2: Export Everything
```bash
# Export complete configuration
mcpgateway export --out my-first-export.json
```
**Expected Output:**
```
Exporting configuration from gateway at http://127.0.0.1:4444
โ
Export completed successfully!
๐ Output file: my-first-export.json
๐ Exported 15 total entities:
โข tools: 8
โข gateways: 2
โข servers: 3
โข prompts: 2
```
### Step 3: Examine the Export
```bash
# View the export structure
jq 'keys' my-first-export.json
# Check entity counts
jq '.metadata.entity_counts' my-first-export.json
# View a sample tool (without showing sensitive auth data)
jq '.entities.tools[0] | {name, url, integration_type}' my-first-export.json
```
---
## ๐ฅ Tutorial 2: Test Import with Dry Run
Before importing to another environment, let's test the import process.
### Step 1: Validate the Export
```bash
# Run dry-run import to validate
mcpgateway import my-first-export.json --dry-run
```
**Expected Output:**
```
Importing configuration from my-first-export.json
๐ Dry-run validation completed!
๐ Results:
โข Total entities: 15
โข Processed: 15
โข Created: 0
โข Updated: 15
โข Skipped: 0
โข Failed: 0
โ ๏ธ Warnings (15):
โข Would import tool: weather_api
โข Would import gateway: external_service
โข Would import server: ai_tools
...
```
### Step 2: Test Different Conflict Strategies
```bash
# Test skip strategy (won't modify existing entities)
mcpgateway import my-first-export.json --conflict-strategy skip --dry-run
# Test rename strategy (creates new entities with timestamp)
mcpgateway import my-first-export.json --conflict-strategy rename --dry-run
# Test fail strategy (stops on first conflict)
mcpgateway import my-first-export.json --conflict-strategy fail --dry-run
```
---
## ๐จ Tutorial 3: Selective Export and Import
Learn to work with specific subsets of your configuration.
### Step 1: Export Only Tools
```bash
# Export just your REST API tools
mcpgateway export --types tools --out tools-only.json --verbose
```
**Verbose Output Shows:**
```
๐ Export details:
โข Version: 2025-03-26
โข Exported at: 2025-01-15T10:30:00Z
โข Exported by: admin
โข Source: http://127.0.0.1:4444
```
### Step 2: Tagged Export
```bash
# Export production-ready entities
mcpgateway export --tags production --out production-config.json
# Export development tools
mcpgateway export --tags development,staging --out dev-config.json
```
### Step 3: Selective Import
```bash
# Import only specific tools
mcpgateway import production-config.json --include "tools:weather_api,translate_service"
# Import tools and their dependent servers
mcpgateway import production-config.json --include "tools:weather_api;servers:*"
```
---
## ๐ Tutorial 4: Cross-Environment Migration
Migrate configuration from staging to production with different encryption keys.
### Scenario Setup
- **Staging**: `AUTH_ENCRYPTION_SECRET=staging-secret-123`
- **Production**: `AUTH_ENCRYPTION_SECRET=prod-secret-xyz`
### Step 1: Export from Staging
```bash
# On staging environment
mcpgateway export --tags production-ready --out staging-to-prod.json
```
### Step 2: Import to Production
```bash
# On production environment
# First, validate with dry-run
mcpgateway import staging-to-prod.json \
--rekey-secret prod-secret-xyz \
--conflict-strategy update \
--dry-run
# If validation passes, perform actual import
mcpgateway import staging-to-prod.json \
--rekey-secret prod-secret-xyz \
--conflict-strategy update
```
**Expected Output:**
```
Importing configuration from staging-to-prod.json
โ
Import completed!
๐ Results:
โข Total entities: 12
โข Processed: 12
โข Created: 5
โข Updated: 7
โข Skipped: 0
โข Failed: 0
```
---
## ๐ฅ Tutorial 5: Admin UI Workflow
Use the web interface for visual export/import management.
### Step 1: Access Admin UI
1. Open your browser to `http://localhost:4444/admin`
2. Login with your credentials
3. Navigate to the "Export/Import" section
### Step 2: Visual Export
1. **Select Entity Types**: Check boxes for Tools, Gateways, Servers
2. **Apply Filters**:
- Tags: `production, api`
- Include Inactive: โ
3. **Export Options**:
- Include Dependencies: โ
4. **Download**: Click "Export Configuration"
### Step 3: Import with Preview
1. **Upload File**: Drag-and-drop your export JSON file
2. **Preview**: Review entity counts and potential conflicts
3. **Configure Options**:
- Conflict Strategy: "Update existing items"
- Dry Run: โ
(for testing)
4. **Execute**: Click "Import Configuration"
5. **Monitor**: Watch real-time progress and results
---
## ๐ง Tutorial 6: Automation Scripts
Create reusable scripts for common export/import operations.
### Daily Backup Script
```bash
#!/bin/bash
# daily-backup.sh
set -e
DATE=$(date +%F)
BACKUP_DIR="/backups/mcpgateway"
BACKUP_FILE="$BACKUP_DIR/config-backup-$DATE.json"
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Export configuration
echo "๐ Starting daily backup for $DATE"
mcpgateway export --out "$BACKUP_FILE" --verbose
# Verify backup
if [[ -f "$BACKUP_FILE" ]]; then
SIZE=$(stat -c%s "$BACKUP_FILE")
ENTITIES=$(jq '.metadata.entity_counts | add' "$BACKUP_FILE")
echo "โ
Backup completed: $BACKUP_FILE ($SIZE bytes, $ENTITIES entities)"
else
echo "โ Backup failed: file not created"
exit 1
fi
# Optional: Upload to cloud storage
# aws s3 cp "$BACKUP_FILE" s3://backup-bucket/mcpgateway/
# gsutil cp "$BACKUP_FILE" gs://backup-bucket/mcpgateway/
```
### Environment Promotion Script
```bash
#!/bin/bash
# promote-staging-to-prod.sh
set -e
STAGING_CONFIG="staging-export.json"
PROD_SECRET="${PROD_ENCRYPTION_SECRET:-prod-secret-key}"
echo "๐ Promoting staging configuration to production"
# Export from staging (assuming we're connected to staging)
echo "๐ค Exporting staging configuration..."
mcpgateway export --tags production-ready --out "$STAGING_CONFIG"
# Validate export
ENTITY_COUNT=$(jq '.metadata.entity_counts | add' "$STAGING_CONFIG")
echo "๐ Exported $ENTITY_COUNT entities from staging"
# Dry run import to production
echo "๐ Validating import to production..."
mcpgateway import "$STAGING_CONFIG" \
--rekey-secret "$PROD_SECRET" \
--conflict-strategy update \
--dry-run
# Prompt for confirmation
read -p "Proceed with production import? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "๐ฅ Importing to production..."
mcpgateway import "$STAGING_CONFIG" \
--rekey-secret "$PROD_SECRET" \
--conflict-strategy update \
--verbose
echo "โ
Production promotion completed!"
else
echo "โ Import cancelled"
exit 1
fi
```
### Selective Tool Migration
```bash
#!/bin/bash
# migrate-tools.sh
TOOLS_TO_MIGRATE="weather_api,translate_service,sentiment_analysis"
EXPORT_FILE="tool-migration.json"
echo "๐ Migrating tools: $TOOLS_TO_MIGRATE"
# Export current config to find tool IDs
mcpgateway export --types tools --out all-tools.json
# Create selective export
mcpgateway export --types tools --out "$EXPORT_FILE"
# Import only specified tools
mcpgateway import "$EXPORT_FILE" \
--include "tools:$TOOLS_TO_MIGRATE" \
--conflict-strategy update
echo "โ
Tool migration completed"
```
---
## ๐ฏ Next Steps
After completing these tutorials, you should be able to:
- โ
Export your complete gateway configuration
- โ
Import configurations with conflict resolution
- โ
Use selective export/import for specific entities
- โ
Migrate configurations between environments
- โ
Set up automated backup and promotion workflows
- โ
Use both CLI and Admin UI interfaces
### Advanced Topics
- [Observability](observability.md) - Monitor export/import operations
- [Securing](securing.md) - Advanced security practices for config management
- [Tuning](tuning.md) - Performance optimization for large configurations
### Troubleshooting
If you encounter issues:
1. **Check the logs**: Gateway logs show detailed export/import operations
2. **Validate data**: Use `jq` to verify export file structure
3. **Test incrementally**: Start with small subsets before full imports
4. **Use dry-run**: Always validate imports before applying changes
5. **Check authentication**: Verify tokens and encryption keys are correct
For detailed troubleshooting, see the main [Export & Import Guide](export-import.md).
Attribution
Comments
Loading commentsโฆ
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.