FortiGate cihazlarını yönetmek için Model Context Protocol (MCP) sunucusu. Bu proje, FortiGate cihazlarına programatik erişim sağlar ve Cursor gibi MCP destekli araçlarla entegrasyon imkanı sunar.
- Cihaz Yönetimi: FortiGate cihazlarını ekleme, kaldırma ve bağlantı testi
- Firewall Yönetimi: Firewall kurallarını listeleme, oluşturma, güncelleme ve silme
- Ağ Yönetimi: Adres ve servis nesnelerini yönetme
- Routing Yönetimi: Statik rotaları ve arayüzleri yönetme
- HTTP Transport: FastMCP ile HTTP üzerinden MCP protokolü
- Docker Desteği: Kolay kurulum ve dağıtım
- Cursor Entegrasyonu: Cursor IDE ile tam entegrasyon
- Python 3.8+
- FortiGate cihazına erişim
- API token veya kullanıcı adı/şifre
git clone <repository-url>
cd fortigate-mcp-server# Virtual environment oluşturun
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# veya
.venv\Scripts\activate # Windows
# Bağımlılıkları yükleyin
pip install -r requirements.txtconfig/config.json dosyasını düzenleyin:
{
"fortigate": {
"devices": {
"default": {
"host": "192.168.1.1",
"port": 443,
"username": "admin",
"password": "password",
"api_token": "your-api-token",
"vdom": "root",
"verify_ssl": false,
"timeout": 30
}
}
},
"logging": {
"level": "INFO",
"file": "./logs/fortigate_mcp.log"
}
}# Script ile başlat
./start_http_server.sh
# Veya manuel olarak
python -m src.fortigate_mcp.server_http \
--host 0.0.0.0 \
--port 8814 \
--path /fortigate-mcp \
--config config/config.json# Build ve başlat
docker-compose up -d
# Logları görüntüle
docker-compose logs -f fortigate-mcp-serverCursor'da ~/.cursor/mcp_servers.json dosyasını düzenleyin:
{
"mcpServers": {
"fortigate-mcp": {
"command": "python",
"args": [
"-m",
"src.fortigate_mcp.server_http",
"--host",
"0.0.0.0",
"--port",
"8814",
"--path",
"/fortigate-mcp",
"--config",
"/path/to/your/config.json"
],
"env": {
"FORTIGATE_MCP_CONFIG": "/path/to/your/config.json"
}
}
}
}{
"mcpServers": {
"FortiGateMCP": {
"url": "http://0.0.0.0:8814/fortigate-mcp/",
"transport": "http"
}
}
}Cursor'da FortiGate MCP'yi kullanmak için:
- Server'ı başlatın:
cd /media/workspace/fortigate-mcp-server
python -m src.fortigate_mcp.server_http --host 0.0.0.0 --port 8814 --path /fortigate-mcp --config config/config.json- Cursor'u yeniden başlatın
- MCP server'ın başladığından emin olun
- Cursor'da FortiGate komutlarını kullanın
list_devices- Kayıtlı cihazları listeleget_device_status- Cihaz durumunu altest_device_connection- Bağlantıyı test etadd_device- Yeni cihaz ekleremove_device- Cihaz kaldırdiscover_vdoms- VDOM'ları keşfet
list_firewall_policies- Firewall kurallarını listelecreate_firewall_policy- Yeni kural oluşturupdate_firewall_policy- Kural güncelledelete_firewall_policy- Kural sil
list_address_objects- Adres nesnelerini listelecreate_address_object- Adres nesnesi oluşturlist_service_objects- Servis nesnelerini listelecreate_service_object- Servis nesnesi oluştur
list_virtual_ips- Virtual IP'leri listelecreate_virtual_ip- Virtual IP oluşturupdate_virtual_ip- Virtual IP güncelleget_virtual_ip_detail- Virtual IP detayını aldelete_virtual_ip- Virtual IP sil
list_static_routes- Statik rotaları listelecreate_static_route- Statik rota oluşturupdate_static_route- Statik rota güncelledelete_static_route- Statik rota silget_static_route_detail- Statik rota detayını alget_routing_table- Routing tablosunu allist_interfaces- Arayüzleri listeleget_interface_status- Arayüz durumunu al
health- Sağlık kontrolütest_connection- Bağlantı testiget_schema_info- Schema bilgisi
# Tüm unit testleri çalıştır (varsayılan)
python -m pytest
# Coverage ile çalıştır
python -m pytest --cov=src --cov-report=html
# Belirli test kategorilerini çalıştır
python -m pytest tests/test_device_manager.py
python -m pytest tests/test_fortigate_api.py
python -m pytest tests/test_tools.py
# Integration testlerini çalıştır (server çalışması gerekir)
python integration_tests.py
# Sadece unit testleri çalıştır (varsayılan)
python -m pytest tests/
# Detaylı çıktı ile çalıştır
python -m pytest -v
# Detaylı hata bilgisi ile çalıştır
python -m pytest --tb=long- Unit Testler: Bireysel bileşenleri ve fonksiyonları test eder
- Integration Testler: HTTP server işlevselliğini test eder (server çalışması gerekir)
- Coverage: HTML çıktısı ile kod coverage raporlaması
# Test script'ini çalıştır
python test_http_server.py# Health check
curl -X POST http://localhost:8814/fortigate-mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "health", "params": {}}'
# List devices
curl -X POST http://localhost:8814/fortigate-mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "list_devices", "params": {}}'fortigate-mcp-server/
├── src/
│ └── fortigate_mcp/
│ ├── __init__.py
│ ├── server_http.py # HTTP MCP server
│ ├── config/ # Konfigürasyon yönetimi
│ ├── core/ # Temel bileşenler
│ ├── tools/ # MCP araçları
│ └── formatting/ # Response formatting
├── config/
│ ├── config.json # Ana konfigürasyon
│ └── config.example.json # Örnek konfigürasyon
├── examples/
│ └── cursor_mcp_config.json # Cursor MCP config
├── logs/ # Log dosyaları
├── tests/ # Test dosyaları
├── docker-compose.yml # Docker compose
├── Dockerfile # Docker image
├── start_http_server.sh # Başlatma script'i
├── test_http_server.py # Test script'i
└── README.md # Bu dosya
-
Bağlantı Hatası
- FortiGate cihazının erişilebilir olduğundan emin olun
- API token veya kullanıcı adı/şifre doğru olmalı
- SSL sertifikası sorunları için
verify_ssl: falsekullanın
-
Port Çakışması
- 8814 portunun kullanılabilir olduğundan emin olun
- Farklı port kullanmak için
--portparametresini değiştirin
-
Konfigürasyon Hatası
config.jsondosyasının doğru formatta olduğundan emin olun- JSON syntax'ını kontrol edin
-
Cursor MCP Bağlantı Sorunu
- Server'ın çalıştığından emin olun
- URL'nin doğru olduğunu kontrol edin
- Cursor'u yeniden başlatın
Logları kontrol etmek için:
# HTTP server logları
tail -f logs/fortigate_mcp.log
# Docker logları
docker-compose logs -f fortigate-mcp-server-
API Token Kullanın
- Kullanıcı adı/şifre yerine API token kullanın
- Token'ları güvenli şekilde saklayın
-
SSL Sertifikası
- Üretim ortamında SSL sertifikası kullanın
verify_ssl: trueyapın
-
Ağ Güvenliği
- MCP server'ı sadece güvenli ağlarda çalıştırın
- Firewall kuralları ile erişimi kısıtlayın
-
Rate Limiting
- Rate limiting'i etkinleştirin
- API çağrılarını sınırlayın
- Fork yapın
- Feature branch oluşturun (
git checkout -b feature/amazing-feature) - Değişikliklerinizi commit edin (
git commit -m 'Add amazing feature') - Branch'inizi push edin (
git push origin feature/amazing-feature) - Pull request gönderin
Bu proje MIT lisansı altında lisanslanmıştır. Detaylar için LICENSE dosyasına bakın.
- FastMCP - MCP HTTP transport için
- FortiGate API - FortiGate entegrasyonu için
- Cursor - MCP desteği için
Sorunlarınız için:
- Issues sayfasını kullanın
- Dokümantasyonu kontrol edin
- Logları inceleyin
Not: Bu proje FortiGate cihazlarıyla test edilmiştir. Üretim ortamında kullanmadan önce kapsamlı test yapın.