Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
AIT-239: Address MCP review feedback#30
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,25 @@ | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { resolve } from 'node:path'; | ||
| import type { Command } from 'commander'; | ||
| import { getEffectiveApiUrl } from '../config/env-profiles.js'; | ||
| import { ConfigurationError } from '../output/error.js'; | ||
| import { addExamples } from '../output/help.js'; | ||
| const MCP_NAME = 'hookmyapp'; | ||
| const CLAUDE_OPTIONS = { encoding: 'utf8' as const, timeout: 10_000 }; | ||
| function headersHelper(): string { | ||
| return `${shellQuote(process.execPath)} ${shellQuote(resolve(process.argv[1]))} mcp-headers`; | ||
| } | ||
| export function shellQuote(value: string, platform = process.platform): string { | ||
| if (platform === 'win32') return `"${value}"`; | ||
| return `'${value.replace(/'/g, `'"'"'`)}'`; | ||
| } | ||
| function timedOut(error: Error | undefined): boolean { | ||
| return (error as NodeJS.ErrnoException | undefined)?.code === 'ETIMEDOUT'; | ||
| } | ||
| function mcpUrl(): string { | ||
| return `${getEffectiveApiUrl().replace(/\/$/, '')}/mcp`; | ||
| @@ -20,26 +35,29 @@ export function installClaudeMcp(): void { | ||
| const config = JSON.stringify({ | ||
| type: 'http', | ||
| url: mcpUrl(), | ||
| headersHelper: 'hookmyapp mcp-headers', | ||
| headersHelper: headersHelper(), | ||
| }); | ||
| const args = ['mcp', 'add-json', '--scope', 'user', MCP_NAME, config]; | ||
| let result = spawnSync('claude', args, { encoding: 'utf8' }); | ||
| let result = spawnSync('claude', args, CLAUDE_OPTIONS); | ||
| const output = `${result.stdout ?? ''}\n${result.stderr ?? ''}`; | ||
| if (result.status !== 0 && output.includes('already exists')) { | ||
| removeClaudeMcp(true); | ||
| result = spawnSync('claude', args, { encoding: 'utf8' }); | ||
| const cleanup = removeClaudeMcp(true); | ||
| if (!cleanup.ok) { | ||
| throw new ConfigurationError(cleanup.detail ?? 'Claude MCP cleanup failed', 'MCP_INSTALL_FAILED'); | ||
| } | ||
| result = spawnSync('claude', args, CLAUDE_OPTIONS); | ||
| } | ||
| if (result.error || result.status !== 0) { | ||
| throw new ConfigurationError( | ||
| result.error?.message || result.stderr.trim() || 'Claude Code MCP setup failed', | ||
| result.error?.message || (result.stderr ?? '').trim() || 'Claude Code MCP setup failed', | ||
| 'MCP_INSTALL_FAILED', | ||
| ); | ||
| } | ||
| } | ||
| export function maybeInstallClaudeMcp(force = false): void { | ||
| if (!force && process.env.NODE_ENV === 'test') return; | ||
| const probe = spawnSync('claude', ['--version'], { encoding: 'utf8' }); | ||
| const probe = spawnSync('claude', ['--version'], CLAUDE_OPTIONS); | ||
| if (probe.error || probe.status !== 0) return; | ||
| try { | ||
| installClaudeMcp(); | ||
| @@ -51,17 +69,26 @@ export function maybeInstallClaudeMcp(force = false): void { | ||
| } | ||
| } | ||
| export function removeClaudeMcp(force = false): void { | ||
| if (!force && process.env.NODE_ENV === 'test') return; | ||
| spawnSync('claude', ['mcp', 'remove', '--scope', 'user', MCP_NAME], { | ||
| encoding: 'utf8', | ||
| }); | ||
| export function removeClaudeMcp(force = false): { ok: boolean; detail?: string } { | ||
| if (!force && process.env.NODE_ENV === 'test') return { ok: true }; | ||
| const result = spawnSync('claude', ['mcp', 'remove', '--scope', 'user', MCP_NAME], CLAUDE_OPTIONS); | ||
| if ((result.error as NodeJS.ErrnoException | undefined)?.code === 'ENOENT') return { ok: true }; | ||
| if (!result.error && result.status === 0) return { ok: true }; | ||
ord669 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const output = `${result.stdout ?? ''}\n${result.stderr ?? ''}`.toLowerCase(); | ||
| if (output.includes('not found') || output.includes('does not exist') || output.includes('no mcp server')) { | ||
| return { ok: true }; | ||
| } | ||
| return { | ||
| ok: false, | ||
ord669 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| detail: timedOut(result.error) | ||
| ? 'Claude MCP cleanup timed out' | ||
| : result.error?.message || (result.stderr ?? '').trim() || 'Claude MCP cleanup failed', | ||
| }; | ||
| } | ||
| export function getClaudeMcpStatus(): { ok: boolean; detail: string } { | ||
| const result = spawnSync('claude', ['mcp', 'get', MCP_NAME], { | ||
| encoding: 'utf8', | ||
| }); | ||
| const result = spawnSync('claude', ['mcp', 'get', MCP_NAME], CLAUDE_OPTIONS); | ||
| if (timedOut(result.error)) return { ok: false, detail: 'Claude MCP check timed out' }; | ||
| if (result.error?.message.includes('ENOENT')) { | ||
| return { ok: false, detail: 'Claude Code not found' }; | ||
| } | ||
| @@ -88,7 +115,11 @@ export function registerMcpCommand(program: Command): void { | ||
| throw new ConfigurationError(`Unsupported agent "${opts.agent}". Supported: claude`, 'MCP_AGENT_UNSUPPORTED'); | ||
| } | ||
| installClaudeMcp(); | ||
| process.stdout.write('HookMyApp MCP configured for Claude Code.\n'); | ||
| process.stdout.write( | ||
| program.opts().json | ||
| ? JSON.stringify({ status: 'configured', agent: 'claude' }) + '\n' | ||
| : 'HookMyApp MCP configured for Claude Code.\n', | ||
| ); | ||
| }); | ||
| addExamples( | ||
| install, | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.