@utilarium/cardigantime 0.0.24-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/LICENSE +65 -0
  2. package/README.md +398 -0
  3. package/dist/cardigantime.cjs +2169 -0
  4. package/dist/cardigantime.cjs.map +1 -0
  5. package/dist/cardigantime.d.ts +92 -0
  6. package/dist/cardigantime.js +198 -0
  7. package/dist/cardigantime.js.map +1 -0
  8. package/dist/config/executable-security.d.ts +32 -0
  9. package/dist/config/format-detector.d.ts +59 -0
  10. package/dist/configure.d.ts +55 -0
  11. package/dist/configure.js +125 -0
  12. package/dist/configure.js.map +1 -0
  13. package/dist/constants.d.ts +25 -0
  14. package/dist/constants.js +38 -0
  15. package/dist/constants.js.map +1 -0
  16. package/dist/discovery/discoverer.d.ts +62 -0
  17. package/dist/discovery/hierarchical-modes.d.ts +64 -0
  18. package/dist/discovery/index.d.ts +15 -0
  19. package/dist/discovery/patterns.d.ts +77 -0
  20. package/dist/discovery/root-detection.d.ts +100 -0
  21. package/dist/discovery/traversal-security.d.ts +106 -0
  22. package/dist/env/errors.d.ts +18 -0
  23. package/dist/env/index.d.ts +7 -0
  24. package/dist/env/naming.d.ts +38 -0
  25. package/dist/env/parser.d.ts +61 -0
  26. package/dist/env/reader.d.ts +45 -0
  27. package/dist/env/resolver.d.ts +25 -0
  28. package/dist/env/schema-utils.d.ts +33 -0
  29. package/dist/env/types.d.ts +43 -0
  30. package/dist/error/ArgumentError.d.ts +31 -0
  31. package/dist/error/ArgumentError.js +48 -0
  32. package/dist/error/ArgumentError.js.map +1 -0
  33. package/dist/error/ConfigParseError.d.ts +26 -0
  34. package/dist/error/ConfigurationError.d.ts +21 -0
  35. package/dist/error/ConfigurationError.js +46 -0
  36. package/dist/error/ConfigurationError.js.map +1 -0
  37. package/dist/error/FileSystemError.d.ts +30 -0
  38. package/dist/error/FileSystemError.js +58 -0
  39. package/dist/error/FileSystemError.js.map +1 -0
  40. package/dist/error/index.d.ts +4 -0
  41. package/dist/mcp/discovery.d.ts +105 -0
  42. package/dist/mcp/errors.d.ts +75 -0
  43. package/dist/mcp/index.d.ts +22 -0
  44. package/dist/mcp/integration.d.ts +184 -0
  45. package/dist/mcp/parser.d.ts +141 -0
  46. package/dist/mcp/resolver.d.ts +165 -0
  47. package/dist/mcp/tools/check-config-types.d.ts +208 -0
  48. package/dist/mcp/tools/check-config.d.ts +85 -0
  49. package/dist/mcp/tools/index.d.ts +12 -0
  50. package/dist/mcp/types.d.ts +210 -0
  51. package/dist/parsers/index.d.ts +25 -0
  52. package/dist/parsers/javascript-parser.d.ts +12 -0
  53. package/dist/parsers/json-parser.d.ts +6 -0
  54. package/dist/parsers/typescript-parser.d.ts +15 -0
  55. package/dist/parsers/yaml-parser.d.ts +6 -0
  56. package/dist/read.d.ts +56 -0
  57. package/dist/read.js +653 -0
  58. package/dist/read.js.map +1 -0
  59. package/dist/security/audit-logger.d.ts +135 -0
  60. package/dist/security/cli-validator.d.ts +73 -0
  61. package/dist/security/config-validator.d.ts +95 -0
  62. package/dist/security/defaults.d.ts +17 -0
  63. package/dist/security/index.d.ts +14 -0
  64. package/dist/security/numeric-guard.d.ts +111 -0
  65. package/dist/security/path-guard.d.ts +53 -0
  66. package/dist/security/profiles.d.ts +127 -0
  67. package/dist/security/security-validator.d.ts +109 -0
  68. package/dist/security/string-guard.d.ts +92 -0
  69. package/dist/security/types.d.ts +126 -0
  70. package/dist/security/zod-secure-enum.d.ts +20 -0
  71. package/dist/security/zod-secure-number.d.ts +39 -0
  72. package/dist/security/zod-secure-path.d.ts +24 -0
  73. package/dist/security/zod-secure-string.d.ts +38 -0
  74. package/dist/types.d.ts +584 -0
  75. package/dist/types.js +56 -0
  76. package/dist/types.js.map +1 -0
  77. package/dist/util/hierarchical.d.ts +136 -0
  78. package/dist/util/hierarchical.js +436 -0
  79. package/dist/util/hierarchical.js.map +1 -0
  80. package/dist/util/schema-defaults.d.ts +80 -0
  81. package/dist/util/schema-defaults.js +118 -0
  82. package/dist/util/schema-defaults.js.map +1 -0
  83. package/dist/util/storage.d.ts +31 -0
  84. package/dist/util/storage.js +154 -0
  85. package/dist/util/storage.js.map +1 -0
  86. package/dist/validate.d.ts +113 -0
  87. package/dist/validate.js +260 -0
  88. package/dist/validate.js.map +1 -0
  89. package/package.json +84 -0
@@ -0,0 +1,184 @@
1
+ import { ZodSchema } from 'zod';
2
+ import { MCPInvocationContext, ResolvedConfig } from './types';
3
+ /**
4
+ * Options for creating MCP integration helpers.
5
+ */
6
+ export interface MCPIntegrationOptions {
7
+ /**
8
+ * Application name (used in CheckConfig documentation links).
9
+ */
10
+ appName: string;
11
+ /**
12
+ * Zod schema for configuration validation.
13
+ */
14
+ configSchema: ZodSchema;
15
+ /**
16
+ * Base URL for documentation links.
17
+ * @default "https://github.com/utilarium/cardigantime"
18
+ */
19
+ docsBaseUrl?: string;
20
+ /**
21
+ * Function to resolve file-based configuration.
22
+ * Called when MCP config is not provided.
23
+ */
24
+ resolveFileConfig?: (workingDirectory: string) => Promise<any>;
25
+ }
26
+ /**
27
+ * Creates a CheckConfig tool handler for your MCP server.
28
+ *
29
+ * This is a convenience function that returns a ready-to-use handler
30
+ * for the CheckConfig tool. Register this with your MCP server to
31
+ * automatically provide configuration inspection capabilities.
32
+ *
33
+ * @param options - Integration options
34
+ * @returns Object with tool descriptor and handler
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import { createCheckConfigTool } from '@utilarium/cardigantime/mcp';
39
+ *
40
+ * const checkConfigTool = createCheckConfigTool({
41
+ * appName: 'myapp',
42
+ * configSchema: myConfigSchema,
43
+ * resolveFileConfig: async (dir) => loadMyConfig(dir),
44
+ * });
45
+ *
46
+ * // Register with your MCP server
47
+ * server.registerTool(
48
+ * checkConfigTool.descriptor,
49
+ * checkConfigTool.handler
50
+ * );
51
+ * ```
52
+ */
53
+ export declare function createCheckConfigTool(options: MCPIntegrationOptions): {
54
+ descriptor: import('./tools').CheckConfigToolDescriptor;
55
+ handler: (input: any, context: MCPInvocationContext) => Promise<import('./tools').CheckConfigResult>;
56
+ };
57
+ /**
58
+ * Creates a configuration resolver for MCP tool handlers.
59
+ *
60
+ * This function returns a resolver that you can call at the beginning
61
+ * of your tool handlers to get the resolved configuration. It handles
62
+ * both MCP-provided config and file-based fallback.
63
+ *
64
+ * @param options - Integration options
65
+ * @returns Configuration resolver function
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * import { createConfigResolver } from '@utilarium/cardigantime/mcp';
70
+ *
71
+ * const resolveMyConfig = createConfigResolver({
72
+ * appName: 'myapp',
73
+ * configSchema: myConfigSchema,
74
+ * resolveFileConfig: async (dir) => loadMyConfig(dir),
75
+ * });
76
+ *
77
+ * // In your tool handler
78
+ * async function myToolHandler(input: any, context: MCPInvocationContext) {
79
+ * const config = await resolveMyConfig(context);
80
+ *
81
+ * // Use config.config for the resolved configuration
82
+ * console.log('Port:', config.config.port);
83
+ *
84
+ * // ... rest of tool logic
85
+ * }
86
+ * ```
87
+ */
88
+ export declare function createConfigResolver<T = unknown>(options: MCPIntegrationOptions): (context: MCPInvocationContext) => Promise<ResolvedConfig<T>>;
89
+ /**
90
+ * Wraps a tool handler to automatically inject resolved configuration.
91
+ *
92
+ * This higher-order function wraps your tool handler and automatically
93
+ * resolves configuration before calling your handler. The resolved config
94
+ * is added to the context object.
95
+ *
96
+ * @param handler - Your tool handler function
97
+ * @param options - Integration options
98
+ * @returns Wrapped handler with config injection
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * import { withConfig } from '@utilarium/cardigantime/mcp';
103
+ *
104
+ * // Your tool handler
105
+ * async function myTool(input: any, context: any) {
106
+ * // Config is automatically available in context
107
+ * console.log('Port:', context.resolvedConfig.config.port);
108
+ *
109
+ * return { result: 'success' };
110
+ * }
111
+ *
112
+ * // Wrap with config injection
113
+ * const wrappedHandler = withConfig(myTool, {
114
+ * appName: 'myapp',
115
+ * configSchema: myConfigSchema,
116
+ * resolveFileConfig: async (dir) => loadMyConfig(dir),
117
+ * });
118
+ *
119
+ * // Register wrapped handler with your MCP server
120
+ * server.registerTool('my_tool', wrappedHandler);
121
+ * ```
122
+ */
123
+ export declare function withConfig<TInput = any, TOutput = any, TConfig = unknown>(handler: (input: TInput, context: MCPInvocationContext & {
124
+ resolvedConfig: ResolvedConfig<TConfig>;
125
+ }) => Promise<TOutput>, options: MCPIntegrationOptions): (input: TInput, context: MCPInvocationContext) => Promise<TOutput>;
126
+ /**
127
+ * Creates a complete set of MCP integration helpers.
128
+ *
129
+ * This is a convenience function that returns all the integration helpers
130
+ * you need in one call. Use this if you want a complete integration setup.
131
+ *
132
+ * @param options - Integration options
133
+ * @returns Object with all integration helpers
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * import { createMCPIntegration } from '@utilarium/cardigantime/mcp';
138
+ *
139
+ * const integration = createMCPIntegration({
140
+ * appName: 'myapp',
141
+ * configSchema: myConfigSchema,
142
+ * resolveFileConfig: async (dir) => loadMyConfig(dir),
143
+ * });
144
+ *
145
+ * // Register CheckConfig tool
146
+ * server.registerTool(
147
+ * integration.checkConfig.descriptor,
148
+ * integration.checkConfig.handler
149
+ * );
150
+ *
151
+ * // Use config resolver in your tools
152
+ * async function myTool(input: any, context: MCPInvocationContext) {
153
+ * const config = await integration.resolveConfig(context);
154
+ * // ... use config
155
+ * }
156
+ *
157
+ * // Or wrap your handlers with config injection
158
+ * const wrappedHandler = integration.withConfig(myToolHandler);
159
+ * server.registerTool('my_tool', wrappedHandler);
160
+ * ```
161
+ */
162
+ export declare function createMCPIntegration<TConfig = unknown>(options: MCPIntegrationOptions): {
163
+ /**
164
+ * CheckConfig tool ready for registration.
165
+ */
166
+ checkConfig: {
167
+ descriptor: import('./tools').CheckConfigToolDescriptor;
168
+ handler: (input: any, context: MCPInvocationContext) => Promise<import('./tools').CheckConfigResult>;
169
+ };
170
+ /**
171
+ * Configuration resolver function.
172
+ */
173
+ resolveConfig: (context: MCPInvocationContext) => Promise<ResolvedConfig<TConfig>>;
174
+ /**
175
+ * Higher-order function to wrap handlers with config injection.
176
+ */
177
+ withConfig: <TInput = any, TOutput = any>(handler: (input: TInput, context: MCPInvocationContext & {
178
+ resolvedConfig: ResolvedConfig<TConfig>;
179
+ }) => Promise<TOutput>) => (input: TInput, context: MCPInvocationContext) => Promise<TOutput>;
180
+ /**
181
+ * Integration options (for reference).
182
+ */
183
+ options: MCPIntegrationOptions;
184
+ };
@@ -0,0 +1,141 @@
1
+ import { ZodSchema } from 'zod';
2
+ import { MCPConfigSource } from './types';
3
+ /**
4
+ * Options for parsing MCP configuration.
5
+ */
6
+ export interface ParseMCPConfigOptions {
7
+ /**
8
+ * Working directory for resolving relative paths.
9
+ * If not provided, paths are not resolved.
10
+ */
11
+ workingDirectory?: string;
12
+ /**
13
+ * Whether to expand environment variable references in string values.
14
+ * Environment variables are referenced as ${VAR_NAME} or $VAR_NAME.
15
+ *
16
+ * @default false
17
+ */
18
+ expandEnvVars?: boolean;
19
+ /**
20
+ * Fields that contain paths to be resolved relative to workingDirectory.
21
+ * Uses dot notation for nested fields (e.g., 'output.directory').
22
+ */
23
+ pathFields?: string[];
24
+ }
25
+ /**
26
+ * Parses and validates configuration received from MCP invocation.
27
+ *
28
+ * This function:
29
+ * - Validates the raw config against the provided Zod schema
30
+ * - Normalizes paths relative to the working directory
31
+ * - Optionally expands environment variable references
32
+ * - Returns a fully typed MCPConfigSource
33
+ *
34
+ * @template T - The Zod schema type
35
+ * @param rawConfig - The raw configuration object from MCP
36
+ * @param schema - Zod schema to validate against
37
+ * @param options - Optional parsing options
38
+ * @returns Promise resolving to a validated MCPConfigSource
39
+ * @throws {MCPConfigError} When validation fails or config is invalid
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const schema = z.object({
44
+ * port: z.number(),
45
+ * host: z.string(),
46
+ * outputDir: z.string(),
47
+ * });
48
+ *
49
+ * const configSource = await parseMCPConfig(
50
+ * { port: 3000, host: 'localhost', outputDir: './output' },
51
+ * schema,
52
+ * {
53
+ * workingDirectory: '/app',
54
+ * pathFields: ['outputDir'],
55
+ * }
56
+ * );
57
+ *
58
+ * // configSource.config.outputDir is now '/app/output'
59
+ * ```
60
+ */
61
+ export declare function parseMCPConfig<T extends ZodSchema>(rawConfig: unknown, schema: T, _options?: ParseMCPConfigOptions): Promise<MCPConfigSource>;
62
+ /**
63
+ * Expands environment variable references in configuration values.
64
+ *
65
+ * Supports both ${VAR_NAME} and $VAR_NAME syntax.
66
+ * Only expands variables in string values.
67
+ *
68
+ * @param config - Configuration object to process
69
+ * @returns Configuration with environment variables expanded
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const config = {
74
+ * host: '${HOST}',
75
+ * port: 3000,
76
+ * path: '$HOME/data',
77
+ * };
78
+ *
79
+ * const expanded = expandEnvironmentVariables(config);
80
+ * // { host: 'localhost', port: 3000, path: '/home/user/data' }
81
+ * ```
82
+ */
83
+ export declare function expandEnvironmentVariables(config: any): any;
84
+ /**
85
+ * Resolves relative paths in configuration to absolute paths.
86
+ *
87
+ * Paths are resolved relative to the provided working directory.
88
+ * Only processes fields specified in pathFields.
89
+ * Supports nested fields using dot notation.
90
+ *
91
+ * @param config - Configuration object to process
92
+ * @param workingDirectory - Base directory for resolving relative paths
93
+ * @param pathFields - Array of field paths to resolve (dot notation for nested)
94
+ * @returns Configuration with resolved paths
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const config = {
99
+ * output: './dist',
100
+ * nested: {
101
+ * path: '../src',
102
+ * },
103
+ * };
104
+ *
105
+ * const resolved = resolveConfigPaths(
106
+ * config,
107
+ * '/app',
108
+ * ['output', 'nested.path']
109
+ * );
110
+ * // { output: '/app/dist', nested: { path: '/src' } }
111
+ * ```
112
+ */
113
+ export declare function resolveConfigPaths(config: any, workingDirectory: string, pathFields: string[]): any;
114
+ /**
115
+ * Merges MCP configuration with default values.
116
+ *
117
+ * This is useful when MCP provides partial configuration and you need
118
+ * to fill in missing fields with defaults.
119
+ *
120
+ * @template T - The configuration type
121
+ * @param mcpConfig - Configuration from MCP (may be partial)
122
+ * @param defaults - Default configuration values
123
+ * @returns Merged configuration with defaults applied
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const defaults = {
128
+ * port: 3000,
129
+ * host: 'localhost',
130
+ * timeout: 5000,
131
+ * };
132
+ *
133
+ * const mcpConfig = {
134
+ * port: 8080,
135
+ * };
136
+ *
137
+ * const merged = mergeMCPConfigWithDefaults(mcpConfig, defaults);
138
+ * // { port: 8080, host: 'localhost', timeout: 5000 }
139
+ * ```
140
+ */
141
+ export declare function mergeMCPConfigWithDefaults<T extends Record<string, any>>(mcpConfig: Partial<T>, defaults: T): T;
@@ -0,0 +1,165 @@
1
+ import { ZodSchema } from 'zod';
2
+ import { ResolvedConfig, MCPInvocationContext, FileConfigSource } from './types';
3
+ import { ParseMCPConfigOptions } from './parser';
4
+ import { Logger } from '../types';
5
+ /**
6
+ * Options for resolving configuration from MCP, file, or environment variable sources.
7
+ */
8
+ export interface ConfigResolverOptions {
9
+ /**
10
+ * Zod schema to validate configuration against.
11
+ */
12
+ schema: ZodSchema;
13
+ /**
14
+ * Options for parsing MCP configuration.
15
+ */
16
+ mcpOptions?: ParseMCPConfigOptions;
17
+ /**
18
+ * Logger for debugging and informational messages.
19
+ */
20
+ logger?: Logger;
21
+ /**
22
+ * Function to resolve configuration from files.
23
+ * This is called when MCP configuration is not provided.
24
+ *
25
+ * @param workingDirectory - Directory to start file discovery from
26
+ * @returns Promise resolving to a FileConfigSource
27
+ */
28
+ resolveFileConfig?: (workingDirectory: string) => Promise<FileConfigSource>;
29
+ /**
30
+ * Application name for environment variable prefix generation.
31
+ * Required if environment variable resolution is enabled.
32
+ *
33
+ * @example 'riotplan' generates env vars like RIOTPLAN_PLAN_DIRECTORY
34
+ */
35
+ appName?: string;
36
+ /**
37
+ * Custom environment variable name mappings.
38
+ * Maps config field names to custom env var names.
39
+ *
40
+ * @example { openaiApiKey: 'OPENAI_API_KEY' }
41
+ */
42
+ envVarMap?: Record<string, string>;
43
+ /**
44
+ * Disable environment variable resolution.
45
+ * When true, env vars are not checked even if appName is provided.
46
+ *
47
+ * @default false
48
+ */
49
+ disableEnvVars?: boolean;
50
+ }
51
+ /**
52
+ * Resolves configuration using the MCP priority model.
53
+ *
54
+ * **Priority Model:**
55
+ * 1. If MCP config is present → use it exclusively
56
+ * 2. If MCP config is absent → try file-based discovery
57
+ * 3. If no file config found → try environment variables
58
+ * 4. No merging between sources
59
+ *
60
+ * This priority model makes configuration predictable and debuggable.
61
+ * Each source is checked in order, and the first one found is used exclusively.
62
+ *
63
+ * @template T - The configuration type
64
+ * @param context - MCP invocation context
65
+ * @param options - Resolution options including schema and resolvers
66
+ * @returns Promise resolving to a ResolvedConfig with source tracking
67
+ * @throws {MCPContextError} When no configuration source is available
68
+ * @throws {MCPConfigError} When MCP config is invalid
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const context: MCPInvocationContext = {
73
+ * config: { port: 3000, host: 'localhost' },
74
+ * workingDirectory: '/app',
75
+ * };
76
+ *
77
+ * const resolved = await resolveConfig(context, {
78
+ * schema: myConfigSchema,
79
+ * appName: 'myapp',
80
+ * logger: console,
81
+ * });
82
+ *
83
+ * console.log(resolved.resolution); // "Configuration loaded from MCP invocation"
84
+ * ```
85
+ */
86
+ export declare function resolveConfig<T = unknown>(context: MCPInvocationContext, options: ConfigResolverOptions): Promise<ResolvedConfig<T>>;
87
+ /**
88
+ * Generates a human-readable explanation of how configuration was resolved.
89
+ *
90
+ * This is useful for:
91
+ * - Debugging configuration issues
92
+ * - The CheckConfig tool
93
+ * - User-facing error messages
94
+ *
95
+ * @param resolved - The resolved configuration
96
+ * @returns Human-readable explanation string
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const explanation = explainResolution(resolved);
101
+ * // "Configuration loaded from MCP invocation"
102
+ * // "Configuration loaded from /app/config.yaml"
103
+ * // "Configuration merged from 3 files: /app/config.yaml, /app/src/config.yaml, /app/src/api/config.yaml"
104
+ * // "Configuration loaded from 5 environment variables"
105
+ * ```
106
+ */
107
+ export declare function explainResolution(resolved: ResolvedConfig): string;
108
+ /**
109
+ * Checks if a configuration was loaded from MCP.
110
+ *
111
+ * @param resolved - The resolved configuration
112
+ * @returns True if configuration came from MCP
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * if (isMCPConfig(resolved)) {
117
+ * console.log('Using MCP-provided configuration');
118
+ * }
119
+ * ```
120
+ */
121
+ export declare function isMCPConfig(resolved: ResolvedConfig): boolean;
122
+ /**
123
+ * Checks if a configuration was loaded from files.
124
+ *
125
+ * @param resolved - The resolved configuration
126
+ * @returns True if configuration came from files
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * if (isFileConfig(resolved)) {
131
+ * console.log(`Config file: ${resolved.source.filePath}`);
132
+ * }
133
+ * ```
134
+ */
135
+ export declare function isFileConfig(resolved: ResolvedConfig): boolean;
136
+ /**
137
+ * Checks if a configuration was loaded from environment variables.
138
+ *
139
+ * @param resolved - The resolved configuration
140
+ * @returns True if configuration came from environment variables
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * if (isEnvConfig(resolved)) {
145
+ * console.log(`Config from ${resolved.source.variables.size} env vars`);
146
+ * }
147
+ * ```
148
+ */
149
+ export declare function isEnvConfig(resolved: ResolvedConfig): boolean;
150
+ /**
151
+ * Gets the list of all configuration files that contributed to the resolved config.
152
+ *
153
+ * For MCP configs, returns an empty array.
154
+ * For file configs, returns the main file and all parent files.
155
+ *
156
+ * @param resolved - The resolved configuration
157
+ * @returns Array of file paths
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const files = getConfigFiles(resolved);
162
+ * console.log('Config loaded from:', files.join(', '));
163
+ * ```
164
+ */
165
+ export declare function getConfigFiles(resolved: ResolvedConfig): string[];
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Type definitions for the CheckConfig MCP tool.
3
+ *
4
+ * CheckConfig is a built-in diagnostic tool available in all CardiganTime-based
5
+ * MCP servers. It helps AI assistants understand how a tool is configured.
6
+ *
7
+ * @module mcp/tools/check-config
8
+ */
9
+ /**
10
+ * Input parameters for the CheckConfig tool.
11
+ */
12
+ export interface CheckConfigInput {
13
+ /**
14
+ * Optional file path to check configuration for.
15
+ *
16
+ * When provided, the tool will determine the most relevant configuration
17
+ * for this specific file (useful in hierarchical mode).
18
+ *
19
+ * @example "/app/src/api/handler.ts"
20
+ */
21
+ targetFile?: string;
22
+ /**
23
+ * Whether to include detailed configuration breakdown.
24
+ *
25
+ * When true, includes:
26
+ * - All config sources that were checked
27
+ * - Merge order (if hierarchical)
28
+ * - Which values came from which source
29
+ *
30
+ * @default false
31
+ */
32
+ verbose?: boolean;
33
+ /**
34
+ * Whether to include the full resolved configuration.
35
+ *
36
+ * When false, only shows a summary without the actual config values.
37
+ * Useful when you only need to know where config comes from.
38
+ *
39
+ * @default true
40
+ */
41
+ includeConfig?: boolean;
42
+ }
43
+ /**
44
+ * Source type for configuration.
45
+ */
46
+ export type ConfigSourceType = 'mcp' | 'file' | 'env' | 'defaults';
47
+ /**
48
+ * Information about a configuration value's source.
49
+ */
50
+ export interface ConfigValueSource {
51
+ /**
52
+ * The configuration field path (dot notation).
53
+ * @example "server.port"
54
+ */
55
+ field: string;
56
+ /**
57
+ * The value of the field (sanitized if sensitive).
58
+ */
59
+ value: unknown;
60
+ /**
61
+ * Where this value came from.
62
+ */
63
+ source: string;
64
+ /**
65
+ * Whether this value was sanitized for security.
66
+ */
67
+ sanitized: boolean;
68
+ }
69
+ /**
70
+ * Result of the CheckConfig tool.
71
+ */
72
+ export interface CheckConfigResult {
73
+ /**
74
+ * Where the configuration came from.
75
+ */
76
+ source: ConfigSourceType;
77
+ /**
78
+ * If file-based, the path(s) to configuration files.
79
+ * Ordered from most specific (closest) to least specific (furthest).
80
+ */
81
+ configPaths?: string[];
82
+ /**
83
+ * Whether hierarchical configuration lookup was used.
84
+ */
85
+ hierarchical: boolean;
86
+ /**
87
+ * The resolved configuration (with sensitive values sanitized).
88
+ * Only included if includeConfig is true.
89
+ */
90
+ config?: Record<string, unknown>;
91
+ /**
92
+ * Detailed breakdown of where each config value came from.
93
+ * Only included in verbose mode.
94
+ */
95
+ valueBreakdown?: ConfigValueSource[];
96
+ /**
97
+ * Human-readable summary of the configuration.
98
+ *
99
+ * @example "Configuration loaded from MCP invocation"
100
+ * @example "Configuration merged from 3 files: /app/config.yaml, /app/src/config.yaml, /app/src/api/config.yaml"
101
+ */
102
+ summary: string;
103
+ /**
104
+ * Links to relevant documentation.
105
+ */
106
+ documentation: {
107
+ /**
108
+ * Link to configuration guide.
109
+ */
110
+ configGuide: string;
111
+ /**
112
+ * Link to format reference (YAML, JSON, JS, TS).
113
+ */
114
+ formatReference: string;
115
+ /**
116
+ * Link to MCP integration guide.
117
+ */
118
+ mcpGuide: string;
119
+ };
120
+ /**
121
+ * Warnings or issues detected in the configuration.
122
+ */
123
+ warnings?: string[];
124
+ }
125
+ /**
126
+ * MCP tool descriptor for CheckConfig.
127
+ *
128
+ * This follows the MCP protocol specification for tool definitions.
129
+ */
130
+ export interface CheckConfigToolDescriptor {
131
+ /**
132
+ * Tool name (always 'check_config').
133
+ */
134
+ name: 'check_config';
135
+ /**
136
+ * Human-readable description of what the tool does.
137
+ */
138
+ description: string;
139
+ /**
140
+ * JSON Schema for the tool's input parameters.
141
+ */
142
+ inputSchema: {
143
+ type: 'object';
144
+ properties: {
145
+ targetFile?: {
146
+ type: 'string';
147
+ description: string;
148
+ };
149
+ verbose?: {
150
+ type: 'boolean';
151
+ description: string;
152
+ default: boolean;
153
+ };
154
+ includeConfig?: {
155
+ type: 'boolean';
156
+ description: string;
157
+ default: boolean;
158
+ };
159
+ };
160
+ additionalProperties: boolean;
161
+ };
162
+ }
163
+ /**
164
+ * Standard CheckConfig tool descriptor.
165
+ *
166
+ * This can be used directly when registering the tool with an MCP server.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * server.registerTool(CHECK_CONFIG_TOOL_DESCRIPTOR, async (input) => {
171
+ * return await checkConfig(input);
172
+ * });
173
+ * ```
174
+ */
175
+ export declare const CHECK_CONFIG_TOOL_DESCRIPTOR: CheckConfigToolDescriptor;
176
+ /**
177
+ * Patterns for detecting sensitive configuration fields.
178
+ *
179
+ * These patterns are used to sanitize sensitive values in CheckConfig output.
180
+ */
181
+ export declare const SENSITIVE_FIELD_PATTERNS: RegExp[];
182
+ /**
183
+ * Checks if a field name indicates sensitive data.
184
+ *
185
+ * @param fieldName - The field name to check
186
+ * @returns True if the field appears to contain sensitive data
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * isSensitiveField('apiKey'); // true
191
+ * isSensitiveField('password'); // true
192
+ * isSensitiveField('port'); // false
193
+ * ```
194
+ */
195
+ export declare function isSensitiveField(fieldName: string): boolean;
196
+ /**
197
+ * Sanitizes a sensitive value for display.
198
+ *
199
+ * @param value - The value to sanitize
200
+ * @returns Sanitized value (e.g., "***")
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * sanitizeValue('my-secret-key'); // "***"
205
+ * sanitizeValue(12345); // "***"
206
+ * ```
207
+ */
208
+ export declare function sanitizeValue(_value: unknown): string;