@@ -16,6 +16,61 @@ import { createTestController } from "./test-controller";
1616
1717let lsClient : LanguageClient | undefined ;
1818let lsProcess : ReturnType < typeof spawn > | undefined ;
19+ const FINECODE_MCP_PROVIDER_ID = 'finecode' ;
20+
21+ function createFineCodeMcpServerDefinitionProvider ( rootPath : string , outputChannel : vscode . LogOutputChannel ) : {
22+ provider : vscode . McpServerDefinitionProvider < vscode . McpStdioServerDefinition > ;
23+ disposable : vscode . Disposable ;
24+ } {
25+ const onDidChangeMcpServerDefinitionsEmitter = new vscode . EventEmitter < void > ( ) ;
26+ const workspaceFoldersChangeDisposable = vscode . workspace . onDidChangeWorkspaceFolders ( ( ) => {
27+ outputChannel . info ( 'Workspace folders changed, refreshing FineCode MCP server definitions' ) ;
28+ onDidChangeMcpServerDefinitionsEmitter . fire ( ) ;
29+ } ) ;
30+
31+ const provider : vscode . McpServerDefinitionProvider < vscode . McpStdioServerDefinition > = {
32+ onDidChangeMcpServerDefinitions : onDidChangeMcpServerDefinitionsEmitter . event ,
33+ provideMcpServerDefinitions : ( ) => {
34+ if ( ! rootPath ) {
35+ outputChannel . warn ( 'FineCode MCP provider: no workspace root available' ) ;
36+ return [ ] ;
37+ }
38+
39+ const pythonPath = rootPath + '/.venvs/dev_workspace/bin/python' ;
40+ if ( ! fs . existsSync ( pythonPath ) ) {
41+ outputChannel . warn ( `FineCode MCP provider: no dev_workspace python in ${ rootPath } ` ) ;
42+ return [ ] ;
43+ }
44+
45+ const serverDefinitions = [
46+ new vscode . McpStdioServerDefinition (
47+ 'FineCode' ,
48+ pythonPath ,
49+ [ '-m' , 'finecode' , 'start-mcp' , `--workdir=${ rootPath } ` ] ,
50+ ) ,
51+ ] ;
52+
53+ outputChannel . debug ( `Providing FineCode MCP server definition for root workspace: ${ rootPath } ` ) ;
54+
55+ return serverDefinitions ;
56+ } ,
57+ resolveMcpServerDefinition : ( serverDefinition ) => {
58+ return serverDefinition ;
59+ } ,
60+ } ;
61+
62+ const disposable = {
63+ dispose : ( ) => {
64+ workspaceFoldersChangeDisposable . dispose ( ) ;
65+ onDidChangeMcpServerDefinitionsEmitter . dispose ( ) ;
66+ } ,
67+ } ;
68+
69+ return {
70+ provider,
71+ disposable,
72+ } ;
73+ }
1974
2075
2176export async function activate ( context : vscode . ExtensionContext ) {
@@ -37,6 +92,13 @@ export async function activate(context: vscode.ExtensionContext) {
3792 outputChannel . info ( `Workspace root path: ${ rootPath } ` ) ;
3893 const actionsProvider = new FineCodeActionsProvider ( rootPath ) ;
3994
95+ const { provider : mcpServerDefinitionProvider , disposable : mcpProviderDisposable } = createFineCodeMcpServerDefinitionProvider ( rootPath , outputChannel ) ;
96+ const mcpProviderRegistration = vscode . lm . registerMcpServerDefinitionProvider (
97+ FINECODE_MCP_PROVIDER_ID ,
98+ mcpServerDefinitionProvider ,
99+ ) ;
100+ outputChannel . info ( 'Registered FineCode MCP server definition provider' ) ;
101+
40102
41103 // task provider:
42104 // docs: https://code.visualstudio.com/api/extension-guides/task-provider
@@ -86,6 +148,8 @@ export async function activate(context: vscode.ExtensionContext) {
86148 outputChannel . info ( 'Registering commands and providers...' ) ;
87149 context . subscriptions . push (
88150 vscode . window . registerTreeDataProvider ( "fineCodeActions" , actionsProvider ) ,
151+ mcpProviderRegistration ,
152+ mcpProviderDisposable ,
89153 vscode . commands . registerCommand ( 'finecode.restartWorkspaceManager' , async ( ) => {
90154 outputChannel . info ( 'Restarting workspace manager' ) ;
91155 await stopWorkspaceManager ( ) ;
@@ -168,6 +232,7 @@ const runWorkspaceManager = async (outputChannel: vscode.LogOutputChannel, actio
168232 let finecodeFound = false ;
169233 for ( const folder of vscode . workspace . workspaceFolders ) {
170234 const dirPath = folder . uri . path ;
235+ wsDir = dirPath ;
171236 devWorkspacePythonPath = dirPath + '/.venvs/dev_workspace/bin/python' ;
172237 outputChannel . info ( `Checking for Python at: ${ devWorkspacePythonPath } ` ) ;
173238 if ( fs . existsSync ( devWorkspacePythonPath ) ) {
0 commit comments