Commit b70a9f6b authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: fix MCP dialog values silently discarded on submit

The registry entry is cleared by submitCurrent() (and again by
showDialog()) BEFORE applyCltDialog() runs the getNext*() reads, so
getValueOrDefault() - which looked the session up via the registry -
always saw null and fell back to every field's default: any value set
via POST /mcp/dialog/values was silently lost and OK re-applied the
loaded config. The dialog now keeps its OWN session reference for the
reads and the await; the registry cleanup clears only its own session
(covers the timeout path without clobbering a newer dialog).
Co-Authored-By: 's avatarClaude Fable 5 <noreply@anthropic.com>
parent b056e1a5
...@@ -38,6 +38,7 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{ ...@@ -38,6 +38,7 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{
private static long dialogTimeoutMs = 30000L; private static long dialogTimeoutMs = 30000L;
public boolean mcp_mode = false; public boolean mcp_mode = false;
private boolean mcpCanceled = false; private boolean mcpCanceled = false;
private McpDialogSession mcpSession = null; // this dialog's OWN session: the registry is cleared on submit BEFORE the getNext*() reads run, so reads must not go through it // By Claude on 07/07/2026
private final List<McpDialogField> mcpFields = new ArrayList<McpDialogField>(); private final List<McpDialogField> mcpFields = new ArrayList<McpDialogField>();
private final String dialogTitle; private final String dialogTitle;
private String currentTab = ""; private String currentTab = "";
...@@ -192,7 +193,8 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{ ...@@ -192,7 +193,8 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{
if (mcp_mode) { if (mcp_mode) {
// codex 2026-01-25: publish dialog schema to MCP registry // codex 2026-01-25: publish dialog schema to MCP registry
readIndex = 0; readIndex = 0;
boolean applied = McpDialogRegistry.setCurrent(new McpDialogSession(dialogTitle, mcpFields)); mcpSession = new McpDialogSession(dialogTitle, mcpFields); // By Claude on 07/07/2026: keep own reference (see field comment)
boolean applied = McpDialogRegistry.setCurrent(mcpSession);
if (!applied) { if (!applied) {
System.out.println("MCP: dialog already active, ignoring \"" + dialogTitle + "\""); System.out.println("MCP: dialog already active, ignoring \"" + dialogTitle + "\"");
} }
...@@ -218,7 +220,7 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{ ...@@ -218,7 +220,7 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{
} }
private String getValueOrDefault(McpDialogField field) { private String getValueOrDefault(McpDialogField field) {
McpDialogSession session = McpDialogRegistry.getCurrent(); McpDialogSession session = mcpSession; // By Claude on 07/07/2026: was McpDialogRegistry.getCurrent() - always null here (registry cleared on submit before the reads), so /mcp/dialog/values was silently discarded
if (session != null && field != null) { if (session != null && field != null) {
String value = session.getValue(field.label); String value = session.getValue(field.label);
if (value != null) { if (value != null) {
...@@ -299,7 +301,7 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{ ...@@ -299,7 +301,7 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{
public boolean showDialog() { public boolean showDialog() {
if (mcp_mode) { if (mcp_mode) {
buildDialog(); buildDialog();
McpDialogSession session = McpDialogRegistry.getCurrent(); McpDialogSession session = mcpSession; // By Claude on 07/07/2026: own session (registry may hold another dialog / be cleared by submit)
if (session != null) { if (session != null) {
long timeout = dialogTimeoutMs; long timeout = dialogTimeoutMs;
Boolean ok = (timeout <= 0) ? session.awaitSubmit(Long.MAX_VALUE) : session.awaitSubmit(timeout); Boolean ok = (timeout <= 0) ? session.awaitSubmit(Long.MAX_VALUE) : session.awaitSubmit(timeout);
...@@ -309,7 +311,9 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{ ...@@ -309,7 +311,9 @@ public class GenericJTabbedDialogMcp extends GenericJTabbedDialog{
mcpCanceled = false; mcpCanceled = false;
} }
} }
McpDialogRegistry.setCurrent(null); if (McpDialogRegistry.getCurrent() == mcpSession) { // By Claude on 07/07/2026: clear only OUR session (submit normally cleared it; this covers the timeout path without clobbering a newer dialog)
McpDialogRegistry.setCurrent(null);
}
return true; return true;
} }
else return super.showDialog(); else return super.showDialog();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment