Template
8707d66108
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 22s
Branch Policy Check / Verify merge target (pull_request) Successful in 2s
Universal: PR Check / Branch Policy (pull_request) Successful in 3s
Universal: PR Check / Secret Scan (pull_request) Successful in 7s
Generic: Project CI / Lint & Validate (pull_request) Successful in 24s
Universal: PR Check / Validate PR (pull_request) Successful in 7s
Universal: Auto-Assign / Assign unassigned issues and PRs (pull_request_target) Successful in 3s
Branch Cleanup / Delete merged branch (pull_request) Successful in 2s
RC Revert / Rename rc/ back to dev/ (pull_request) Has been skipped
Generic: Project CI / Tests (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Standardize the template on `source/` as the source input directory and retire user-facing `src/` references, per issue #34. Changes: - git mv src -> source (history preserved for all .ts files) - source/*.ts: update PATH headers /src/ -> /source/ - tsconfig.json: rootDir and include point at source/ - package.json: lint script targets source/ - Makefile: add SRC_DIR := source (CI resolver source of truth) - README.md, CLAUDE.md, docs/ARCHITECTURE.md: source path refs -> source/ The `dist/` directory is retained solely as tsc's compiled build output (outDir), which is already gitignored and never committed/published; releases go through the MokoGIT release system. No new dist/ references were introduced. Authored-by: Moko Consulting
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* This file is part of a Moko Consulting project.
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
* DEFGROUP: {{PROJECT_NAME}}.Config
|
|
* INGROUP: {{PROJECT_NAME}}
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/{{PROJECT_NAME}}
|
|
* PATH: /source/config.ts
|
|
* VERSION: 01.00.00
|
|
* BRIEF: Configuration loader for {{DISPLAY_NAME}} MCP connections
|
|
*/
|
|
|
|
import { readFile } from 'node:fs/promises';
|
|
import { resolve } from 'node:path';
|
|
import { homedir } from 'node:os';
|
|
import type { ApiConfig, ApiConnection } from './types.js';
|
|
|
|
// ── Customize this ──────────────────────────────────────────────────────
|
|
// Change the filename to match your project (e.g. ".dolibarr-api-mcp.json")
|
|
const CONFIG_FILENAME = '.{{PROJECT_NAME}}.json';
|
|
// Change the env var name to match your project
|
|
const CONFIG_ENV_VAR = '{{ENV_PREFIX}}_CONFIG';
|
|
// ────────────────────────────────────────────────────────────────────────
|
|
|
|
export async function loadConfig(): Promise<ApiConfig> {
|
|
const config_path = process.env[CONFIG_ENV_VAR]
|
|
? resolve(process.env[CONFIG_ENV_VAR]!)
|
|
: resolve(homedir(), CONFIG_FILENAME);
|
|
|
|
try {
|
|
const raw = await readFile(config_path, 'utf-8');
|
|
const parsed = JSON.parse(raw) as Partial<ApiConfig>;
|
|
|
|
if (!parsed.connections || Object.keys(parsed.connections).length === 0) {
|
|
throw new Error('No connections defined in config');
|
|
}
|
|
|
|
return {
|
|
connections: parsed.connections,
|
|
defaultConnection: parsed.defaultConnection ?? Object.keys(parsed.connections)[0],
|
|
};
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
throw new Error(
|
|
`Failed to load config from ${config_path}: ${message}\n` +
|
|
`Create ${config_path} — see config.example.json for format.`,
|
|
);
|
|
}
|
|
}
|
|
|
|
export function getConnection(config: ApiConfig, name?: string): ApiConnection {
|
|
const key = name ?? config.defaultConnection;
|
|
const conn = config.connections[key];
|
|
if (!conn) {
|
|
throw new Error(
|
|
`Connection "${key}" not found. Available: ${Object.keys(config.connections).join(', ')}`,
|
|
);
|
|
}
|
|
return conn;
|
|
}
|