From 48491a94a6949925bdfc19e1566dbd6d5582d11e Mon Sep 17 00:00:00 2001 From: alamin-br Date: Fri, 16 Oct 2026 10:55:57 +0200 Subject: [PATCH] feat(mcp): send openWorldHint and serve the OpenAI apps challenge (#6395) OpenAI's ChatGPT app review needs all three tool hints set explicitly and fetches a domain verification token from /.well-known/openai-apps-challenge. --- Caddyfile | 2 +- backend/src/baserow/config/settings/base.py | 5 +++++ backend/src/baserow/core/mcp/oauth/urls.py | 11 ++++++++++- backend/src/baserow/core/mcp/oauth/views.py | 14 +++++++++++++- backend/src/baserow/core/mcp/registries.py | 4 ++++ .../database/mcp/test_mcp_tool_annotations.py | 2 ++ .../baserow/core/mcp/oauth/test_metadata.py | 16 ++++++++++++++++ .../baserow/core/mcp/test_mcp_streamable_http.py | 11 +++++++++-- .../mcp_openai_apps_directory_requirements.json | 9 +++++++++ docker-compose.no-caddy.yml | 1 + docker-compose.yml | 1 + docs/development/mcp-server.md | 4 ++++ docs/installation/configuration.md | 1 + 13 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 changelog/entries/unreleased/feature/mcp_openai_apps_directory_requirements.json diff --git a/Caddyfile b/Caddyfile index c668490cff..80884acd60 100644 --- a/Caddyfile +++ b/Caddyfile @@ -63,7 +63,7 @@ } handle @is_baserow_tool { - @backend_routes path /api/* /ws/* /mcp /mcp/* /oauth/* /.well-known/oauth-authorization-server* /.well-known/oauth-protected-resource* /assistant/* {$BASEROW_CADDY_BACKEND_EXTRA_ROUTES:} + @backend_routes path /api/* /ws/* /mcp /mcp/* /oauth/* /.well-known/oauth-authorization-server* /.well-known/oauth-protected-resource* /.well-known/openai-apps-challenge /assistant/* {$BASEROW_CADDY_BACKEND_EXTRA_ROUTES:} handle @backend_routes { reverse_proxy {$PRIVATE_BACKEND_URL:localhost:8000} } diff --git a/backend/src/baserow/config/settings/base.py b/backend/src/baserow/config/settings/base.py index dba8e7cba5..9beb9207a6 100644 --- a/backend/src/baserow/config/settings/base.py +++ b/backend/src/baserow/config/settings/base.py @@ -947,6 +947,11 @@ except ValueError as exc: f"separated list of rate limits, for example '10/m,60/h'. {exc}" ) from exc MCP_OAUTH_UNUSED_CLIENT_DAYS = 30 +# The domain verification token OpenAI shows when submitting the app. It's served +# at /.well-known/openai-apps-challenge. +BASEROW_MCP_OPENAI_APPS_CHALLENGE = ( + os.getenv("BASEROW_MCP_OPENAI_APPS_CHALLENGE") or "" +).strip() MCP_OAUTH_UNUSED_CIMD_CLIENT_DAYS = 1 # django-oauth-toolkit's migrations declare swappable dependencies on these settings, diff --git a/backend/src/baserow/core/mcp/oauth/urls.py b/backend/src/baserow/core/mcp/oauth/urls.py index c043325cfe..8cb1e906cf 100644 --- a/backend/src/baserow/core/mcp/oauth/urls.py +++ b/backend/src/baserow/core/mcp/oauth/urls.py @@ -4,7 +4,11 @@ from oauth2_provider import urls as oauth2_urls from .registration import MCPRegistrationView, RegistrationManagementNotOffered from .token_view import MCPRevokeTokenView, MCPTokenView -from .views import MCPAuthorizeRedirectView, MCPProtectedResourceMetadataView +from .views import ( + MCPAuthorizeRedirectView, + MCPProtectedResourceMetadataView, + openai_apps_challenge, +) oauth_patterns = [ path("authorize/", MCPAuthorizeRedirectView.as_view(), name="authorize"), @@ -51,4 +55,9 @@ urlpatterns = [ ) ), ), + path( + ".well-known/openai-apps-challenge", + openai_apps_challenge, + name="mcp-openai-apps-challenge", + ), ] diff --git a/backend/src/baserow/core/mcp/oauth/views.py b/backend/src/baserow/core/mcp/oauth/views.py index 26db3c47cd..bc3e65c5b2 100644 --- a/backend/src/baserow/core/mcp/oauth/views.py +++ b/backend/src/baserow/core/mcp/oauth/views.py @@ -2,7 +2,7 @@ import base64 from urllib.parse import urlencode from django.conf import settings -from django.http import HttpResponseRedirect +from django.http import Http404, HttpResponse, HttpResponseRedirect from django.views import View from oauth2_provider import cimd @@ -81,3 +81,15 @@ class MCPProtectedResourceMetadataView(OAuthProtectedResourceMetadataView): def get_scopes_supported(self): return [MCP_SCOPE] + + +def openai_apps_challenge(request): + """ + Returns the token OpenAI fetches to verify the domain of the MCP server, or a + 404 when it isn't set. + """ + + token = settings.BASEROW_MCP_OPENAI_APPS_CHALLENGE + if not token: + raise Http404() + return HttpResponse(token, content_type="text/plain") diff --git a/backend/src/baserow/core/mcp/registries.py b/backend/src/baserow/core/mcp/registries.py index 59cc37a39c..eb98f4da95 100644 --- a/backend/src/baserow/core/mcp/registries.py +++ b/backend/src/baserow/core/mcp/registries.py @@ -43,6 +43,9 @@ class MCPTool(Instance): destructive: bool = False """True when the tool can overwrite or delete data. Clients always confirm.""" + open_world: bool = False + """True when the tool reaches outside the endpoint's workspace.""" + @property def name(self) -> str: """MCP tool name, derived from ``type``.""" @@ -79,6 +82,7 @@ class MCPTool(Instance): title=self.display_title, readOnlyHint=self.read_only, destructiveHint=self.destructive, + openWorldHint=self.open_world, ) return [ Tool( diff --git a/backend/tests/baserow/contrib/database/mcp/test_mcp_tool_annotations.py b/backend/tests/baserow/contrib/database/mcp/test_mcp_tool_annotations.py index 5950a0cd3b..cf3542ef12 100644 --- a/backend/tests/baserow/contrib/database/mcp/test_mcp_tool_annotations.py +++ b/backend/tests/baserow/contrib/database/mcp/test_mcp_tool_annotations.py @@ -36,6 +36,7 @@ def test_enabled_tools_have_annotations(data_fixture): assert annotations.title assert annotations.readOnlyHint is read_only assert annotations.destructiveHint is destructive + assert annotations.openWorldHint is False @pytest.mark.django_db @@ -48,3 +49,4 @@ def test_all_registered_tools_are_annotated(data_fixture): assert mcp_tool_registry.get(name).title == tool.annotations.title assert tool.annotations.readOnlyHint is read_only assert tool.annotations.destructiveHint is destructive + assert tool.annotations.openWorldHint is False diff --git a/backend/tests/baserow/core/mcp/oauth/test_metadata.py b/backend/tests/baserow/core/mcp/oauth/test_metadata.py index 484e811ee5..fa05325b61 100644 --- a/backend/tests/baserow/core/mcp/oauth/test_metadata.py +++ b/backend/tests/baserow/core/mcp/oauth/test_metadata.py @@ -29,3 +29,19 @@ def test_protected_resource_metadata(client, settings): assert data["scopes_supported"] == ["mcp"] assert "offline_access" not in data["scopes_supported"] assert data["bearer_methods_supported"] == ["header"] + + +@pytest.mark.django_db +def test_openai_apps_challenge_returns_the_token(client, settings): + settings.BASEROW_MCP_OPENAI_APPS_CHALLENGE = "challenge-token" + response = client.get("/.well-known/openai-apps-challenge") + assert response.status_code == 200 + assert response["Content-Type"].startswith("text/plain") + assert response.content == b"challenge-token" + + +@pytest.mark.django_db +def test_openai_apps_challenge_is_not_found_without_a_token(client, settings): + settings.BASEROW_MCP_OPENAI_APPS_CHALLENGE = "" + response = client.get("/.well-known/openai-apps-challenge") + assert response.status_code == 404 diff --git a/backend/tests/baserow/core/mcp/test_mcp_streamable_http.py b/backend/tests/baserow/core/mcp/test_mcp_streamable_http.py index 9e11a9f09d..33e243d3b9 100644 --- a/backend/tests/baserow/core/mcp/test_mcp_streamable_http.py +++ b/backend/tests/baserow/core/mcp/test_mcp_streamable_http.py @@ -126,8 +126,15 @@ def test_endpoint_key_lists_tools(data_fixture): assert _post(INIT, endpoint.key).status_code == 200 response = _post(LIST, endpoint.key) assert response.status_code == 200 - names = [t["name"] for t in response.json()["result"]["tools"]] - assert "list_tables" in names + tools = {t["name"]: t for t in response.json()["result"]["tools"]} + assert "list_tables" in tools + # OpenAI's app review requires all three hints to be sent explicitly. + assert tools["list_tables"]["annotations"] == { + "title": "List tables", + "readOnlyHint": True, + "destructiveHint": False, + "openWorldHint": False, + } @pytest.mark.django_db(transaction=True) diff --git a/changelog/entries/unreleased/feature/mcp_openai_apps_directory_requirements.json b/changelog/entries/unreleased/feature/mcp_openai_apps_directory_requirements.json new file mode 100644 index 0000000000..3536154d33 --- /dev/null +++ b/changelog/entries/unreleased/feature/mcp_openai_apps_directory_requirements.json @@ -0,0 +1,9 @@ +{ + "type": "feature", + "message": "MCP tools declare that they don't reach outside the workspace, and BASEROW_MCP_OPENAI_APPS_CHALLENGE serves OpenAI's domain verification token for ChatGPT app submission", + "issue_origin": "github", + "issue_number": null, + "domain": "core", + "bullet_points": [], + "created_at": "2026-10-15" +} diff --git a/docker-compose.no-caddy.yml b/docker-compose.no-caddy.yml index e7a228d47b..6fded35076 100644 --- a/docker-compose.no-caddy.yml +++ b/docker-compose.no-caddy.yml @@ -139,6 +139,7 @@ x-backend-variables: BASEROW_MCP_OAUTH_AUTHORIZE_RATE_LIMITS: BASEROW_MCP_OAUTH_DCR_ENABLED: BASEROW_MCP_OAUTH_REGISTRATION_RATE_LIMITS: + BASEROW_MCP_OPENAI_APPS_CHALLENGE: BASEROW_ENABLE_OTEL: BASEROW_OTEL_LOG_LEVEL: BASEROW_OTEL_SLOW_REQUEST_THRESHOLD_SECONDS: diff --git a/docker-compose.yml b/docker-compose.yml index 748761b7cb..d36a030f2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -152,6 +152,7 @@ x-backend-variables: BASEROW_MCP_OAUTH_AUTHORIZE_RATE_LIMITS: BASEROW_MCP_OAUTH_DCR_ENABLED: BASEROW_MCP_OAUTH_REGISTRATION_RATE_LIMITS: + BASEROW_MCP_OPENAI_APPS_CHALLENGE: BASEROW_ENABLE_OTEL: BASEROW_OTEL_LOG_LEVEL: BASEROW_OTEL_SLOW_REQUEST_THRESHOLD_SECONDS: diff --git a/docs/development/mcp-server.md b/docs/development/mcp-server.md index 6ace8d5fdd..300d479bdf 100644 --- a/docs/development/mcp-server.md +++ b/docs/development/mcp-server.md @@ -88,6 +88,10 @@ claude mcp add --transport http baserow http://localhost:8000/mcp `ALLOW_LOCALHOST_LOOPBACK` is already on in the settings, so clients can use `http://localhost` redirect URIs. +### ChatGPT app domain verification + +OpenAI verifies the domain of a submitted ChatGPT app by fetching `/.well-known/openai-apps-challenge`. Set `BASEROW_MCP_OPENAI_APPS_CHALLENGE` to the token shown in OpenAI's portal and the backend returns it as plain text. When it's empty the route returns a 404. Like the other OAuth routes, it only exists with `BASEROW_MCP_OAUTH_ENABLED=true`. + ## Tools Some tools are currently disabled (`enabled = False`) and hidden from MCP clients. They will be enabled once users can control tool availability through the UI. diff --git a/docs/installation/configuration.md b/docs/installation/configuration.md index 9e02032a7f..4cc7760077 100644 --- a/docs/installation/configuration.md +++ b/docs/installation/configuration.md @@ -252,6 +252,7 @@ until you make a model available to Kuma and select it under **AI features**; se | BASEROW\_MCP\_OAUTH\_AUTHORIZE\_RATE\_LIMITS | Rate limits per client IP for the MCP OAuth authorization endpoint, as `calls/period` separated by commas. The IP is the first `X-Forwarded-For` entry, see [MCP OAuth sign-in](mcp-oauth.md). Defaults to `30/m,300/h`. | 30/m,300/h | | BASEROW\_MCP\_OAUTH\_DCR\_ENABLED | Set to `false` to stop MCP clients without a client metadata document (for example Cursor) from registering themselves. Defaults to `true`. | true | | BASEROW\_MCP\_OAUTH\_REGISTRATION\_RATE\_LIMITS | Rate limits per client IP for MCP OAuth client registration, as `calls/period` separated by commas. Defaults to `10/m,60/h`. | 10/m,60/h | +| BASEROW\_MCP\_OPENAI\_APPS\_CHALLENGE | The domain verification token OpenAI shows when you submit Baserow as a ChatGPT app. The backend serves it as plain text at `/.well-known/openai-apps-challenge` when MCP OAuth is enabled, and returns a 404 when it's empty. | | | BASEROW\_WAIT\_INSTEAD\_OF\_409\_CONFLICT\_ERROR | When updating or creating various resources in Baserow if another concurrent operation is ongoing (like a snapshot, duplication, import etc) which would be affected by your modification a 409 HTTP error will be returned. If you instead would prefer Baserow to not return a 409 and just block waiting until the operation finishes and then to perform the requested operation set this flag to any non-empty value. | | | BASEROW\_JOB\_CLEANUP\_INTERVAL\_MINUTES | How often the job cleanup task will run. | 5 | | BASEROW\_JOB\_EXPIRATION\_TIME\_LIMIT | How long before a Baserow job will be kept before being cleaned up. | 30 * 24 * 60 (24 days) |