-
Notifications
You must be signed in to change notification settings - Fork 19
feat(mcp): add mcp connect and disconnect commands #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "mcpServers": {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import type { Command } from 'commander'; | ||
| import * as clack from '@clack/prompts'; | ||
| import { updateMcpConnectionStatus } from '../../lib/api/oss.js'; | ||
| import { getProjectConfig } from '../../lib/config.js'; | ||
| import { handleError, getRootOpts, ProjectNotLinkedError, CLIError } from '../../lib/errors.js'; | ||
| import { connectMcpProvider, displayMcpConfigPath, parseMcpProvider } from '../../lib/mcp-config.js'; | ||
| import { outputJson, outputSuccess } from '../../lib/output.js'; | ||
| import { reportCliUsage } from '../../lib/skills.js'; | ||
| import { captureEvent, shutdownAnalytics } from '../../lib/analytics.js'; | ||
| import type { ProjectConfig } from '../../types.js'; | ||
|
|
||
| export function registerMcpConnectCommand(program: Command): void { | ||
| program | ||
| .command('connect [provider]') | ||
| .description('Connect an MCP provider to the linked InsForge project') | ||
| .option('--api-key <apiKey>', 'API key for InsForge MCP') | ||
| .option('--api-base-url <apiBaseUrl>', 'Base URL of the InsForge backend') | ||
| .action(async (providerArg: string | undefined, options: { apiKey?: string; apiBaseUrl?: string }, cmd) => { | ||
| const { json } = getRootOpts(cmd); | ||
| try { | ||
| const { apiKey, apiBaseUrl } = options; | ||
| let connectionConfig: { apiKey: string; apiBaseUrl: string } | ProjectConfig; | ||
| let projectId: string | undefined; | ||
|
|
||
| if (apiKey || apiBaseUrl) { | ||
| if (!apiKey || !apiBaseUrl) { | ||
| throw new CLIError('Both --api-key and --api-base-url must be provided if not using a linked project.'); | ||
| } | ||
| connectionConfig = { apiKey, apiBaseUrl }; | ||
| } else { | ||
| const project = getProjectConfig(); | ||
| if (!project) throw new ProjectNotLinkedError(); | ||
| connectionConfig = project; | ||
| projectId = project.project_id; | ||
| } | ||
|
|
||
| const provider = parseMcpProvider(providerArg ?? 'cursor'); | ||
| const result = connectMcpProvider(provider, connectionConfig); | ||
| if (apiKey && apiBaseUrl) { | ||
| await updateMcpConnectionStatus('connected', { apiKey, apiBaseUrl }); | ||
| } else { | ||
| await updateMcpConnectionStatus('connected'); | ||
| } | ||
|
|
||
| if (projectId && 'project_id' in connectionConfig) { | ||
| captureEvent(connectionConfig.project_id, 'cli_mcp_connect', { | ||
| provider, | ||
| project_id: connectionConfig.project_id, | ||
| project_name: connectionConfig.project_name, | ||
| org_id: connectionConfig.org_id, | ||
| region: connectionConfig.region, | ||
| changed: result.changed, | ||
| }); | ||
| } | ||
| await reportCliUsage('cli.mcp.connect', true); | ||
|
|
||
| if (json) { | ||
| outputJson({ | ||
| success: true, | ||
| status: 'connected', | ||
| provider, | ||
| config_path: result.path, | ||
| changed: result.changed, | ||
| }); | ||
| } else { | ||
| outputSuccess(`Connected ${provider} to InsForge MCP in ${displayMcpConfigPath(result.path)}.`); | ||
| if (!result.changed) { | ||
| clack.log.info('The existing InsForge MCP entry was already up to date.'); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| await reportCliUsage('cli.mcp.connect', false); | ||
| handleError(err, json); | ||
| } finally { | ||
| await shutdownAnalytics(); | ||
| } | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import type { Command } from 'commander'; | ||
| import * as clack from '@clack/prompts'; | ||
| import { updateMcpConnectionStatus } from '../../lib/api/oss.js'; | ||
| import { getProjectConfig } from '../../lib/config.js'; | ||
| import { handleError, getRootOpts, ProjectNotLinkedError, CLIError } from '../../lib/errors.js'; | ||
| import { MCP_PROVIDERS, disconnectMcpProvider, displayMcpConfigPath, parseMcpProvider } from '../../lib/mcp-config.js'; | ||
| import { outputJson, outputSuccess } from '../../lib/output.js'; | ||
| import { reportCliUsage } from '../../lib/skills.js'; | ||
| import { captureEvent, shutdownAnalytics } from '../../lib/analytics.js'; | ||
|
|
||
| export function registerMcpDisconnectCommand(program: Command): void { | ||
| program | ||
| .command('disconnect [provider]') | ||
| .description('Disconnect an MCP provider from the linked InsForge project') | ||
| .option('--api-key <apiKey>', 'API key for InsForge MCP') | ||
| .option('--api-base-url <apiBaseUrl>', 'Base URL of the InsForge backend') | ||
| .action(async (providerArg: string | undefined, options: { apiKey?: string; apiBaseUrl?: string }, cmd) => { | ||
| const { json } = getRootOpts(cmd); | ||
| try { | ||
| const { apiKey, apiBaseUrl } = options; | ||
| let projectId: string | undefined; | ||
| let projectConfig: ReturnType<typeof getProjectConfig> = null; | ||
|
|
||
| if (apiKey || apiBaseUrl) { | ||
| if (!apiKey || !apiBaseUrl) { | ||
| throw new CLIError('Both --api-key and --api-base-url must be provided if not using a linked project.'); | ||
| } | ||
| } else { | ||
| projectConfig = getProjectConfig(); | ||
| if (!projectConfig) throw new ProjectNotLinkedError(); | ||
| projectId = projectConfig.project_id; | ||
| } | ||
|
|
||
| const providers = providerArg ? [parseMcpProvider(providerArg)] : MCP_PROVIDERS; | ||
| const results = providers.map((provider) => disconnectMcpProvider(provider)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Bulk disconnect is not fault-tolerant: a single malformed or unreadable provider config file aborts the entire cleanup and leaves remaining providers untouched. Each provider operation should be isolated in a try/catch so that one bad config doesn't prevent cleanup of the others. Prompt for AI agents |
||
| if (apiKey && apiBaseUrl) { | ||
| await updateMcpConnectionStatus('disconnected', { apiKey, apiBaseUrl }); | ||
| } else { | ||
| await updateMcpConnectionStatus('disconnected'); | ||
| } | ||
| const changed = results.some((result) => result.changed); | ||
|
|
||
| if (projectId && projectConfig) { | ||
| captureEvent(projectConfig.project_id, 'cli_mcp_disconnect', { | ||
| provider: providerArg ? results[0].provider : 'all', | ||
| project_id: projectConfig.project_id, | ||
| project_name: projectConfig.project_name, | ||
| org_id: projectConfig.org_id, | ||
| region: projectConfig.region, | ||
| changed, | ||
| }); | ||
| } | ||
| await reportCliUsage('cli.mcp.disconnect', true); | ||
|
|
||
| if (json) { | ||
| outputJson({ | ||
| success: true, | ||
| status: 'disconnected', | ||
| provider: providerArg ? results[0].provider : 'all', | ||
| results: results.map((result) => ({ | ||
| provider: result.provider, | ||
| config_path: result.path, | ||
| changed: result.changed, | ||
| })), | ||
| changed, | ||
| }); | ||
| } else { | ||
| if (providerArg) { | ||
| const result = results[0]; | ||
| outputSuccess(`Disconnected ${result.provider} from InsForge MCP in ${displayMcpConfigPath(result.path)}.`); | ||
| } else { | ||
| outputSuccess('Disconnected InsForge MCP from all known local provider configs.'); | ||
| const updated = results.filter((result) => result.changed); | ||
| if (updated.length > 0) { | ||
| clack.log.info(`Updated: ${updated.map((result) => displayMcpConfigPath(result.path)).join(', ')}`); | ||
| } | ||
| } | ||
| if (!changed) { | ||
| clack.log.info('No InsForge MCP entries were present; backend status was still marked disconnected.'); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| await reportCliUsage('cli.mcp.disconnect', false); | ||
| handleError(err, json); | ||
| } finally { | ||
| await shutdownAnalytics(); | ||
| } | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { Command } from 'commander'; | ||
| import { registerMcpConnectCommand } from './connect.js'; | ||
| import { registerMcpDisconnectCommand } from './disconnect.js'; | ||
|
|
||
| export function registerMcpCommands(program: Command): void { | ||
| registerMcpConnectCommand(program); | ||
| registerMcpDisconnectCommand(program); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Provider MCP config file
.antigravity/mcp.jsonis committed in-repo and will be mutated byconnectwith sensitive API credentials, creating accidental commit risk.Prompt for AI agents