@@ -37,6 +37,7 @@ import {
3737} from "@t3tools/client-runtime/state/thread-settled" ;
3838import {
3939 codexFeedbackMessage ,
40+ isReconnectMcpCommand ,
4041 parseCodexFeedbackCommand ,
4142 submitCodexFeedback ,
4243 type CodexFeedbackSubmission ,
@@ -1311,6 +1312,9 @@ function ChatViewContent(props: ChatViewProps) {
13111312 reportFailure : false ,
13121313 } ) ;
13131314 const startThreadTurn = useAtomCommand ( threadEnvironment . startTurn , { reportFailure : false } ) ;
1315+ const stopThreadSession = useAtomCommand ( threadEnvironment . stopSession , {
1316+ reportFailure : false ,
1317+ } ) ;
13141318 const createAttachmentAssetUrl = useAtomQueryRunner ( assetEnvironment . createUrl , {
13151319 reportFailure : false ,
13161320 } ) ;
@@ -5554,6 +5558,86 @@ function ChatViewContent(props: ChatViewProps) {
55545558 composerPreviewAnnotations . length +
55555559 composerReviewComments . length ,
55565560 } ) ;
5561+ const reconnectMcpCommand =
5562+ ctxSelectedProvider === "codex" &&
5563+ composerImages . length === 0 &&
5564+ composerFiles . length === 0 &&
5565+ sendableComposerTerminalContexts . length === 0 &&
5566+ composerElementContexts . length === 0 &&
5567+ composerPreviewAnnotations . length === 0 &&
5568+ composerReviewComments . length === 0 &&
5569+ isReconnectMcpCommand ( trimmed ) ;
5570+ if ( reconnectMcpCommand ) {
5571+ if (
5572+ ! isServerThread ||
5573+ activeThread . session === null ||
5574+ activeThread . session . providerName !== "codex"
5575+ ) {
5576+ toastManager . add (
5577+ stackedThreadToast ( {
5578+ type : "warning" ,
5579+ title : "Start a Codex thread first" ,
5580+ description : "Send a message before reconnecting its MCP servers." ,
5581+ } ) ,
5582+ ) ;
5583+ return ;
5584+ }
5585+ if ( activeThread . session . status === "starting" || activeThread . session . status === "running" ) {
5586+ toastManager . add (
5587+ stackedThreadToast ( {
5588+ type : "warning" ,
5589+ title : "Codex is still working" ,
5590+ description : "Wait for the current turn to finish, then reconnect MCP servers." ,
5591+ } ) ,
5592+ ) ;
5593+ return ;
5594+ }
5595+ sendInFlightRef . current = true ;
5596+ promptRef . current = "" ;
5597+ clearComposerDraftContent ( composerDraftTarget ) ;
5598+ composerRef . current ?. resetCursorState ( ) ;
5599+ const result = await stopThreadSession ( {
5600+ environmentId,
5601+ input : { threadId : activeThread . id , onlyIfIdle : true } ,
5602+ } ) . finally ( ( ) => {
5603+ sendInFlightRef . current = false ;
5604+ } ) ;
5605+ if ( result . _tag === "Failure" ) {
5606+ if (
5607+ promptRef . current . length === 0 &&
5608+ composerImagesRef . current . length === 0 &&
5609+ composerFilesRef . current . length === 0 &&
5610+ composerTerminalContextsRef . current . length === 0 &&
5611+ composerElementContextsRef . current . length === 0
5612+ ) {
5613+ promptRef . current = promptForSend ;
5614+ setComposerDraftPrompt ( composerDraftTarget , promptForSend ) ;
5615+ composerRef . current ?. resetCursorState ( {
5616+ cursor : collapseExpandedComposerCursor ( promptForSend , promptForSend . length ) ,
5617+ prompt : promptForSend ,
5618+ detectTrigger : true ,
5619+ } ) ;
5620+ }
5621+ if ( ! isAtomCommandInterrupted ( result ) ) {
5622+ toastManager . add (
5623+ stackedThreadToast ( {
5624+ type : "error" ,
5625+ title : "Could not reconnect MCP servers" ,
5626+ description : chatActionErrorMessage ( squashAtomCommandFailure ( result ) ) ,
5627+ } ) ,
5628+ ) ;
5629+ }
5630+ return ;
5631+ }
5632+ toastManager . add (
5633+ stackedThreadToast ( {
5634+ type : "success" ,
5635+ title : "MCP servers disconnected" ,
5636+ description : "They will reconnect with fresh tool schemas on your next message." ,
5637+ } ) ,
5638+ ) ;
5639+ return ;
5640+ }
55575641 const feedbackCommand =
55585642 ctxSelectedProvider === "codex" &&
55595643 composerImages . length === 0 &&
0 commit comments