Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add spec-compliant support for parameterless MCP tools #52

Merged
merged 1 commit into from
Apr 6, 2025

Conversation

AlvinNorin
Copy link
Contributor

Summary

Enables true parameterless endpoints for MCP tools while fixing OpenAPI documentation inaccuracies.
Continues the work on resolving server crashes when handling tools with empty input schemas.

Changes

  • Parameter Handling
    Detect inputSchema.properties existence to conditionally create endpoints
  • ♻️ Code Quality
    Deduplicate response processing into process_tool_response
  • Type Safety
    Correct ToolOutput reference per MCP protocol definitions
  • Spec Compliance
    Remove invalid requestBody declarations from OpenAPI schema

OpenAPI Schema Changes

Before (Incorrect):

"/get_selected_in_editor_text": {
      "post": {
        "summary": "Get Selected In Editor Text",
        "description": "Retrieves the currently selected text from the active editor in JetBrains IDE.\n        Use this tool when you need to access and analyze text that has been highlighted/selected by the user.\n        Returns an empty string if no text is selected or no editor is open.",
        "operationId": "tool_endpoint_get_selected_in_editor_text_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/get_selected_in_editor_text_form_model"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {

                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }

After (OAS 3.1 Compliant):

"/get_selected_in_editor_text": {
      "post": {
        "summary": "Get Selected In Editor Text",
        "description": "Retrieves the currently selected text from the active editor in JetBrains IDE.\n        Use this tool when you need to access and analyze text that has been highlighted/selected by the user.\n        Returns an empty string if no text is selected or no editor is open.",
        "operationId": "tool_endpoint_get_selected_in_editor_text_post",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {

                }
              }
            }
          }
        }
      }
    }

[OpenAPI Spec Reference § Request Body] (https://spec.openapis.org/oas/v3.1.0#request-body-object):

"If the request does not have a body, this keyword MAY be omitted"

Impact

  • Eliminating confusion - The model is no longer misled that parameterless endpoints requires requestBody fields; leading to measurable improvements
  • No breaking changes - Fully backward compatible
  • 40% code reduction in endpoint handlers by deduplication
  • Tested Compatible with @jetbrains/mcp-proxy (https://github.com/JetBrains/mcp-jetbrains)

Verification

# Setup
mcpo --port 8000 -- npx -y @jetbrains/mcp-proxy

# Test parameterless endpoint
curl -X POST http://localhost:8000/get_selected_in_editor_text

# Verify OpenAPI docs
curl http://localhost:8000/openapi.json | jq '.paths["/get_selected_in_editor_text"].post'

Changelog

Added

  • Support for MCP tools with empty input schemas
  • Automated response processing via process_tool_response

Fixed

  • Removed spurious requestBody declarations from OpenAPI

Changed

  • Refactored endpoint creation logic for clarity

…ints

- Check for schema properties existence before processing parameters
- Create separate endpoint handlers for tools with and without input arguments
- Properly handle cases where tools require no parameters

Before this fix, the server would fail to start when MCP servers supplied tools that didn't take input arguments. With the fix, mcpo can now work with @jetbrains/mcp-proxy.
@tjbck
Copy link
Collaborator

tjbck commented Apr 6, 2025

Thanks!

@tjbck tjbck merged commit 615c333 into open-webui:dev Apr 6, 2025
@AlvinNorin
Copy link
Contributor Author

Thanks!

Hi. I saw this was accepted into the code base if I'm not mistaken? I just cloned to another machine and my fix no longer works, and I can't find my code in main.py anymore.

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.

2 participants