Skip to content

[Bug]:Encoded DATABASE_URL causes configparser interpolation error #1533

@ESnark

Description

@ESnark

🐞 Bug Summary

When 'DATABASE_URL' contains URL-encoded '@' characters (e.g,. %40 for @), Alembic fails with a ValuError because Python's configparser treats % as an interpolation prefix.


🧩 Affected Component

Select the area of the project impacted:

  • mcpgateway - API
  • mcpgateway - UI (admin panel)
  • mcpgateway.wrapper - stdio wrapper
  • Federation or Transports
  • CLI, Makefiles, or shell scripts
  • Container setup (Docker/Podman/Compose)
  • Other (explain below)

🔁 Steps to Reproduce

  1. Set DATABASE_URL with a password containing %.
  2. Run the bootstrap script or start the application:
    python3 -m mcpgateway.bootstrap_db or python3 -m mcpgateway.

🤔 Expected Behavior

Both DATABASE_URL parsing and Database authentication should succeed.


📓 Logs / Error Output

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File ".../mcp-context-forge/mcpgateway/bootstrap_db.py", line 365, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File ".../mcp-context-forge/mcpgateway/bootstrap_db.py", line 261, in main
    cfg.set_main_option("sqlalchemy.url", settings.database_url)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../mcp-context-forge/.venv/lib/python3.13/site-packages/alembic/config.py", line 344, in set_main_option
    self.set_section_option(self.config_ini_section, name, value)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../mcp-context-forge/.venv/lib/python3.13/site-packages/alembic/config.py", line 377, in set_section_option
    self.file_config.set(section, name, value)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/configparser.py", line 1240, in set
    super().set(section, option, value)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/configparser.py", line 923, in set
    value = self._interpolation.before_set(self, section, option,
                                           value)
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/configparser.py", line 422, in before_set
    raise ValueError("invalid interpolation syntax in %r at "
                     "position %d" % (value, tmp_value.find('%')))
ValueError: invalid interpolation syntax in 'postgresql://****:{password}@{host}/{database}' at position 34

🧠 Environment Info

You can retrieve most of this from the /version endpoint.

Key Value
Version or commit v0.9.0
Runtime Python 3.13, Gunicorn
Platform / OS macOS
Container none

🧩 Additional Context (optional)

Add any configuration details, flags, or related issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageIssues / Features awaiting triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions