Skip to content

[Bug]: API incorrectly shows version, use semantic version from __init__ #382

@crivetimihai

Description

@crivetimihai

Bug: API incorrectly shows hardcoded version "1.0.0" instead of semantic version from version

Summary

When UI is disabled (MCPGATEWAY_UI_ENABLED=False), the root API endpoint returns a hardcoded version "1.0.0" instead of using the semantic version from the __version__ variable. This causes version mismatch and inconsistency across the application. Example:

{"name":"MCP_Gateway","version":"1.0.0","description":"MCP_Gateway API - UI is disabled","ui_enabled":false,"admin_api_enabled":false}

Check test cases and other components that have a hard coded 1.0.0 version..

Affected Component

  • mcpgateway - API (main.py)
  • Federation/Discovery service (discovery.py)

Steps to Reproduce

  1. Set MCPGATEWAY_UI_ENABLED=False in environment variables
  2. Start the MCP Gateway
  3. Access the root endpoint (GET /)
  4. Observe the returned JSON shows "version": "1.0.0" regardless of actual version

Expected Behavior

The API should return the actual semantic version from __version__ variable, matching the version shown in other parts of the application (e.g., /version endpoint, wrapper server info).

Current Code (main.py)

from mcpgateway import __version__  # Already imported at the top

# ... later in the file ...

@app.get("/")
async def root_info():
    """
    Returns basic API information at the root path.
    ...
    """
    logger.info("UI disabled, serving API info at root path")
    return {
        "name": settings.app_name, 
        "version": "1.0.0",  # ❌ Hardcoded version
        "description": f"{settings.app_name} API - UI is disabled", 
        "ui_enabled": False, 
        "admin_api_enabled": ADMIN_API_ENABLED
    }

Fixed Code (main.py)

@app.get("/")
async def root_info():
    """
    Returns basic API information at the root path.
    ...
    """
    logger.info("UI disabled, serving API info at root path")
    return {
        "name": settings.app_name, 
        "version": __version__,  # ✅ Use imported __version__
        "description": f"{settings.app_name} API - UI is disabled", 
        "ui_enabled": False, 
        "admin_api_enabled": ADMIN_API_ENABLED
    }

Additional Instances Found

1. discovery.py - LocalDiscoveryService

# Current code (line ~66)
self._service_info = ServiceInfo(
    self._service_type,
    f"{settings.app_name}.{self._service_type}",
    addresses=[socket.inet_aton(addr) for addr in self._get_local_addresses()],
    port=settings.port,
    properties={
        "name": settings.app_name,
        "version": "1.0.0",  # ❌ Hardcoded version
        "protocol": PROTOCOL_VERSION,
    },
)

# Should be:
from mcpgateway import __version__  # Add import at top

# Then use:
properties={
    "name": settings.app_name,
    "version": __version__,  # ✅ Use imported __version__
    "protocol": PROTOCOL_VERSION,
}

Files to Check/Update

  1. main.py - root_info() function
  2. discovery.py - LocalDiscoveryService.init() method
  3. ❓ Any other files that might reference "1.0.0" as a version string

Impact

  • Version inconsistency between different endpoints
  • Misleading version information for API consumers
  • Difficult to track actual deployed version when UI is disabled
  • Service discovery broadcasts incorrect version information

Environment Info

  • Version: Issue present in current main branch
  • Component: mcpgateway API and discovery services

Additional Notes

The __version__ variable is already being correctly imported and used in other parts of the codebase (e.g., wrapper.py), so this fix aligns with existing patterns and ensures consistency across all version reporting.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpythonPython / backend development (FastAPI)triageIssues / Features awaiting triage

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions