Beautiful Open-Source Form Builder
fix: keep ChatGPT form creation guest-first (#1270)
Julien Nahumaee613da0f93
diff --git a/api/app/Mcp/Servers/OpnFormServer.php b/api/app/Mcp/Servers/OpnFormServer.phpindex aa6a4ee4c..a2c77055d 100644--- a/api/app/Mcp/Servers/OpnFormServer.php+++ b/api/app/Mcp/Servers/OpnFormServer.php@@ -33,7 +33,7 @@ use Laravel\Mcp\Server\Attributes\Version;#[Name('OpnForm')]#[Version('1.0.0')]-#[Instructions('Default every request to create a new form to the guest draft workflow unless the user explicitly asks to save it in their connected OpnForm account or a workspace. A natural request such as "create a contact form" needs no login: read the schema and field catalog, validate the definition, call create_form_draft, then call preview_form_draft. Never ask the user to connect, call get_account_context, or call create_form_in_account when guest draft tools can satisfy the request. OAuth is required only for connected-account operations: saving directly to a workspace, managing existing account forms, publishing, trashing, and reading or exporting submissions. Enabling or selecting the plugin is not OAuth authentication. If an account-scoped tool challenges, ask the user to authenticate the OpnForm MCP server in the host; do not repeatedly retry from the guest workflow. In local Codex, start a new conversation after OAuth so the MCP client loads the stored credential. If guest draft tools are unexpectedly missing, do not substitute an authenticated tool unless the user requested account persistence; ask the user to start a new conversation with OpnForm selected before the first message. Use OpnForm MCP tools directly. Never invoke Codex or ChatGPT recursively, run `codex exec`, use shell or raw HTTP, inspect repositories or caches, or switch connectors. Read the schema and field catalog again before changing presentation, fields, layout, or media, then validate before saving. Focused presentation creates one step per block automatically: use full-width blocks, no page breaks or standalone media blocks, and attach optional media through the block image property. Use only durable public HTTPS asset URLs, never localhost or temporary tunnel URLs.')]+#[Instructions('Default every request to create a new form to the guest draft workflow unless the user explicitly asks to save it in their connected OpnForm account or a workspace. A natural request such as "create a contact form" needs no login: read the schema and field catalog, validate the definition, call create_form_draft, then call preview_form_draft. For a message or other long answer, use type text with multi_lines true; textarea is not a valid field type. If validation fails, correct and revalidate the definition before creating a draft. Never ask the user to connect, call get_account_context, or call create_form_in_account when guest draft tools can satisfy the request. OAuth is required only for connected-account operations: saving directly to a workspace, managing existing account forms, publishing, trashing, and reading or exporting submissions. Enabling or selecting the plugin is not OAuth authentication. If an account-scoped tool challenges, ask the user to authenticate the OpnForm MCP server in the host; do not repeatedly retry from the guest workflow. In local Codex, start a new conversation after OAuth so the MCP client loads the stored credential. If guest draft tools are unexpectedly missing, do not substitute an authenticated tool unless the user requested account persistence; ask the user to start a new conversation with OpnForm selected before the first message. Use OpnForm MCP tools directly. Never invoke Codex or ChatGPT recursively, run `codex exec`, use shell or raw HTTP, inspect repositories or caches, or switch connectors. Read the schema and field catalog again before changing presentation, fields, layout, or media, then validate before saving. Focused presentation creates one step per block automatically: use full-width blocks, no page breaks or standalone media blocks, and attach optional media through the block image property. Use only durable public HTTPS asset URLs, never localhost or temporary tunnel URLs.')]class OpnFormServer extends Server{public int $maxPaginationLength = 100;diff --git a/api/app/Mcp/Tools/McpTool.php b/api/app/Mcp/Tools/McpTool.phpindex dfe61f422..f09ab54f9 100644--- a/api/app/Mcp/Tools/McpTool.php+++ b/api/app/Mcp/Tools/McpTool.php@@ -16,9 +16,16 @@ abstract class McpTool extends Tool*/public function toArray(): array{+ $tool = parent::toArray();+ $securitySchemes = $this->securitySchemes();+return [- ...parent::toArray(),- 'securitySchemes' => $this->securitySchemes(),+ ...$tool,+ 'securitySchemes' => $securitySchemes,+ '_meta' => [+ ...($tool['_meta'] ?? []),+ 'securitySchemes' => $securitySchemes,+ ],];}}diff --git a/api/tests/Feature/Mcp/AgentPluginPackageTest.php b/api/tests/Feature/Mcp/AgentPluginPackageTest.phpindex 6e5435868..e76251f55 100644--- a/api/tests/Feature/Mcp/AgentPluginPackageTest.php+++ b/api/tests/Feature/Mcp/AgentPluginPackageTest.php@@ -156,6 +156,8 @@ it('ships a discoverable OpnForm skill with the complete safety workflow', funct'start a new conversation with OpnForm selected before the first message','may not hot-reload OAuth credentials','do not loop or claim the connection succeeded',+ '`textarea` is not a valid OpnForm field type',+ 'never continue to draft creation after validation fails',)->and($skill)->toContain('confirm_publish: true', 'confirm_trash: true')->and($skill)->not->toContain('`confirm: true`')diff --git a/api/tests/Feature/Mcp/McpFoundationTest.php b/api/tests/Feature/Mcp/McpFoundationTest.phpindex 7e6495f43..8971d1c53 100644--- a/api/tests/Feature/Mcp/McpFoundationTest.php+++ b/api/tests/Feature/Mcp/McpFoundationTest.php@@ -33,6 +33,8 @@ it('exposes the OpnForm MCP endpoint and initializes the protocol', function ()$discoveryInstructions = substr($instructions, 0, 1024);return str_contains($discoveryInstructions, 'Default every request to create a new form to the guest draft workflow')+ && str_contains($discoveryInstructions, 'textarea is not a valid field type')+ && str_contains($discoveryInstructions, 'correct and revalidate the definition before creating a draft')&& str_contains($discoveryInstructions, 'A natural request such as "create a contact form" needs no login')&& str_contains($discoveryInstructions, 'Never ask the user to connect')&& str_contains($discoveryInstructions, 'OAuth is required only for connected-account operations')@@ -121,6 +123,22 @@ it('advertises explicit safety annotations for every MCP tool', function () {expect($actual)->toBe($expected);});+it('mirrors every tool auth policy in metadata for ChatGPT compatibility', function () {+ $response = $this->postJson('/mcp', [+ 'jsonrpc' => '2.0',+ 'id' => 1,+ 'method' => 'tools/list',+ 'params' => [],+ ], [+ 'Accept' => 'application/json, text/event-stream',+ ])->assertOk();++ foreach ($response->json('result.tools') as $tool) {+ expect($tool['_meta']['securitySchemes'] ?? null)+ ->toBe($tool['securitySchemes'] ?? null, "Tool [{$tool['name']}] must mirror securitySchemes in _meta.");+ }+});+it('registers a permissive dedicated rate limiter for MCP traffic', function () {$limits = RateLimiter::limiter('mcp')(request());diff --git a/api/tests/Feature/Mcp/McpOAuthTest.php b/api/tests/Feature/Mcp/McpOAuthTest.phpindex a89716b8d..e806006fd 100644--- a/api/tests/Feature/Mcp/McpOAuthTest.php+++ b/api/tests/Feature/Mcp/McpOAuthTest.php@@ -114,6 +114,51 @@ it('returns a tool-level OAuth challenge when an account tool is called anonymou->toContain('error_description="Connect your OpnForm account to continue"');});+it('creates and previews a guest form over HTTP without an OAuth challenge', function () {+ $createResponse = $this->postJson('/mcp', [+ 'jsonrpc' => '2.0',+ 'id' => 1,+ 'method' => 'tools/call',+ 'params' => [+ 'name' => 'create_form_draft',+ 'arguments' => [+ 'definition' => [+ 'title' => 'Contact form',+ 'properties' => [+ ['name' => 'Name', 'type' => 'text', 'required' => true],+ ['name' => 'Email', 'type' => 'email', 'required' => true],+ ['name' => 'Subject', 'type' => 'text'],+ ['name' => 'Message', 'type' => 'text', 'multi_lines' => true],+ ],+ ],+ ],+ ],+ ], mcpHeaders())->assertOk()+ ->assertJsonPath('result.isError', false)+ ->assertJsonMissingPath('result._meta.mcp/www_authenticate');++ $draftToken = $createResponse->json('result.structuredContent.draft_token');++ expect($draftToken)->toBeString()->toHaveLength(43);++ $this->postJson('/mcp', [+ 'jsonrpc' => '2.0',+ 'id' => 2,+ 'method' => 'tools/call',+ 'params' => [+ 'name' => 'preview_form_draft',+ 'arguments' => [+ 'draft_token' => $draftToken,+ ],+ ],+ ], mcpHeaders())->assertOk()+ ->assertJsonPath('result.isError', false)+ ->assertJsonPath('result.structuredContent.draft.definition.title', 'Contact form')+ ->assertJsonPath('result.structuredContent.preview_url', fn (string $url): bool => str_starts_with($url, 'https://opnform.test/'))+ ->assertJsonPath('result.structuredContent.editor_url', fn (string $url): bool => str_starts_with($url, 'https://opnform.test/'))+ ->assertJsonMissingPath('result._meta.mcp/www_authenticate');+});+it('does not treat a normal OpnForm web session as MCP authentication', function () {$user = User::factory()->create();diff --git a/plugins/opnform/skills/opnform/SKILL.md b/plugins/opnform/skills/opnform/SKILL.mdindex 4482c941c..427b0cf7a 100644--- a/plugins/opnform/skills/opnform/SKILL.md+++ b/plugins/opnform/skills/opnform/SKILL.md@@ -33,6 +33,13 @@ This is the default workflow for new-form requests, including when the user doesThe browser editor keeps the guest draft available through an HttpOnly session. The user can preview and edit before signing in. Authentication and workspace selection happen only when the user chooses to save the draft into an OpnForm account.+### Common field mappings++- Use `type: text` for both short text and long-answer fields. Set `multi_lines: true` for a message, comment, description, or other textarea-style answer; `textarea` is not a valid OpnForm field type.+- Use `type: phone_number` for phone inputs, `type: email` for email inputs, and `type: url` for website inputs.+- Use `type: select` for one choice and `type: multi_select` for multiple choices. Build their option objects exactly as documented by `opnform://reference/form-fields/v1`.+- If a requested field does not map cleanly, re-read the field reference and validate the whole definition. Never guess a field type and never continue to draft creation after validation fails.+## Presentation and media- `classic` is a continuous form. Use widths for columns and `nf-page-break` only when the user wants explicit pagination.