mcpgraph 0.1.18 → 0.1.20
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.
- package/README.md +69 -48
- package/dist/api.d.ts +7 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +11 -4
- package/dist/api.js.map +1 -1
- package/dist/config/expression-validator.d.ts.map +1 -1
- package/dist/config/expression-validator.js +12 -10
- package/dist/config/expression-validator.js.map +1 -1
- package/dist/config/loader.d.ts +8 -2
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +16 -2
- package/dist/config/loader.js.map +1 -1
- package/dist/config/mcp-loader.d.ts +13 -0
- package/dist/config/mcp-loader.d.ts.map +1 -0
- package/dist/config/mcp-loader.js +47 -0
- package/dist/config/mcp-loader.js.map +1 -0
- package/dist/config/schema.d.ts +292 -186
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +5 -6
- package/dist/config/schema.js.map +1 -1
- package/dist/execution/executor.d.ts +2 -2
- package/dist/execution/executor.d.ts.map +1 -1
- package/dist/execution/executor.js +22 -13
- package/dist/execution/executor.js.map +1 -1
- package/dist/graph/validator.d.ts.map +1 -1
- package/dist/graph/validator.js +52 -69
- package/dist/graph/validator.js.map +1 -1
- package/dist/main.js +23 -5
- package/dist/main.js.map +1 -1
- package/dist/types/config.d.ts +4 -5
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/execution.d.ts +9 -8
- package/dist/types/execution.d.ts.map +1 -1
- package/docs/building.md +76 -0
- package/docs/design.md +55 -43
- package/docs/github-pages-setup.md +492 -0
- package/docs/introspection-debugging.md +31 -6
- package/examples/api-usage.ts +3 -3
- package/examples/count_files.yaml +47 -52
- package/examples/loop_example.yaml +55 -58
- package/examples/switch_example.yaml +48 -55
- package/examples/test_minimal.yaml +23 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,13 +24,23 @@ version: "1.0"
|
|
|
24
24
|
server:
|
|
25
25
|
name: "fileUtils"
|
|
26
26
|
version: "1.0.0"
|
|
27
|
-
|
|
27
|
+
title: "File utilities"
|
|
28
|
+
instructions: "This server provides file utility tools for counting files in directories."
|
|
28
29
|
|
|
29
30
|
# Optional: Execution limits to prevent infinite loops
|
|
30
31
|
executionLimits:
|
|
31
32
|
maxNodeExecutions: 1000 # Maximum total node executions (default: 1000)
|
|
32
33
|
maxExecutionTimeMs: 300000 # Maximum execution time in milliseconds (default: 300000 = 5 minutes)
|
|
33
34
|
|
|
35
|
+
# MCP Servers used by the graph
|
|
36
|
+
mcpServers:
|
|
37
|
+
filesystem:
|
|
38
|
+
command: "npx"
|
|
39
|
+
args:
|
|
40
|
+
- "-y"
|
|
41
|
+
- "@modelcontextprotocol/server-filesystem"
|
|
42
|
+
- "./tests/counting"
|
|
43
|
+
|
|
34
44
|
# Tool Definitions
|
|
35
45
|
tools:
|
|
36
46
|
- name: "count_files"
|
|
@@ -49,45 +59,31 @@ tools:
|
|
|
49
59
|
count:
|
|
50
60
|
type: "number"
|
|
51
61
|
description: "The number of files in the directory"
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
- "
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
next: "count_files_node"
|
|
78
|
-
|
|
79
|
-
# Transform and count files
|
|
80
|
-
- id: "count_files_node"
|
|
81
|
-
type: "transform"
|
|
82
|
-
transform:
|
|
83
|
-
expr: |
|
|
84
|
-
{ "count": $count($split($.list_directory_node, "\n")) }
|
|
85
|
-
next: "exit_count_files"
|
|
86
|
-
|
|
87
|
-
# Exit node: Returns the count
|
|
88
|
-
- id: "exit_count_files"
|
|
89
|
-
type: "exit"
|
|
90
|
-
tool: "count_files"
|
|
62
|
+
nodes:
|
|
63
|
+
# Entry node: Receives tool arguments
|
|
64
|
+
- id: "entry"
|
|
65
|
+
type: "entry"
|
|
66
|
+
next: "list_directory_node"
|
|
67
|
+
|
|
68
|
+
# List directory contents
|
|
69
|
+
- id: "list_directory_node"
|
|
70
|
+
type: "mcp"
|
|
71
|
+
server: "filesystem"
|
|
72
|
+
tool: "list_directory"
|
|
73
|
+
args:
|
|
74
|
+
path: "$.entry.directory"
|
|
75
|
+
next: "count_files_node"
|
|
76
|
+
|
|
77
|
+
# Transform and count files
|
|
78
|
+
- id: "count_files_node"
|
|
79
|
+
type: "transform"
|
|
80
|
+
transform:
|
|
81
|
+
expr: '{ "count": $count($split($.list_directory_node, "\n")) }'
|
|
82
|
+
next: "exit"
|
|
83
|
+
|
|
84
|
+
# Exit node: Returns the count
|
|
85
|
+
- id: "exit"
|
|
86
|
+
type: "exit"
|
|
91
87
|
```
|
|
92
88
|
|
|
93
89
|
This graph:
|
|
@@ -104,6 +100,7 @@ This graph:
|
|
|
104
100
|
- **Output**: The MCP tool's response (parsed from the tool's content)
|
|
105
101
|
- **`transform`**: Applies [JSONata](https://jsonata.org/) expressions to transform data between nodes.
|
|
106
102
|
- **Output**: The result of evaluating the JSONata expression
|
|
103
|
+
- **Expression Format**: The `expr` field is a string containing a JSONata expression. Use single-quoted strings for simple expressions: `expr: '{ "result": "value" }'`. Use block scalars (`|`) for complex multi-line expressions to improve readability.
|
|
107
104
|
- **`switch`**: Uses [JSON Logic](https://jsonlogic.com/) to conditionally route to different nodes. Note: `var` operations in JSON Logic rules are evaluated using JSONata, allowing full JSONata expression support.
|
|
108
105
|
- **Output**: The node ID of the target node that was routed to (string)
|
|
109
106
|
- **`exit`**: Exit point that returns the final result to the MCP tool caller.
|
|
@@ -130,10 +127,33 @@ mcpGraph maintains a complete execution history for each tool execution, enablin
|
|
|
130
127
|
See [docs/introspection-debugging.md](docs/introspection-debugging.md) for detailed documentation on debugging features.
|
|
131
128
|
|
|
132
129
|
**Context Access:**
|
|
133
|
-
- All node outputs are accessible by node ID (e.g., `$.
|
|
130
|
+
- All node outputs are accessible by node ID (e.g., `$.entry.directory`, `$.list_directory_node`)
|
|
134
131
|
- Latest execution wins: `$.increment_node` returns the most recent output when a node executes multiple times
|
|
135
132
|
- History functions are available in all JSONata expressions (including those used in JSON Logic `var` operations)
|
|
136
133
|
|
|
134
|
+
### JSONata Expression Format
|
|
135
|
+
|
|
136
|
+
The `expr` field in transform nodes is a string containing a JSONata expression. In YAML, you can use either:
|
|
137
|
+
|
|
138
|
+
- **Single-quoted strings** (`'...'`) for simple, single-line expressions:
|
|
139
|
+
```yaml
|
|
140
|
+
transform:
|
|
141
|
+
expr: '{ "count": $count($split($.list_directory_node, "\n")) }'
|
|
142
|
+
```
|
|
143
|
+
This keeps the expression on one line and is ideal for simple transformations.
|
|
144
|
+
|
|
145
|
+
- **Block scalars** (`|`) for complex, multi-line expressions:
|
|
146
|
+
```yaml
|
|
147
|
+
transform:
|
|
148
|
+
expr: |
|
|
149
|
+
$executionCount("increment_node") = 0
|
|
150
|
+
? { "counter": 1, "sum": 1, "target": $.entry_sum.n }
|
|
151
|
+
: { "counter": $nodeExecution("increment_node", -1).counter + 1, ... }
|
|
152
|
+
```
|
|
153
|
+
This improves readability for expressions with conditional logic, nested objects, or multiple operations.
|
|
154
|
+
|
|
155
|
+
Both forms work identically - the expression is evaluated as a string by JSONata. Use single quotes for simple expressions and block scalars for complex ones to improve readability.
|
|
156
|
+
|
|
137
157
|
## For Developers
|
|
138
158
|
|
|
139
159
|
If you're interested in contributing to mcpGraph or working with the source code, see [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions, development guidelines, and project structure.
|
|
@@ -162,9 +182,10 @@ mcpGraph supports cyclical graphs, which requires guardrails to prevent infinite
|
|
|
162
182
|
version: "1.0"
|
|
163
183
|
|
|
164
184
|
server:
|
|
165
|
-
name: "myServer"
|
|
166
|
-
version: "1.0.0"
|
|
167
|
-
|
|
185
|
+
name: "myServer" # Required: unique identifier
|
|
186
|
+
version: "1.0.0" # Required: server version
|
|
187
|
+
title: "My MCP server" # Optional: display name (defaults to name if not provided)
|
|
188
|
+
instructions: "Instructions for using this server" # Optional: server usage instructions
|
|
168
189
|
|
|
169
190
|
# Optional: Execution limits to prevent infinite loops
|
|
170
191
|
executionLimits:
|
|
@@ -197,7 +218,7 @@ Add `mcpgraph` to your Claude Desktop MCP configuration (typically located at `~
|
|
|
197
218
|
"mcpgraph": {
|
|
198
219
|
"command": "mcpgraph",
|
|
199
220
|
"args": [
|
|
200
|
-
"-
|
|
221
|
+
"-g",
|
|
201
222
|
"/path/to/your/config.yaml"
|
|
202
223
|
]
|
|
203
224
|
}
|
|
@@ -215,7 +236,7 @@ Or if not installed (run from npm):
|
|
|
215
236
|
"args": [
|
|
216
237
|
"-y",
|
|
217
238
|
"mcpgraph",
|
|
218
|
-
"-
|
|
239
|
+
"-g",
|
|
219
240
|
"/path/to/your/config.yaml"
|
|
220
241
|
]
|
|
221
242
|
}
|
|
@@ -223,7 +244,7 @@ Or if not installed (run from npm):
|
|
|
223
244
|
}
|
|
224
245
|
```
|
|
225
246
|
|
|
226
|
-
**Note:** Replace `/path/to/your/config.yaml` with the actual path to your YAML configuration file. The `-
|
|
247
|
+
**Note:** Replace `/path/to/your/config.yaml` with the actual path to your YAML configuration file. The `-g` (or `--graph`) flag specifies the graph configuration file to use.
|
|
227
248
|
|
|
228
249
|
### Programmatic API
|
|
229
250
|
|
|
@@ -240,7 +261,7 @@ const tools = api.listTools();
|
|
|
240
261
|
|
|
241
262
|
// Execute a tool
|
|
242
263
|
const result = await api.executeTool('count_files', {
|
|
243
|
-
directory: './tests/
|
|
264
|
+
directory: './tests/counting',
|
|
244
265
|
});
|
|
245
266
|
|
|
246
267
|
// Clean up resources
|
package/dist/api.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - UX applications - for HTTP/WebSocket servers
|
|
7
7
|
* - Other applications - for programmatic graph execution
|
|
8
8
|
*/
|
|
9
|
-
import type { McpGraphConfig } from './types/config.js';
|
|
9
|
+
import type { McpGraphConfig, ServerConfig } from './types/config.js';
|
|
10
10
|
import { type ValidationError } from './graph/validator.js';
|
|
11
11
|
import type { ExecutionOptions, ExecutionResult as CoreExecutionResult, ExecutionController, ExecutionState, NodeExecutionRecord } from './types/execution.js';
|
|
12
12
|
export type { NodeDefinition, McpGraphConfig } from './types/config.js';
|
|
@@ -30,16 +30,19 @@ export declare class McpGraphApi {
|
|
|
30
30
|
/**
|
|
31
31
|
* Create a new McpGraphApi instance
|
|
32
32
|
* @param configPath - Path to the YAML configuration file
|
|
33
|
+
* @param mcpServersFromFile - Optional mcpServers loaded from an MCP JSON file
|
|
33
34
|
* @throws Error if config cannot be loaded or validated
|
|
34
35
|
*/
|
|
35
|
-
constructor(configPath: string);
|
|
36
|
+
constructor(configPath: string, mcpServersFromFile?: Record<string, ServerConfig>);
|
|
36
37
|
/**
|
|
37
38
|
* Get the server metadata
|
|
39
|
+
* Title defaults to name if not provided (matching MCP SDK behavior)
|
|
38
40
|
*/
|
|
39
41
|
getServerInfo(): {
|
|
40
42
|
name: string;
|
|
41
43
|
version: string;
|
|
42
|
-
|
|
44
|
+
title: string;
|
|
45
|
+
instructions?: string;
|
|
43
46
|
};
|
|
44
47
|
/**
|
|
45
48
|
* List all available tools
|
|
@@ -65,7 +68,7 @@ export declare class McpGraphApi {
|
|
|
65
68
|
/**
|
|
66
69
|
* Get the graph structure
|
|
67
70
|
*/
|
|
68
|
-
getGraph(): import("./graph/graph.js").Graph;
|
|
71
|
+
getGraph(): import("./graph/graph.js").Graph | null;
|
|
69
72
|
/**
|
|
70
73
|
* Get the current execution state (if execution is in progress)
|
|
71
74
|
*/
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":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"}
|
package/dist/api.js
CHANGED
|
@@ -18,11 +18,12 @@ export class McpGraphApi {
|
|
|
18
18
|
/**
|
|
19
19
|
* Create a new McpGraphApi instance
|
|
20
20
|
* @param configPath - Path to the YAML configuration file
|
|
21
|
+
* @param mcpServersFromFile - Optional mcpServers loaded from an MCP JSON file
|
|
21
22
|
* @throws Error if config cannot be loaded or validated
|
|
22
23
|
*/
|
|
23
|
-
constructor(configPath) {
|
|
24
|
+
constructor(configPath, mcpServersFromFile) {
|
|
24
25
|
logger.info(`Loading configuration from: ${configPath}`);
|
|
25
|
-
const config = loadConfig(configPath);
|
|
26
|
+
const config = loadConfig(configPath, mcpServersFromFile);
|
|
26
27
|
const errors = validateGraph(config);
|
|
27
28
|
if (errors.length > 0) {
|
|
28
29
|
const errorMessages = errors.map((e) => e.message).join(', ');
|
|
@@ -31,17 +32,23 @@ export class McpGraphApi {
|
|
|
31
32
|
this.config = config;
|
|
32
33
|
this.clientManager = new McpClientManager();
|
|
33
34
|
this.executor = new GraphExecutor(config, this.clientManager);
|
|
34
|
-
|
|
35
|
+
const title = config.server.title || config.server.name;
|
|
36
|
+
logger.info(`Loaded configuration: ${config.server.name} v${config.server.version} - ${title}`);
|
|
37
|
+
if (config.server.instructions) {
|
|
38
|
+
logger.debug(`Server instructions: ${config.server.instructions}`);
|
|
39
|
+
}
|
|
35
40
|
logger.info(`Tools defined: ${config.tools.map(t => t.name).join(', ')}`);
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* Get the server metadata
|
|
44
|
+
* Title defaults to name if not provided (matching MCP SDK behavior)
|
|
39
45
|
*/
|
|
40
46
|
getServerInfo() {
|
|
41
47
|
return {
|
|
42
48
|
name: this.config.server.name,
|
|
43
49
|
version: this.config.server.version,
|
|
44
|
-
|
|
50
|
+
title: this.config.server.title || this.config.server.name, // Default to name if title not provided
|
|
51
|
+
instructions: this.config.server.instructions,
|
|
45
52
|
};
|
|
46
53
|
}
|
|
47
54
|
/**
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAwB,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAmC3D,MAAM,OAAO,WAAW;IACd,MAAM,CAAiB;IACvB,QAAQ,CAAgB;IACxB,aAAa,CAAmB;IAExC
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAwB,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAmC3D,MAAM,OAAO,WAAW;IACd,MAAM,CAAiB;IACvB,QAAQ,CAAgB;IACxB,aAAa,CAAmB;IAExC;;;;;OAKG;IACH,YAAY,UAAkB,EAAE,kBAAiD;QAC/E,MAAM,CAAC,IAAI,CAAC,+BAA+B,UAAU,EAAE,CAAC,CAAC;QAEzD,MAAM,MAAM,GAAG,UAAU,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QAE1D,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,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file":"expression-validator.d.ts","sourceRoot":"","sources":["../../src/config/expression-validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,oBAAoB,CAAC;AAGzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,cAAc,GAAG,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"expression-validator.d.ts","sourceRoot":"","sources":["../../src/config/expression-validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,oBAAoB,CAAC;AAGzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,cAAc,GAAG,eAAe,EAAE,CAkBnF"}
|
|
@@ -10,16 +10,18 @@ import { validateJsonLogicSyntax } from "../expressions/json-logic.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export function validateConfigExpressions(config) {
|
|
12
12
|
const errors = [];
|
|
13
|
-
for (const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
for (const tool of config.tools) {
|
|
14
|
+
for (const node of tool.nodes) {
|
|
15
|
+
try {
|
|
16
|
+
validateNodeExpressions(node, config);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
20
|
+
errors.push({
|
|
21
|
+
message: errorMessage,
|
|
22
|
+
nodeId: node.id,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
return errors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression-validator.js","sourceRoot":"","sources":["../../src/config/expression-validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAGvE;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAsB;IAC9D,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"expression-validator.js","sourceRoot":"","sources":["../../src/config/expression-validator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAGvE;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAsB;IAC9D,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,CAAC;gBACH,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACxC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5E,MAAM,CAAC,IAAI,CAAC;oBACV,OAAO,EAAE,YAAY;oBACrB,MAAM,EAAE,IAAI,CAAC,EAAE;iBAChB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,IAAoB,EAAE,MAAsB;IAC3E,QAAQ,IAAI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,KAAK,SAAS,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;oBAC5D,IAAI,CAAC;wBACH,uBAAuB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;oBAC1C,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;wBAC5E,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,GAAG,CAAC,KAAK,YAAY,EAAE,CAAC,CAAC;oBACtF,CAAC;gBACH,CAAC;YACH,CAAC;YACD,MAAM;QAER,KAAK,OAAO,CAAC;QACb,KAAK,MAAM;YACT,6BAA6B;YAC7B,MAAM;IACV,CAAC;AACH,CAAC"}
|
package/dist/config/loader.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Configuration loader for mcpGraph
|
|
3
3
|
*/
|
|
4
|
-
import type { McpGraphConfig } from "../types/config.js";
|
|
5
|
-
|
|
4
|
+
import type { McpGraphConfig, ServerConfig } from "../types/config.js";
|
|
5
|
+
/**
|
|
6
|
+
* Load graph configuration, optionally merging mcpServers from an MCP JSON file
|
|
7
|
+
* @param graphFilePath - Path to the YAML graph configuration file
|
|
8
|
+
* @param mcpServersFromFile - Optional mcpServers loaded from an MCP JSON file
|
|
9
|
+
* @returns McpGraphConfig with merged mcpServers (graph servers override mcp file servers)
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadConfig(graphFilePath: string, mcpServersFromFile?: Record<string, ServerConfig>): McpGraphConfig;
|
|
6
12
|
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvE;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,aAAa,EAAE,MAAM,EACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAChD,cAAc,CAYhB"}
|
package/dist/config/loader.js
CHANGED
|
@@ -2,7 +2,21 @@
|
|
|
2
2
|
* Configuration loader for mcpGraph
|
|
3
3
|
*/
|
|
4
4
|
import { parseYamlConfig } from "./parser.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Load graph configuration, optionally merging mcpServers from an MCP JSON file
|
|
7
|
+
* @param graphFilePath - Path to the YAML graph configuration file
|
|
8
|
+
* @param mcpServersFromFile - Optional mcpServers loaded from an MCP JSON file
|
|
9
|
+
* @returns McpGraphConfig with merged mcpServers (graph servers override mcp file servers)
|
|
10
|
+
*/
|
|
11
|
+
export function loadConfig(graphFilePath, mcpServersFromFile) {
|
|
12
|
+
const config = parseYamlConfig(graphFilePath);
|
|
13
|
+
// Merge mcpServers: mcp file servers first, then graph servers (graph overrides)
|
|
14
|
+
if (mcpServersFromFile) {
|
|
15
|
+
config.mcpServers = {
|
|
16
|
+
...mcpServersFromFile,
|
|
17
|
+
...(config.mcpServers || {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return config;
|
|
7
21
|
}
|
|
8
22
|
//# sourceMappingURL=loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,UAAU,UAAU,
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,aAAqB,EACrB,kBAAiD;IAEjD,MAAM,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC;IAE9C,iFAAiF;IACjF,IAAI,kBAAkB,EAAE,CAAC;QACvB,MAAM,CAAC,UAAU,GAAG;YAClB,GAAG,kBAAkB;YACrB,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;SAC7B,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP JSON file loader for mcpGraph
|
|
3
|
+
* Loads mcpServers from a standard MCP configuration JSON file
|
|
4
|
+
*/
|
|
5
|
+
import type { ServerConfig } from "../types/config.js";
|
|
6
|
+
/**
|
|
7
|
+
* Load mcpServers from an MCP JSON configuration file
|
|
8
|
+
* @param filePath - Path to the MCP JSON file (typically mcp.json)
|
|
9
|
+
* @returns Record of server name to ServerConfig, or undefined if file doesn't exist or has no mcpServers
|
|
10
|
+
* @throws Error if file exists but cannot be parsed or validated
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadMcpServers(filePath: string): Record<string, ServerConfig> | undefined;
|
|
13
|
+
//# sourceMappingURL=mcp-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-loader.d.ts","sourceRoot":"","sources":["../../src/config/mcp-loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAQvD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,SAAS,CA6BzF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP JSON file loader for mcpGraph
|
|
3
|
+
* Loads mcpServers from a standard MCP configuration JSON file
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { logger } from "../logger.js";
|
|
8
|
+
import { serverConfigSchema } from "./schema.js";
|
|
9
|
+
// Schema for MCP JSON file structure
|
|
10
|
+
const mcpJsonFileSchema = z.object({
|
|
11
|
+
mcpServers: z.record(serverConfigSchema).optional(),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Load mcpServers from an MCP JSON configuration file
|
|
15
|
+
* @param filePath - Path to the MCP JSON file (typically mcp.json)
|
|
16
|
+
* @returns Record of server name to ServerConfig, or undefined if file doesn't exist or has no mcpServers
|
|
17
|
+
* @throws Error if file exists but cannot be parsed or validated
|
|
18
|
+
*/
|
|
19
|
+
export function loadMcpServers(filePath) {
|
|
20
|
+
try {
|
|
21
|
+
logger.info(`Loading MCP servers from: ${filePath}`);
|
|
22
|
+
const fileContents = readFileSync(filePath, "utf-8");
|
|
23
|
+
const parsed = JSON.parse(fileContents);
|
|
24
|
+
// Validate file structure and server configs (all validated at once)
|
|
25
|
+
const validated = mcpJsonFileSchema.parse(parsed);
|
|
26
|
+
if (!validated.mcpServers || Object.keys(validated.mcpServers).length === 0) {
|
|
27
|
+
logger.info(`No mcpServers found in ${filePath}`);
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
// All servers are already validated by the schema, just cast to the correct type
|
|
31
|
+
const servers = validated.mcpServers;
|
|
32
|
+
logger.info(`Loaded ${Object.keys(servers).length} MCP server(s) from ${filePath}`);
|
|
33
|
+
return servers;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
// Check if it's a file not found error
|
|
38
|
+
if (error.code === "ENOENT") {
|
|
39
|
+
throw new Error(`MCP file not found: ${filePath}`);
|
|
40
|
+
}
|
|
41
|
+
logger.error(`Failed to load MCP file: ${error.message}`);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
throw new Error("Unknown error loading MCP file");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=mcp-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-loader.js","sourceRoot":"","sources":["../../src/config/mcp-loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,qCAAqC;AACrC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,QAAQ,EAAE;CACpD,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,IAAI,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;QACrD,MAAM,YAAY,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAY,CAAC;QAEnD,qEAAqE;QACrE,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAElD,IAAI,CAAC,SAAS,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5E,MAAM,CAAC,IAAI,CAAC,0BAA0B,QAAQ,E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