sgp-mcp-server

thiagojbs/sgp-mcp-server

3.2

If you are the rightful owner of sgp-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The SGP MCP Server is a Model Context Protocol server designed to integrate seamlessly with the SGP API, providing comprehensive ISP management capabilities through both MCP and HTTP interfaces.

Tools
  1. sgp_get_customer_contracts

    Get customer contracts

  2. sgp_get_contract_details

    Get specific contract details

  3. sgp_get_customer_invoices

    Get customer invoices

  4. sgp_get_invoice_details

    Get specific invoice details

  5. sgp_generate_second_copy

    Generate invoice second copy

  6. sgp_get_support_tickets

    Get customer support tickets

  7. sgp_create_support_ticket

    Create new support ticket

  8. sgp_list_onus

    List ONUs with pagination

  9. sgp_get_onu_details

    Get ONU details

  10. sgp_provision_onu

    Provision an ONU

  11. sgp_deprovision_onu

    Deprovision an ONU

  12. sgp_restart_onu

    Restart an ONU

  13. sgp_get_onu_status

    Get ONU status

  14. sgp_list_olts

    List OLTs

  15. sgp_get_network_status

    Get overall network status

  16. sgp_list_products

    List products

  17. sgp_generate_invoice_batch

    Generate invoice batch

  18. sgp_process_return_file

    Process bank return file

SGP MCP Server

A comprehensive Model Context Protocol (MCP) server for integrating with SGP (Sistema de GestΓ£o para Provedores) API. This production-ready server provides complete access to SGP's ISP management capabilities through both MCP and HTTP interfaces.

Created by: Thiago Barroncas ()

Version 2.0.0 Features

  • πŸ” Multi-Protocol Authentication: Basic Auth, Token Auth, and CPF/CNPJ Auth
  • πŸš€ Advanced Rate Limiting: Per-authentication-method rate limiting (100/300/50 req/min)
  • πŸ’Ύ Intelligent Caching: TTL-based caching system with configurable expiration
  • πŸ”„ Retry Logic: Exponential backoff for failed requests with circuit breaker
  • πŸ“Š Enterprise Logging: Winston-based structured logging with multiple levels
  • 🌐 Dual Interface: Complete HTTP API and MCP server implementation
  • πŸ—οΈ 10 Business Systems: 327+ methods across all SGP modules
  • πŸ“ˆ 95% API Coverage: Comprehensive integration with SGP platform
  • πŸ›‘οΈ Production Security: Input validation, error handling, and secure configuration

Quick Start

Installation

git clone https://github.com/thiagojbs/sgp-mcp-server.git
cd sgp-mcp-server
npm install

Configuration

  1. Copy the environment template:
cp .env.example .env
  1. Configure your SGP credentials in .env:
SGP_BASE_URL=https://demo.sgp.net.br/api
SGP_USERNAME=your_username
SGP_PASSWORD=your_password
SGP_API_TOKEN=your_api_token
SGP_APP_NAME=sgp-mcp-server

Running the Server

As MCP Server (for automation integration)
npm run build
npm start
As HTTP Server (for direct API access)
npm run build
node dist/http/index.js
Development Mode
# MCP Server
npm run dev

# HTTP Server
npm run dev -- src/http/index.ts

API Documentation

Business Systems & Tools

The server provides 219+ tools organized across 10 comprehensive business systems:

1. Core Customer & Financial Management (18 tools)
  • sgp_get_customer_contracts - Get customer contracts
  • sgp_get_contract_details - Get specific contract details
  • sgp_get_customer_invoices - Get customer invoices
  • sgp_get_invoice_details - Get detailed invoice information
  • sgp_generate_second_copy - Generate invoice second copy
  • sgp_create_support_ticket - Create new support tickets
  • sgp_get_support_tickets - List customer support tickets
  • sgp_generate_invoice_batch - Generate bank remittance
  • sgp_process_return_file - Process bank return files
  • sgp_get_ura_* - URA/IVR system integration tools
2. Advanced Inventory Management (25 tools)
  • sgp_list_products - Complete product catalog
  • sgp_get_product_details - Detailed product information
  • sgp_get_inventory_summary - Stock level overview
  • sgp_create_stock_movement - Inventory transactions
  • sgp_get_stock_movements - Movement history
  • sgp_update_stock_levels - Bulk stock updates
  • sgp_manage_suppliers - Vendor management
  • sgp_track_serials - Serial number tracking
  • sgp_generate_inventory_reports - Stock analytics
3. Network Infrastructure Management (21 tools)
  • sgp_list_onus - ONU device listing with pagination
  • sgp_get_onu_details - Comprehensive ONU information
  • sgp_provision_onu - Network device provisioning
  • sgp_deprovision_onu - Device decommissioning
  • sgp_restart_onu - Remote device restart
  • sgp_get_onu_status - Real-time status monitoring
  • sgp_list_olts - OLT equipment management
  • sgp_get_network_status - Network health monitoring
  • sgp_manage_ftth_infrastructure - Fiber infrastructure
4. RADIUS Advanced System (21 tools)
  • sgp_get_radius_users - RADIUS user management
  • sgp_create_radius_user - User provisioning
  • sgp_update_radius_user - User configuration updates
  • sgp_delete_radius_user - User deprovisioning
  • sgp_get_radius_sessions - Active session monitoring
  • sgp_disconnect_radius_session - Session termination
  • sgp_get_radius_groups - Group management
  • sgp_manage_radius_attributes - Attribute configuration
  • sgp_get_radius_accounting - Usage accounting
  • sgp_get_radius_statistics - Performance metrics
5. Document & Contract Management (18 tools)
  • sgp_get_document_templates - Contract templates
  • sgp_create_contract_document - Document generation
  • sgp_get_contract_documents - Document listing
  • sgp_update_contract_status - Status management
  • sgp_create_digital_signature - Electronic signatures
  • sgp_get_contract_addendum - Contract amendments
  • sgp_create_legal_notification - Legal documentation
  • sgp_approve_document - Approval workflow
  • sgp_renew_contract - Contract renewals
6. Analytics & Reporting System (16 tools)
  • sgp_get_system_statistics - System-wide metrics
  • sgp_generate_financial_report - Financial analytics
  • sgp_get_network_analytics - Network performance data
  • sgp_get_customer_analytics - Customer behavior insights
  • sgp_get_support_analytics - Support metrics
  • sgp_generate_revenue_forecast - Revenue projections
  • sgp_get_operational_kpis - Operational KPIs
  • sgp_get_geographic_analytics - Geographic distribution
7. External Integrations & APIs (14 tools)
  • sgp_configure_webhook - Webhook management
  • sgp_get_webhook_executions - Webhook monitoring
  • sgp_configure_external_api - Third-party integrations
  • sgp_configure_payment_gateway - Payment processing
  • sgp_configure_sms_provider - SMS notifications
  • sgp_configure_email_provider - Email services
  • sgp_integrate_bank_services - Banking integration
  • sgp_integrate_postal_services - Shipping services
8. Backup & Recovery System (12 tools)
  • sgp_create_backup - System backup creation
  • sgp_get_backup_status - Backup monitoring
  • sgp_restore_backup - Data restoration
  • sgp_schedule_backup - Automated backups
  • sgp_configure_backup_storage - Storage management
  • sgp_test_disaster_recovery - DR testing
  • sgp_create_system_snapshot - Point-in-time snapshots
9. Configuration & Personalization (10 tools)
  • sgp_get_system_configuration - System settings
  • sgp_update_system_configuration - Configuration updates
  • sgp_manage_user_preferences - User customization
  • sgp_configure_custom_fields - Field customization
  • sgp_customize_workflows - Process customization
  • sgp_configure_branding - Brand customization
10. Audit & Compliance System (8 tools)
  • sgp_get_audit_events - Audit trail access
  • sgp_create_compliance_rule - Compliance management
  • sgp_get_compliance_violations - Violation tracking
  • sgp_configure_data_retention - Data policies
  • sgp_manage_access_control - Security controls

HTTP API Usage

Base URL: http://localhost:3000

Get Customer Contracts
curl -X POST http://localhost:3000/mcp/tools/get_customer_contracts \\
  -H \"Content-Type: application/json\" \\
  -d '{
    \"cpfcnpj\": \"12345678900\",
    \"senha\": \"customer_password\"
  }'
List ONUs
curl -X POST http://localhost:3000/mcp/tools/list_onus \\
  -H \"Content-Type: application/json\" \\
  -d '{
    \"page\": 1,
    \"per_page\": 20
  }'
Create Support Ticket
curl -X POST http://localhost:3000/mcp/tools/create_support_ticket \\
  -H \"Content-Type: application/json\" \\
  -d '{
    \"cpfcnpj\": \"12345678900\",
    \"senha\": \"customer_password\",
    \"assunto\": \"Internet slow\",
    \"descricao\": \"Customer reports slow internet connection\"
  }'

MCP Integration

For MCP client applications, configure your client to connect to this server:

{
  \"mcpServers\": {
    \"sgp\": {
      \"command\": \"node\",
      \"args\": [\"/path/to/sgp-mcp-server/dist/index.js\"],
      \"env\": {
        \"SGP_BASE_URL\": \"https://demo.sgp.net.br/api\",
        \"SGP_API_TOKEN\": \"your_token\"
      }
    }
  }
}

Authentication Methods

1. Basic Authentication

Uses username and password for SGP admin access:

SGP_USERNAME=admin_user
SGP_PASSWORD=admin_password

2. Token Authentication

Uses API token for enhanced security:

SGP_API_TOKEN=your_api_token
SGP_APP_NAME=your_app_name

3. CPF/CNPJ Authentication

For customer portal access (passed in function calls):

{
  \"cpfcnpj\": \"12345678900\",
  \"senha\": \"customer_password\"
}

Rate Limits

  • Basic Auth: 100 requests/minute
  • Token Auth: 300 requests/minute
  • CPF/CNPJ Auth: 50 requests/minute

Caching

The server implements intelligent caching:

  • Default TTL: 5 minutes
  • Max Keys: 1000
  • Cache Keys: Automatically generated based on endpoint and parameters

Error Handling

  • Automatic retry with exponential backoff
  • Comprehensive error logging
  • Graceful degradation for rate limits
  • Clear error messages in API responses

Architecture & Implementation

Technical Specifications

  • Total Methods: 327+ API methods implemented
  • MCP Tools: 219+ tools across all business systems
  • Code Coverage: ~95% of SGP API functionality
  • TypeScript: Full type safety with 1,235+ interface definitions
  • Authentication: 3 methods with different rate limits
  • Caching: TTL-based with node-cache
  • Logging: Winston with structured logging
  • Error Handling: Comprehensive with retry logic

Project Structure

src/
β”œβ”€β”€ auth/              # Multi-protocol authentication
β”œβ”€β”€ client/            # SGP API client with retry logic
β”œβ”€β”€ http/              # HTTP server implementation
β”œβ”€β”€ mcp/               # MCP server with 219+ tools
β”œβ”€β”€ services/          # 327+ business logic methods
β”‚   └── sgp-service.ts # 6,547 lines of service methods
β”œβ”€β”€ types/             # 1,235+ TypeScript interfaces
β”‚   └── sgp.ts         # Complete type definitions
└── utils/             # Logging, caching, and utilities

Implementation Highlights

Business System Coverage
  • Inventory Management: 25 endpoints for complete stock control
  • RADIUS System: 21 endpoints for network authentication
  • Network Infrastructure: 21 endpoints for device management
  • Document Management: 18 endpoints for contract lifecycle
  • Analytics & Reporting: 16 endpoints for business intelligence
  • External Integrations: 14 endpoints for third-party services
  • Backup & Recovery: 12 endpoints for data protection
  • System Configuration: 10 endpoints for customization
  • Audit & Compliance: 8 endpoints for security and compliance

Building

npm run build

Testing

npm test

Linting

npm run lint
npm run format

Deployment

VPS Deployment

  1. Prepare server:
# Install Node.js 18+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# Install PM2 for process management
sudo npm install -g pm2
  1. Deploy application:
# Clone repository
git clone https://github.com/thiagojbs/sgp-mcp-server.git
cd sgp-mcp-server

# Install dependencies
npm install

# Build application
npm run build

# Configure environment
cp .env.example .env
# Edit .env with your credentials

# Create logs directory
mkdir -p logs

# Start with PM2
pm2 start dist/http/index.js --name sgp-mcp-server
pm2 startup
pm2 save
  1. Configure reverse proxy (Nginx):
server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}

Cloudflare Workers Deployment

For Cloudflare Workers deployment, see the cloudflare/ directory for Worker-specific implementation.

Production Features

Monitoring & Observability

  • Health Endpoints: GET /health with detailed system status
  • Structured Logging: Winston with configurable log levels
  • Performance Metrics: Built-in request/response timing
  • Error Tracking: Comprehensive error logging and categorization
  • PM2 Integration: Process monitoring with pm2 monit
  • Rate Limit Monitoring: Per-authentication-method tracking

Security & Compliance

  • Environment Configuration: All credentials via environment variables
  • Multi-Layer Authentication: Basic, Token, and CPF/CNPJ methods
  • Rate Limiting: Prevents abuse with per-method limits
  • Input Validation: Comprehensive parameter validation and sanitization
  • Error Sanitization: No sensitive data exposure in logs or responses
  • HTTPS Enforcement: SSL/TLS required in production environments
  • Audit Trail: Complete request/response logging for compliance

Performance Optimizations

  • Intelligent Caching: TTL-based caching reduces API calls
  • Connection Pooling: Efficient HTTP connection management
  • Retry Logic: Exponential backoff for resilient operations
  • Circuit Breaker: Prevents cascade failures
  • Memory Management: Optimized for long-running processes

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Commit changes: git commit -am 'Add new feature'
  4. Push to branch: git push origin feature/new-feature
  5. Submit a Pull Request

License

MIT License - see file for details.

Support

  • Documentation: Check /docs endpoint when server is running
  • Issues: Report bugs on GitHub Issues
  • API Reference: Visit /docs for complete API documentation

Examples

See the examples/ directory for:

  • MCP client integration examples
  • HTTP API usage examples
  • Authentication method examples
  • Error handling patterns

Changelog

Version 2.0.0 (Latest)

  • Major Release: Complete SGP API integration
  • 327+ Methods: Comprehensive business logic implementation
  • 219+ MCP Tools: Full Model Context Protocol support
  • 10 Business Systems: All major SGP modules covered
  • 95% API Coverage: Near-complete SGP functionality
  • Production Ready: Security, monitoring, and deployment features
  • TypeScript: Full type safety with 1,235+ interfaces

Version 1.0.0

  • Initial release with core functionality
  • Basic SGP API integration
  • MCP and HTTP server implementations
  • 16+ initial tools for essential operations

Technical Metrics

MetricValue
API Methods327+
MCP Tools219+
Business Systems10
TypeScript Interfaces1,235+
Lines of Code9,138+
API Coverage~95%
Authentication Methods3
Rate Limits100/300/50 req/min

Note: This is a production-ready open-source project for SGP API integration. Built with enterprise-grade security, monitoring, and scalability features. Not officially affiliated with SGP.