@@ -7,7 +7,6 @@ import TelemetryReporter from '@vscode/extension-telemetry';
77import { exec } from 'child_process' ;
88import { promisify } from 'util' ;
99import * as vscode from 'vscode' ;
10- import which from 'which' ;
1110
1211const execAsync = promisify ( exec ) ;
1312
@@ -68,41 +67,47 @@ export class McpServerFeature {
6867 provideMcpServerDefinitions : ( ) => {
6968 return this . provideMcpServerDefinitions ( ) ;
7069 } ,
70+ resolveMcpServerDefinition : ( definition : McpServerDefinition ) => {
71+ return this . resolveMcpServerDefinition ( definition ) ;
72+ } ,
7173 } ) ;
7274 } catch ( error ) {
7375 this . logError ( 'Error registering MCP server provider' , error ) ;
7476 return undefined ;
7577 }
7678 }
7779
78- private async provideMcpServerDefinitions ( ) : Promise < McpServerDefinition [ ] > {
80+ // According to VS Code API docs, no user interaction should happen here
81+ // Just provide the available MCP server definitions
82+ private provideMcpServerDefinitions ( ) : McpServerDefinition [ ] {
7983 try {
80- const dockerAvailable = await this . dockerValidations ( ) ;
81- if ( ! dockerAvailable ) {
82- return [ ] ;
83- }
84-
8584 const server : McpServerDefinition = {
8685 label : 'HashiCorp Terraform MCP Server' ,
8786 command : 'docker' ,
8887 args : [ 'run' , '-i' , '--rm' , 'hashicorp/terraform-mcp-server' ] ,
8988 env : { } ,
9089 } ;
9190
92- this . showMcpServerInfoMessage ( ) ;
93-
9491 return [ server ] ;
9592 } catch ( error ) {
9693 this . logError ( 'Error providing MCP server definitions' , error ) ;
9794 return [ ] ;
9895 }
9996 }
97+
98+ // All user interactions should happen here
99+ // Should return resolved server definition if server should be started
100+ private async resolveMcpServerDefinition ( definition : McpServerDefinition ) : Promise < McpServerDefinition > {
101+ const dockerAvailable = await this . dockerValidations ( ) ;
102+ if ( ! dockerAvailable ) {
103+ throw new Error ( 'Docker is required but not available or running' ) ;
104+ }
105+
106+ return definition ;
107+ }
108+
100109 private async dockerValidations ( ) : Promise < boolean > {
101110 try {
102- if ( ! ( await this . checkDockerAvailability ( ) ) ) {
103- return false ;
104- }
105-
106111 if ( ! ( await this . checkDockerRunning ( ) ) ) {
107112 return false ;
108113 }
@@ -114,36 +119,16 @@ export class McpServerFeature {
114119 }
115120 }
116121
117- private async checkDockerAvailability ( ) : Promise < boolean > {
118- try {
119- await which ( 'docker' ) ;
120- return true ;
121- } catch {
122- void vscode . window
123- . showWarningMessage (
124- 'Docker is required to run the Terraform MCP Server. Please install Docker to use this feature.' ,
125- 'Learn More' ,
126- )
127- . then ( ( selection ) => {
128- if ( selection === 'Learn More' ) {
129- void vscode . env . openExternal ( vscode . Uri . parse ( 'https://docs.docker.com/get-docker/' ) ) ;
130- }
131- } ) ;
132- return false ;
133- }
134- }
135-
122+ // Check if container runtime is available and running
123+ // The 'docker info' command validates both installation and daemon status
136124 private async checkDockerRunning ( ) : Promise < boolean > {
137125 try {
138126 await execAsync ( 'docker info' , { timeout : 5000 } ) ;
139127 return true ;
140128 } catch ( error ) {
141129 this . logError ( 'Docker daemon check failed' , error ) ;
142130 void vscode . window
143- . showWarningMessage (
144- 'Docker is installed but not running. Please start Docker to use the Terraform MCP Server.' ,
145- 'Learn More' ,
146- )
131+ . showWarningMessage ( 'Please install and start a Docker compatible runtime to use this feature.' , 'Learn More' )
147132 . then ( ( selection ) => {
148133 if ( selection === 'Learn More' ) {
149134 void vscode . env . openExternal ( vscode . Uri . parse ( 'https://docs.docker.com/get-started/' ) ) ;
@@ -153,20 +138,6 @@ export class McpServerFeature {
153138 }
154139 }
155140
156- private showMcpServerInfoMessage ( ) : void {
157- const message = 'Terraform MCP Server is now available for GitHub Copilot integration.' ;
158- const startAction = 'Start MCP Server' ;
159- const learnMoreAction = 'Learn More' ;
160-
161- void vscode . window . showInformationMessage ( message , startAction , learnMoreAction ) . then ( ( selection ) => {
162- if ( selection === startAction ) {
163- void vscode . commands . executeCommand ( 'workbench.action.quickOpen' , '>MCP: List Servers' ) ;
164- } else if ( selection === learnMoreAction ) {
165- void vscode . env . openExternal ( vscode . Uri . parse ( 'https://github.com/hashicorp/terraform-mcp-server' ) ) ;
166- }
167- } ) ;
168- }
169-
170141 dispose ( ) : void {
171142 // context.subscriptions will be disposed by the extension, so any explicit code should not be required.
172143 }
0 commit comments