mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
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.
This commit is contained in:
1 parent
c95046c2f9
commit
48491a94a6
13 files changed
+76
-5
No files matched your search
@@ -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}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
),
|
||||
]
|
||||
@@ -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")
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) |
|
||||
|
||||
Reference in new issue
Block a user