mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

fix(api): oauth offered as auth_type in Add Tool form but silently ignored by POST /tools and POST /admin/tools

Open marekdano opened this issue 5 months ago • 3 comments

Closes #5164

Summary

OAuth 2.0 appeared as a selectable authentication type in the Add Tool form, but submitting it was silently accepted with no effect — the tool was created with no authentication configured. This happens because ToolCreate and the Tool DB model have no oauth_config field; Pydantic silently drops unknown fields. OAuth on tools is inherited from the gateway the tool is registered under — the tool service reads gateway.oauth_config at invocation time. Direct OAuth configuration on a tool was never wired up, and _build_auth_obj_from_form in admin.py had no branch for oauth, so it returned None silently.

Changes

mcpgateway/templates/admin.html

Removed <option value="oauth">OAuth 2.0</option> from the Add Tool form (#add-tool-form). The option remains on gateway and A2A agent forms where OAuth is fully wired up.

mcpgateway/schemas.py

Added a field_validator on AuthenticationValues.auth_type that raises a ValueError (Pydantic 422) when auth_type is "oauth" (case-insensitive). This blocks POST /tools and POST /admin/tools API calls that submit auth_type=oauth.

mcpgateway/admin.py

Added an early HTTPException(422) in _build_auth_obj_from_form for auth_type == "oauth", covering the form-submission path.

Tests

  • test_admin.py: new test asserts _build_auth_obj_from_form raises 422 when auth_type=oauth
  • test_schemas.py: three new tests covering AuthenticationValues rejection of oauth (exact, case-insensitive, and valid-type acceptance)
  • test_tools_extended.py (Playwright): updated test_auth_type_options to assert oauth is not attached to the add-tool form and to serve as a regression guard

marekdano avatar Jun 11 '26 10:06 marekdano

Should we drop the option or add support to it? 🤔

gcgoncalves avatar Jun 11 '26 10:06 gcgoncalves

Should we drop the option or add support to it? 🤔

I'm dropping it from the admin UI now. If we support it on the API, we can bring it up.

marekdano avatar Jun 11 '26 11:06 marekdano

Should we drop the option or add support to it? 🤔

I'm dropping it from the admin UI now. If we support it on the API, we can bring it up.

Perfect. The code looks good, aproving! 🙇

gcgoncalves avatar Jun 11 '26 12:06 gcgoncalves