(
server: McpServer,
options: BootstrapOptions = {},
)
| 49 | } |
| 50 | |
| 51 | export async function bootstrapServer( |
| 52 | server: McpServer, |
| 53 | options: BootstrapOptions = {}, |
| 54 | ): Promise<BootstrapResult> { |
| 55 | const profiler = createStartupProfiler('bootstrap'); |
| 56 | |
| 57 | server.server.setRequestHandler(SetLevelRequestSchema, async (request) => { |
| 58 | const { level } = request.params; |
| 59 | const normalized = normalizeLogLevel(level); |
| 60 | if (normalized) { |
| 61 | setLogLevel(normalized); |
| 62 | } |
| 63 | log('info', `Client requested log level: ${level}`); |
| 64 | return {}; |
| 65 | }); |
| 66 | |
| 67 | const hasLegacyEnabledWorkflows = Object.prototype.hasOwnProperty.call( |
| 68 | options, |
| 69 | 'enabledWorkflows', |
| 70 | ); |
| 71 | let overrides: RuntimeConfigOverrides | undefined; |
| 72 | if (options.configOverrides !== undefined) { |
| 73 | overrides = { ...options.configOverrides }; |
| 74 | } |
| 75 | if (hasLegacyEnabledWorkflows) { |
| 76 | overrides ??= {}; |
| 77 | overrides.enabledWorkflows = options.enabledWorkflows ?? []; |
| 78 | } |
| 79 | |
| 80 | let stageStartMs = getStartupProfileNowMs(); |
| 81 | const result = await bootstrapRuntime({ |
| 82 | runtime: 'mcp', |
| 83 | cwd: options.cwd, |
| 84 | fs: options.fileSystemExecutor, |
| 85 | configOverrides: overrides, |
| 86 | }); |
| 87 | profiler.mark('bootstrapRuntime', stageStartMs); |
| 88 | |
| 89 | if (result.configFound) { |
| 90 | for (const notice of result.notices) { |
| 91 | log('info', `[ProjectConfig] ${notice}`); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | const enabledWorkflows = result.runtime.config.enabledWorkflows; |
| 96 | const { workspaceRoot, workspaceKey } = result; |
| 97 | |
| 98 | log('info', `🚀 Initializing server...`); |
| 99 | |
| 100 | const executor = getDefaultCommandExecutor(); |
| 101 | stageStartMs = getStartupProfileNowMs(); |
| 102 | const xcodeDetection = await detectXcodeRuntime(executor); |
| 103 | profiler.mark('detectXcodeRuntime', stageStartMs); |
| 104 | |
| 105 | const ctx: PredicateContext = { |
| 106 | runtime: 'mcp', |
| 107 | config: result.runtime.config, |
| 108 | runningUnderXcode: xcodeDetection.runningUnderXcode, |
no test coverage detected