Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

config.ts

23 lines966 Bytes

1import type { MCPCodegenConfig } from './define-config'
2​
3export type { CodegenServerConfig, MCPCodegenConfig } from './define-config'
4export { defineConfig } from './define-config'
5​
6/** Load mcp.config.ts (via jiti) or mcp.config.json from cwd. */
7export async function loadConfig(cwd: string): Promise<MCPCodegenConfig> {
8 const { existsSync } = await import('node:fs')
9 const { join } = await import('node:path')
10 const tsPath = join(cwd, 'mcp.config.ts')
11 const jsonPath = join(cwd, 'mcp.config.json')
12 if (existsSync(tsPath)) {
13 const { createJiti } = await import('jiti')
14 const jiti = createJiti(import.meta.url)
15 const mod = await jiti.import<{ default: MCPCodegenConfig }>(tsPath)
16 return mod.default
17 }
18 if (existsSync(jsonPath)) {
19 const { readFileSync } = await import('node:fs')
20 return JSON.parse(readFileSync(jsonPath, 'utf8')) as MCPCodegenConfig
21 }
22 throw new Error('No mcp.config.ts or mcp.config.json found in ' + cwd)