@graph-ir/mcp-server 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Graph-IR Tools contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # @graph-ir/mcp-server
2
+
3
+ MCP (Model Context Protocol) server for Graph-IR validation, generation, visualization, and layout.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @graph-ir/mcp-server
9
+ ```
10
+
11
+ ## Usage with Claude Code
12
+
13
+ Add to your Claude Code configuration:
14
+
15
+ ```bash
16
+ claude mcp add graph-ir-tools -- node /home/coreyt/projects/graph-ir-tools/packages/mcp-server/dist/index.js
17
+ ```
18
+
19
+ Or add to `.claude/settings.json`:
20
+
21
+ ```json
22
+ {
23
+ "mcpServers": {
24
+ "graph-ir-tools": {
25
+ "command": "node",
26
+ "args": ["/home/coreyt/projects/graph-ir-tools/packages/mcp-server/dist/index.js"]
27
+ }
28
+ }
29
+ }
30
+ ```
31
+
32
+ ## Available Tools
33
+
34
+ ### validate_ir
35
+
36
+ Validate Graph-IR JSON against schema and semantic rules.
37
+
38
+ **Input:**
39
+ - `ir` (string, required): Graph-IR JSON string
40
+ - `strict` (boolean): Treat warnings as errors
41
+
42
+ **Output:**
43
+ - `valid`: Whether the IR is valid
44
+ - `errors`: Array of error objects
45
+ - `warnings`: Array of warning objects
46
+ - `stats`: Node and edge counts
47
+
48
+ ### generate_ir
49
+
50
+ Generate Graph-IR from natural language description.
51
+
52
+ **Input:**
53
+ - `description` (string, required): Natural language description
54
+ - `style` (string): Generation style (default, compact, detailed)
55
+
56
+ **Output:**
57
+ - `success`: Whether generation succeeded
58
+ - `ir`: Generated Graph-IR object
59
+ - `notes`: Generation notes
60
+
61
+ ### visualize_ir
62
+
63
+ Generate ASCII visualization of Graph-IR.
64
+
65
+ **Input:**
66
+ - `ir` (string, required): Graph-IR JSON string
67
+ - `style` (string): Visualization style (box, compact, tree)
68
+
69
+ **Output:**
70
+ - `success`: Whether visualization succeeded
71
+ - `visualization`: ASCII art string
72
+
73
+ ### layout_ir
74
+
75
+ Compute graph layout using ELK algorithms.
76
+
77
+ **Input:**
78
+ - `ir` (string, required): Graph-IR JSON string
79
+ - `algorithm` (string): Layout algorithm (layered, force, mrtree, box, stress)
80
+ - `options` (object): Additional layout options
81
+
82
+ **Output:**
83
+ - `success`: Whether layout succeeded
84
+ - `ir`: Graph-IR with layout coordinates added
85
+
86
+ ## Development
87
+
88
+ ```bash
89
+ # Install dependencies
90
+ npm install
91
+
92
+ # Build
93
+ npm run build
94
+
95
+ # Run tests
96
+ npm test
97
+
98
+ # Start server (for debugging)
99
+ npm start
100
+ ```
101
+
102
+ ## Related
103
+
104
+ - [Graph-IR Specification](../../specs/graph-ir/)
105
+ - [CONSOLIDATION-PLAN.md](../../CONSOLIDATION-PLAN.md)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,257 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
+ import { validateIR } from './tools/validate.js';
6
+ import { generateIR } from './tools/generate.js';
7
+ import { visualizeIR } from './tools/visualize.js';
8
+ import { layoutIR } from './tools/layout.js';
9
+ import { listSymbols } from './tools/list-symbols.js';
10
+ import { listNotations } from './tools/list-notations.js';
11
+ import { validateNotation } from './tools/validate-notation.js';
12
+ const server = new Server({
13
+ name: 'graph-ir-tools',
14
+ version: '0.1.0',
15
+ }, {
16
+ capabilities: {
17
+ tools: {},
18
+ },
19
+ });
20
+ // List available tools
21
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
22
+ tools: [
23
+ {
24
+ name: 'validate_ir',
25
+ description: 'Validate Graph-IR JSON against schema and semantic rules',
26
+ inputSchema: {
27
+ type: 'object',
28
+ properties: {
29
+ ir: {
30
+ type: 'string',
31
+ description: 'Graph-IR JSON string to validate',
32
+ },
33
+ strict: {
34
+ type: 'boolean',
35
+ description: 'Treat warnings as errors',
36
+ default: false,
37
+ },
38
+ },
39
+ required: ['ir'],
40
+ },
41
+ },
42
+ {
43
+ name: 'generate_ir',
44
+ description: 'Generate Graph-IR from a natural language description',
45
+ inputSchema: {
46
+ type: 'object',
47
+ properties: {
48
+ description: {
49
+ type: 'string',
50
+ description: 'Natural language description of the graph',
51
+ },
52
+ style: {
53
+ type: 'string',
54
+ enum: ['default', 'compact', 'detailed'],
55
+ description: 'Generation style',
56
+ default: 'default',
57
+ },
58
+ },
59
+ required: ['description'],
60
+ },
61
+ },
62
+ {
63
+ name: 'visualize_ir',
64
+ description: 'Generate ASCII visualization of Graph-IR',
65
+ inputSchema: {
66
+ type: 'object',
67
+ properties: {
68
+ ir: {
69
+ type: 'string',
70
+ description: 'Graph-IR JSON string to visualize',
71
+ },
72
+ style: {
73
+ type: 'string',
74
+ enum: ['box', 'compact', 'tree'],
75
+ description: 'Visualization style',
76
+ default: 'box',
77
+ },
78
+ },
79
+ required: ['ir'],
80
+ },
81
+ },
82
+ {
83
+ name: 'layout_ir',
84
+ description: 'Compute graph layout using ELK algorithm',
85
+ inputSchema: {
86
+ type: 'object',
87
+ properties: {
88
+ ir: {
89
+ type: 'string',
90
+ description: 'Graph-IR JSON string to layout',
91
+ },
92
+ algorithm: {
93
+ type: 'string',
94
+ enum: ['layered', 'force', 'mrtree', 'box', 'stress'],
95
+ description: 'ELK algorithm to use',
96
+ default: 'layered',
97
+ },
98
+ options: {
99
+ type: 'object',
100
+ description: 'Additional ELK layout options',
101
+ },
102
+ },
103
+ required: ['ir'],
104
+ },
105
+ },
106
+ {
107
+ name: 'list_symbols',
108
+ description: 'List available symbols with optional filtering',
109
+ inputSchema: {
110
+ type: 'object',
111
+ properties: {
112
+ notation: {
113
+ type: 'string',
114
+ description: 'Filter by notation ID',
115
+ },
116
+ tag: {
117
+ type: 'string',
118
+ description: 'Filter by tag',
119
+ },
120
+ query: {
121
+ type: 'string',
122
+ description: 'Search query (matches name/description)',
123
+ },
124
+ full: {
125
+ type: 'boolean',
126
+ description: 'Include full definitions (default: false, returns IDs only)',
127
+ default: false,
128
+ },
129
+ },
130
+ },
131
+ },
132
+ {
133
+ name: 'list_notations',
134
+ description: 'List available notations',
135
+ inputSchema: {
136
+ type: 'object',
137
+ properties: {
138
+ full: {
139
+ type: 'boolean',
140
+ description: 'Include full definitions (default: false, returns IDs only)',
141
+ default: false,
142
+ },
143
+ },
144
+ },
145
+ },
146
+ {
147
+ name: 'validate_notation',
148
+ description: 'Validate Graph-IR against notation rules (symbol validity, connection rules)',
149
+ inputSchema: {
150
+ type: 'object',
151
+ properties: {
152
+ ir: {
153
+ type: 'string',
154
+ description: 'Graph-IR JSON string to validate',
155
+ },
156
+ notation: {
157
+ type: 'string',
158
+ description: 'Notation to validate against (overrides metadata.notation)',
159
+ },
160
+ strict: {
161
+ type: 'boolean',
162
+ description: 'Treat warnings as errors',
163
+ default: false,
164
+ },
165
+ },
166
+ required: ['ir'],
167
+ },
168
+ },
169
+ ],
170
+ }));
171
+ // Handle tool calls
172
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
173
+ const { name, arguments: args } = request.params;
174
+ try {
175
+ switch (name) {
176
+ case 'validate_ir': {
177
+ const result = await validateIR(args?.ir, args?.strict);
178
+ return formatResult(result);
179
+ }
180
+ case 'generate_ir': {
181
+ const result = await generateIR(args?.description, args?.style);
182
+ return formatResult(result);
183
+ }
184
+ case 'visualize_ir': {
185
+ const result = await visualizeIR(args?.ir, args?.style);
186
+ return formatResult(result);
187
+ }
188
+ case 'layout_ir': {
189
+ const result = await layoutIR(args?.ir, args?.algorithm, args?.options);
190
+ return formatResult(result);
191
+ }
192
+ case 'list_symbols': {
193
+ const result = await listSymbols({
194
+ notation: args?.notation,
195
+ tag: args?.tag,
196
+ query: args?.query,
197
+ full: args?.full,
198
+ });
199
+ return formatResult(result);
200
+ }
201
+ case 'list_notations': {
202
+ const result = await listNotations({
203
+ full: args?.full,
204
+ });
205
+ return formatResult(result);
206
+ }
207
+ case 'validate_notation': {
208
+ const result = await validateNotation({
209
+ ir: args?.ir,
210
+ notation: args?.notation,
211
+ strict: args?.strict,
212
+ });
213
+ return formatResult(result);
214
+ }
215
+ default:
216
+ return {
217
+ content: [
218
+ {
219
+ type: 'text',
220
+ text: `Unknown tool: ${name}`,
221
+ },
222
+ ],
223
+ isError: true,
224
+ };
225
+ }
226
+ }
227
+ catch (error) {
228
+ return {
229
+ content: [
230
+ {
231
+ type: 'text',
232
+ text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
233
+ },
234
+ ],
235
+ isError: true,
236
+ };
237
+ }
238
+ });
239
+ function formatResult(result) {
240
+ return {
241
+ content: [
242
+ {
243
+ type: 'text',
244
+ text: JSON.stringify(result, null, 2),
245
+ },
246
+ ],
247
+ isError: 'errors' in result && Array.isArray(result.errors) && result.errors.length > 0,
248
+ };
249
+ }
250
+ // Start the server
251
+ async function main() {
252
+ const transport = new StdioServerTransport();
253
+ await server.connect(transport);
254
+ console.error('Graph-IR Tools MCP server running on stdio');
255
+ }
256
+ main().catch(console.error);
257
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAoB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAoB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAgB,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAqB,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAuB,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAA0B,MAAM,8BAA8B,CAAC;AAExF,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;IACE,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,OAAO;CACjB,EACD;IACE,YAAY,EAAE;QACZ,KAAK,EAAE,EAAE;KACV;CACF,CACF,CAAC;AAEF,uBAAuB;AACvB,MAAM,CAAC,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AO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,UAAU,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE;iBAC3E;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,SAAS,YAAY,CACnB,MAO0B;IAE1B,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;aACtC;SACF;QACD,OAAO,EAAE,QAAQ,IAAI,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;KACxF,CAAC;AACJ,CAAC;AAED,mBAAmB;AACnB,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;AAC9D,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Graph-IR Generation Tool
3
+ *
4
+ * Generates Graph-IR from natural language descriptions.
5
+ * Note: Full NL processing would require an LLM - this provides
6
+ * pattern-based generation for common cases.
7
+ */
8
+ export interface GenerationResult {
9
+ success: boolean;
10
+ ir?: GraphIR;
11
+ errors: string[];
12
+ notes: string[];
13
+ }
14
+ interface GraphIR {
15
+ version: string;
16
+ nodes: Array<{
17
+ id: string;
18
+ type: string;
19
+ label: string;
20
+ }>;
21
+ edges: Array<{
22
+ id: string;
23
+ source: string;
24
+ target: string;
25
+ label?: string;
26
+ }>;
27
+ }
28
+ /**
29
+ * Generate Graph-IR from description
30
+ */
31
+ export declare function generateIR(description: string, style?: string): Promise<GenerationResult>;
32
+ export {};
33
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/tools/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH,KAAK,EAAE,KAAK,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ;AAoBD;;GAEG;AACH,wBAAsB,UAAU,CAC9B,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,MAAkB,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAsE3B"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Graph-IR Generation Tool
3
+ *
4
+ * Generates Graph-IR from natural language descriptions.
5
+ * Note: Full NL processing would require an LLM - this provides
6
+ * pattern-based generation for common cases.
7
+ */
8
+ // Entity type mapping from keywords
9
+ const TYPE_KEYWORDS = {
10
+ service: ['service', 'microservice', 'api', 'server', 'backend', 'frontend'],
11
+ database: ['database', 'db', 'store', 'storage', 'cache', 'redis', 'postgres', 'mysql', 'mongodb'],
12
+ actor: ['user', 'customer', 'client', 'admin', 'actor', 'person'],
13
+ external_api: ['external', 'third-party', '3rd party', 'gateway', 'payment'],
14
+ module: ['module', 'component', 'package', 'library', 'lib'],
15
+ group: ['group', 'cluster', 'boundary', 'container'],
16
+ };
17
+ // Relationship keywords
18
+ const RELATIONSHIP_KEYWORDS = {
19
+ http: ['calls', 'requests', 'invokes', 'fetches'],
20
+ database: ['reads', 'queries', 'writes', 'stores', 'persists'],
21
+ event: ['sends', 'publishes', 'emits', 'subscribes'],
22
+ contains: ['contains', 'includes', 'has'],
23
+ };
24
+ /**
25
+ * Generate Graph-IR from description
26
+ */
27
+ export async function generateIR(description, style = 'default') {
28
+ const errors = [];
29
+ const notes = [];
30
+ if (!description || description.trim().length === 0) {
31
+ return {
32
+ success: false,
33
+ errors: ['Description is required'],
34
+ notes: [],
35
+ };
36
+ }
37
+ const lowerDesc = description.toLowerCase();
38
+ // Extract entities
39
+ const entities = extractEntities(lowerDesc);
40
+ if (entities.length === 0) {
41
+ notes.push('No specific entities detected - using generic nodes');
42
+ // Create generic nodes from the description
43
+ const words = description.split(/[\s,]+/).filter(w => w.length > 2);
44
+ const genericNodes = words.slice(0, 3).map(word => ({
45
+ name: word,
46
+ type: 'module',
47
+ }));
48
+ entities.push(...genericNodes);
49
+ }
50
+ // Extract relationships
51
+ const relationships = extractRelationships(lowerDesc, entities);
52
+ // Build Graph-IR
53
+ const nodes = entities.map((entity, index) => ({
54
+ id: toId(entity.name),
55
+ type: entity.type,
56
+ label: toLabel(entity.name),
57
+ }));
58
+ const edges = relationships.map((rel, index) => ({
59
+ id: `e${index + 1}`,
60
+ source: rel.source,
61
+ target: rel.target,
62
+ label: rel.label,
63
+ }));
64
+ // Add implicit edges if none found
65
+ if (edges.length === 0 && nodes.length > 1) {
66
+ notes.push('No explicit relationships found - adding sequential connections');
67
+ for (let i = 0; i < nodes.length - 1; i++) {
68
+ edges.push({
69
+ id: `e${i + 1}`,
70
+ source: nodes[i].id,
71
+ target: nodes[i + 1].id,
72
+ label: undefined,
73
+ });
74
+ }
75
+ }
76
+ const ir = {
77
+ version: '1.0.0',
78
+ nodes,
79
+ edges,
80
+ };
81
+ return {
82
+ success: true,
83
+ ir,
84
+ errors,
85
+ notes,
86
+ };
87
+ }
88
+ function extractEntities(text) {
89
+ const entities = [];
90
+ const foundNames = new Set();
91
+ // Look for type keywords followed by potential names
92
+ for (const [type, keywords] of Object.entries(TYPE_KEYWORDS)) {
93
+ for (const keyword of keywords) {
94
+ // Pattern: "keyword name" or "name keyword"
95
+ const patterns = [
96
+ new RegExp(`${keyword}\\s+([a-z][a-z0-9_-]*)`, 'gi'),
97
+ new RegExp(`([a-z][a-z0-9_-]*)\\s+${keyword}`, 'gi'),
98
+ ];
99
+ for (const pattern of patterns) {
100
+ let match;
101
+ while ((match = pattern.exec(text)) !== null) {
102
+ const name = match[1].toLowerCase();
103
+ if (!foundNames.has(name) && name.length > 1 && !isStopWord(name)) {
104
+ foundNames.add(name);
105
+ entities.push({ name, type });
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ // Also look for quoted strings as names
112
+ const quotedPattern = /"([^"]+)"/g;
113
+ let match;
114
+ while ((match = quotedPattern.exec(text)) !== null) {
115
+ const name = match[1].toLowerCase();
116
+ if (!foundNames.has(name)) {
117
+ foundNames.add(name);
118
+ entities.push({ name, type: 'module' });
119
+ }
120
+ }
121
+ return entities;
122
+ }
123
+ function extractRelationships(text, entities) {
124
+ const relationships = [];
125
+ const entityIds = entities.map(e => toId(e.name));
126
+ // Look for relationship patterns
127
+ for (const [label, keywords] of Object.entries(RELATIONSHIP_KEYWORDS)) {
128
+ for (const keyword of keywords) {
129
+ // Pattern: "A calls B" or "A -> B"
130
+ const pattern = new RegExp(`([a-z][a-z0-9_-]*)\\s+(?:${keyword}|->|→)\\s+([a-z][a-z0-9_-]*)`, 'gi');
131
+ let match;
132
+ while ((match = pattern.exec(text)) !== null) {
133
+ const source = toId(match[1]);
134
+ const target = toId(match[2]);
135
+ // Only add if both ends are known entities
136
+ if (entityIds.includes(source) && entityIds.includes(target)) {
137
+ relationships.push({ source, target, label });
138
+ }
139
+ }
140
+ }
141
+ }
142
+ return relationships;
143
+ }
144
+ function toId(name) {
145
+ return name
146
+ .toLowerCase()
147
+ .replace(/[^a-z0-9]+/g, '-')
148
+ .replace(/^-|-$/g, '');
149
+ }
150
+ function toLabel(name) {
151
+ return name
152
+ .split(/[-_\s]+/)
153
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
154
+ .join(' ');
155
+ }
156
+ function isStopWord(word) {
157
+ const stopWords = ['the', 'a', 'an', 'and', 'or', 'with', 'to', 'from', 'for', 'in', 'on'];
158
+ return stopWords.includes(word.toLowerCase());
159
+ }
160
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/tools/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwBH,oCAAoC;AACpC,MAAM,aAAa,GAA6B;IAC9C,OAAO,EAAE,CAAC,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC;IAC5E,QAAQ,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC;IAClG,KAAK,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;IACjE,YAAY,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC;IAC5E,MAAM,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC;IAC5D,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC;CACrD,CAAC;AAEF,wBAAwB;AACxB,MAAM,qBAAqB,GAA6B;IACtD,IAAI,EAAE,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