Skip to content

Conversation

kevalmahajan
Copy link
Member

@kevalmahajan kevalmahajan commented Jul 31, 2025

🐛 Bug-fix PR

closes #623

📌 Summary

A. In test tool panel:

  1. Default values are populated for all datatypes (str,integers,bool) automatically for the tool if present in tool configuration.
  2. Required fields are marked with red * mark.

B. In Tools Panel:

Issue: Tools were displayed in a random order, with tools from the same gateway scattered throughout the list. This made it difficult to locate all tools associated with a specific gateway.

Fix: Sorted list of tools

  1. Grouped tools with common gateway together
  2. And then sorted in alphabetical order of tool name

🧪 Verification

Check Command Status
Lint suite make lint
Unit tests make test
Coverage ≥ 90 % make coverage
Manual regression no longer fails steps / screenshots

📐 MCP Compliance (if relevant)

  • Matches current MCP spec
  • No breaking change to MCP clients

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • No secrets/credentials committed

Signed-off-by: Keval Mahajan <[email protected]>
Copy link
Member

@crivetimihai crivetimihai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing

  • make doctest test lint-web flake8 ruff pylint

Summary

  • Improves sorting of tools in the Python backend for admin UI.
  • Enhances the form rendering in the admin UI for tool testing, with better handling for required fields, default values, and data types.

Python (mcpgateway/admin.py)

  • Admin UI Tool List Sorting:
    The tools shown in the admin UI are now sorted by their url (case-insensitive) and then by original_name (case-insensitive).
    tools = [
        tool.model_dump(by_alias=True)
        for tool in sorted(
            await tool_service.list_tools(db, include_inactive=include_inactive),
            key=lambda t: ((t.url or "").lower(), (t.original_name or "").lower())
        )
    ]

JavaScript (mcpgateway/static/admin.js)

  • Form Label Improvements:
    The label for each tool input now uses a <span> for the main text and appends a red asterisk (*) if the field is required.

  • Help Text:
    The help text remains unchanged, but comments clarify that no HTML escaping is needed.

  • Input Creation for Arrays:

    • Refactored array input handling for better readability and maintainability.
    • Now checks if the schema default is an array and pre-populates array inputs with those values.
  • Input Type Handling:

    • Improved handling for number, integer, and boolean types.
    • Uses optional chaining (prop.items?.type) for safer property access.
    • Boolean inputs (checkbox) set their checked state based on default values.
    • For other types, falls back to "text".
  • Default Values:

    • Default values from the schema are now set on inputs:
      • For checkboxes, the input is checked if the default is true.
      • For other inputs, the value is set directly.

Considerations

  1. Sorting Logic (Python):

    • Sorting by url and then original_name is reasonable, but if either of these fields can be None, the code uses or "" to avoid errors, which is good.
    • If users expect a different sorting order (by display name, for example), this could be surprising.
  2. Required Field Indicator (JS):

    • Adding a red asterisk is standard for required fields and improves UX.
    • Make sure that the required fields in the schema are always accurately reflected in schema.required.
  3. Default Values (JS):

    • Now, if a schema provides a default, the form pre-fills it.
    • Edge case: Some types (like objects or complex structures) might not render correctly if passed as default values (though not shown here).
  4. Type Handling (JS):

    • Support for "integer" type is added (treated as "number" inputs).
    • For array items, if the default array is empty or contains complex types, additional handling may be needed.
    • If the schema unexpectedly changes shape, the code may not handle deeply nested or edge-case schemas.
  5. Checkbox Defaults (JS):

    • Only checks for true. If the schema has a default of false, the checkbox will be unchecked, which is the expected behavior.

@crivetimihai crivetimihai merged commit 2f269c9 into main Jul 31, 2025
37 checks passed
@crivetimihai crivetimihai deleted the fill_default_values_test_tool branch July 31, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Display default values from input_schema in test tool screen
2 participants