@likec4/language-server 1.37.0 → 1.38.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/dist/LikeC4LanguageServices.d.ts +7 -4
- package/dist/LikeC4LanguageServices.js +12 -2
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/bundled.mjs +4263 -3104
- package/dist/empty.d.ts +2 -0
- package/dist/empty.js +1 -0
- package/dist/filesystem/ChokidarWatcher.d.ts +14 -0
- package/dist/filesystem/ChokidarWatcher.js +64 -0
- package/dist/filesystem/FileSystemWatcher.d.ts +19 -0
- package/dist/filesystem/FileSystemWatcher.js +11 -0
- package/dist/filesystem/LikeC4FileSystem.d.ts +5 -0
- package/dist/filesystem/LikeC4FileSystem.js +56 -0
- package/dist/filesystem/index.d.ts +20 -0
- package/dist/filesystem/index.js +16 -0
- package/dist/index.d.ts +18 -4
- package/dist/index.js +23 -10
- package/dist/mcp/{sseserver/MCPServerFactory.d.ts → MCPServerFactory.d.ts} +1 -1
- package/dist/mcp/MCPServerFactory.js +69 -0
- package/dist/mcp/NoopLikeC4MCPServer.d.ts +4 -10
- package/dist/mcp/NoopLikeC4MCPServer.js +5 -10
- package/dist/mcp/interfaces.d.ts +7 -5
- package/dist/mcp/interfaces.js +4 -0
- package/dist/mcp/server/StdioLikeC4MCPServer.d.ts +16 -0
- package/dist/mcp/server/StdioLikeC4MCPServer.js +43 -0
- package/dist/mcp/{sseserver/MCPServer.d.ts → server/StreamableLikeC4MCPServer.d.ts} +3 -2
- package/dist/mcp/server/StreamableLikeC4MCPServer.js +156 -0
- package/dist/mcp/server/WithMCPServer.d.ts +2 -0
- package/dist/mcp/server/WithMCPServer.js +57 -0
- package/dist/mcp/tools/_common.d.ts +24 -5
- package/dist/mcp/tools/_common.js +31 -3
- package/dist/mcp/tools/find-relationships.d.ts +13 -0
- package/dist/mcp/tools/find-relationships.js +151 -0
- package/dist/mcp/tools/list-projects.js +40 -12
- package/dist/mcp/tools/open-view.d.ts +4 -3
- package/dist/mcp/tools/open-view.js +37 -14
- package/dist/mcp/tools/{read-project-elements.d.ts → read-deployment.d.ts} +6 -3
- package/dist/mcp/tools/read-deployment.js +130 -0
- package/dist/mcp/tools/read-element.d.ts +4 -3
- package/dist/mcp/tools/read-element.js +114 -51
- package/dist/mcp/tools/read-project-summary.d.ts +3 -2
- package/dist/mcp/tools/read-project-summary.js +139 -32
- package/dist/mcp/tools/read-view.d.ts +4 -3
- package/dist/mcp/tools/read-view.js +146 -105
- package/dist/mcp/tools/search-element.js +81 -30
- package/dist/mcp/utils.js +7 -4
- package/dist/module.d.ts +9 -9
- package/dist/module.js +24 -29
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +1 -1
- package/dist/test/testServices.js +3 -2
- package/dist/workspace/ProjectsManager.js +5 -2
- package/dist/workspace/WorkspaceManager.d.ts +9 -2
- package/dist/workspace/WorkspaceManager.js +30 -39
- package/package.json +14 -10
- package/dist/LikeC4FileSystem.d.ts +0 -14
- package/dist/LikeC4FileSystem.js +0 -39
- package/dist/mcp/sseserver/MCPServer.js +0 -80
- package/dist/mcp/sseserver/MCPServerFactory.js +0 -50
- package/dist/mcp/sseserver/WithMCPServer.d.ts +0 -9
- package/dist/mcp/sseserver/WithMCPServer.js +0 -53
- package/dist/mcp/tools/read-project-elements.js +0 -93
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { serve } from "@hono/node-server";
|
|
2
|
+
import { loggable } from "@likec4/log";
|
|
3
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
|
+
import { toFetchResponse, toReqRes } from "fetch-to-node";
|
|
5
|
+
import { Hono } from "hono";
|
|
6
|
+
import { createServer } from "node:http";
|
|
7
|
+
import { logger } from "../utils.js";
|
|
8
|
+
export class StreamableLikeC4MCPServer {
|
|
9
|
+
constructor(services) {
|
|
10
|
+
this.services = services;
|
|
11
|
+
}
|
|
12
|
+
// Store transports by session ID to send notifications
|
|
13
|
+
server = void 0;
|
|
14
|
+
_port = 33335;
|
|
15
|
+
get mcp() {
|
|
16
|
+
throw new Error("StreamableLikeC4MCPServer has access to McpServer only during the request");
|
|
17
|
+
}
|
|
18
|
+
get isStarted() {
|
|
19
|
+
return this.server?.listening === true;
|
|
20
|
+
}
|
|
21
|
+
get port() {
|
|
22
|
+
return this._port;
|
|
23
|
+
}
|
|
24
|
+
async dispose() {
|
|
25
|
+
await this.stop();
|
|
26
|
+
}
|
|
27
|
+
async start(port = 33335) {
|
|
28
|
+
if (this.server) {
|
|
29
|
+
if (this.port === port) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
await this.stop();
|
|
33
|
+
}
|
|
34
|
+
logger.info("Starting MCP server on port {port}", { port });
|
|
35
|
+
this._port = port;
|
|
36
|
+
const app = new Hono().post("/mcp", async (c) => {
|
|
37
|
+
const { req, res } = toReqRes(c.req.raw);
|
|
38
|
+
const server = this.services.mcp.ServerFactory.create();
|
|
39
|
+
try {
|
|
40
|
+
const transport = new StreamableHTTPServerTransport({
|
|
41
|
+
sessionIdGenerator: void 0
|
|
42
|
+
});
|
|
43
|
+
transport.onerror = (err) => {
|
|
44
|
+
logger.error(loggable(err));
|
|
45
|
+
};
|
|
46
|
+
await server.connect(transport);
|
|
47
|
+
await transport.handleRequest(req, res, await c.req.json());
|
|
48
|
+
res.on("close", () => {
|
|
49
|
+
logger.debug("Request closed");
|
|
50
|
+
transport.close();
|
|
51
|
+
server.close();
|
|
52
|
+
});
|
|
53
|
+
return toFetchResponse(res);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
logger.error(loggable(e));
|
|
56
|
+
return c.json(
|
|
57
|
+
{
|
|
58
|
+
jsonrpc: "2.0",
|
|
59
|
+
error: {
|
|
60
|
+
code: -32603,
|
|
61
|
+
message: "Internal server error"
|
|
62
|
+
},
|
|
63
|
+
id: null
|
|
64
|
+
},
|
|
65
|
+
{ status: 500 }
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}).get("/mcp", async (c) => {
|
|
69
|
+
logger.debug("Received GET MCP request");
|
|
70
|
+
return c.json(
|
|
71
|
+
{
|
|
72
|
+
jsonrpc: "2.0",
|
|
73
|
+
error: {
|
|
74
|
+
code: -32e3,
|
|
75
|
+
message: "Method not allowed."
|
|
76
|
+
},
|
|
77
|
+
id: null
|
|
78
|
+
},
|
|
79
|
+
{ status: 405 }
|
|
80
|
+
);
|
|
81
|
+
}).delete("/mcp", async (c) => {
|
|
82
|
+
logger.debug("Received DELETE MCP request");
|
|
83
|
+
return c.json(
|
|
84
|
+
{
|
|
85
|
+
jsonrpc: "2.0",
|
|
86
|
+
error: {
|
|
87
|
+
code: -32e3,
|
|
88
|
+
message: "Method not allowed."
|
|
89
|
+
},
|
|
90
|
+
id: null
|
|
91
|
+
},
|
|
92
|
+
{ status: 405 }
|
|
93
|
+
);
|
|
94
|
+
}).notFound((c) => {
|
|
95
|
+
logger.debug(`${c.req.method} ${c.req.url} not found`);
|
|
96
|
+
return c.json(
|
|
97
|
+
{
|
|
98
|
+
jsonrpc: "2.0",
|
|
99
|
+
error: {
|
|
100
|
+
code: -32e3,
|
|
101
|
+
message: "Method not found."
|
|
102
|
+
},
|
|
103
|
+
id: null
|
|
104
|
+
},
|
|
105
|
+
{ status: 404 }
|
|
106
|
+
);
|
|
107
|
+
}).onError((e, c) => {
|
|
108
|
+
logger.error(loggable(e));
|
|
109
|
+
return c.json(
|
|
110
|
+
{
|
|
111
|
+
jsonrpc: "2.0",
|
|
112
|
+
error: {
|
|
113
|
+
code: -32603,
|
|
114
|
+
message: "Internal server error"
|
|
115
|
+
},
|
|
116
|
+
id: null
|
|
117
|
+
},
|
|
118
|
+
{ status: 500 }
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
try {
|
|
123
|
+
this.server = serve(
|
|
124
|
+
{
|
|
125
|
+
fetch: app.fetch,
|
|
126
|
+
port: this._port,
|
|
127
|
+
createServer
|
|
128
|
+
},
|
|
129
|
+
(info) => {
|
|
130
|
+
logger.info("MCP server listening on port {port}", { port: info.port });
|
|
131
|
+
resolve();
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
reject(err);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async stop() {
|
|
140
|
+
const server = this.server;
|
|
141
|
+
if (!server) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
logger.info("Stopping MCP server");
|
|
145
|
+
this.server = void 0;
|
|
146
|
+
return new Promise((resolve) => {
|
|
147
|
+
server.close((err) => {
|
|
148
|
+
if (err) {
|
|
149
|
+
logger.error("Failed to stop MCP server", { err });
|
|
150
|
+
}
|
|
151
|
+
logger.info("MCP server stopped");
|
|
152
|
+
resolve();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { loggable } from "@likec4/log";
|
|
2
|
+
import { isError } from "remeda";
|
|
3
|
+
import { logger } from "../../logger.js";
|
|
4
|
+
import { StdioLikeC4MCPServer } from "./StdioLikeC4MCPServer.js";
|
|
5
|
+
import { StreamableLikeC4MCPServer } from "./StreamableLikeC4MCPServer.js";
|
|
6
|
+
const streamableLikeC4MCPServer = (services) => {
|
|
7
|
+
logger.debug("Creating StreamableLikeC4MCPServer");
|
|
8
|
+
const server = new StreamableLikeC4MCPServer(services);
|
|
9
|
+
const langId = services.LanguageMetaData.languageId;
|
|
10
|
+
const connection = services.shared.lsp.Connection;
|
|
11
|
+
services.shared.workspace.ConfigurationProvider.onConfigurationSectionUpdate((update) => {
|
|
12
|
+
if (update.section !== langId) {
|
|
13
|
+
logger.warn("Unexpected configuration update: {update}", { update });
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
logger.debug("Configuration update: {update}", { update });
|
|
17
|
+
const {
|
|
18
|
+
enabled = false,
|
|
19
|
+
port = 33335
|
|
20
|
+
} = update.configuration.mcp;
|
|
21
|
+
if (!enabled) {
|
|
22
|
+
server.stop();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
Promise.resolve().then(() => server.start(port)).then(() => {
|
|
26
|
+
connection?.telemetry?.logEvent({
|
|
27
|
+
eventName: "mcp-server-started",
|
|
28
|
+
mcpPort: port
|
|
29
|
+
});
|
|
30
|
+
}).catch((err) => {
|
|
31
|
+
const message = isError(err) ? err.message : void 0;
|
|
32
|
+
connection?.telemetry?.logEvent({
|
|
33
|
+
eventName: "mcp-server-start-failed",
|
|
34
|
+
mcpPort: port,
|
|
35
|
+
...message && { message }
|
|
36
|
+
});
|
|
37
|
+
logger.error("Failed to start LikeC4 MCP Server", { err });
|
|
38
|
+
if (connection) {
|
|
39
|
+
connection.window.showErrorMessage(`LikeC4: Failed to start MCP Server
|
|
40
|
+
|
|
41
|
+
${loggable(err)}`);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return server;
|
|
46
|
+
};
|
|
47
|
+
const stdioLikeC4MCPServer = (services) => {
|
|
48
|
+
return new StdioLikeC4MCPServer(services);
|
|
49
|
+
};
|
|
50
|
+
export const WithMCPServer = (type = "sse") => ({
|
|
51
|
+
mcpServer: (services) => {
|
|
52
|
+
if (type === "stdio") {
|
|
53
|
+
return stdioLikeC4MCPServer(services);
|
|
54
|
+
}
|
|
55
|
+
return streamableLikeC4MCPServer(services);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type { LikeC4ViewModel } from '@likec4/core/model';
|
|
1
2
|
import z from 'zod';
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
import type { LikeC4LanguageServices } from '../../LikeC4LanguageServices';
|
|
4
|
+
import type { Locate } from '../../protocol';
|
|
5
|
+
export declare const locationSchema: z.ZodNullable<z.ZodObject<{
|
|
6
|
+
path: z.ZodString;
|
|
4
7
|
range: z.ZodObject<{
|
|
5
8
|
start: z.ZodObject<{
|
|
6
9
|
line: z.ZodNumber;
|
|
@@ -42,7 +45,6 @@ export declare const locationSchema: z.ZodObject<{
|
|
|
42
45
|
};
|
|
43
46
|
}>;
|
|
44
47
|
}, "strip", z.ZodTypeAny, {
|
|
45
|
-
uri: string;
|
|
46
48
|
range: {
|
|
47
49
|
start: {
|
|
48
50
|
line: number;
|
|
@@ -53,8 +55,8 @@ export declare const locationSchema: z.ZodObject<{
|
|
|
53
55
|
character: number;
|
|
54
56
|
};
|
|
55
57
|
};
|
|
58
|
+
path: string;
|
|
56
59
|
}, {
|
|
57
|
-
uri: string;
|
|
58
60
|
range: {
|
|
59
61
|
start: {
|
|
60
62
|
line: number;
|
|
@@ -65,4 +67,21 @@ export declare const locationSchema: z.ZodObject<{
|
|
|
65
67
|
character: number;
|
|
66
68
|
};
|
|
67
69
|
};
|
|
68
|
-
|
|
70
|
+
path: string;
|
|
71
|
+
}>>;
|
|
72
|
+
export declare const projectIdSchema: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodString, ProjectId, string>>>;
|
|
73
|
+
export declare const includedInViewsSchema: z.ZodArray<z.ZodObject<{
|
|
74
|
+
id: z.ZodString;
|
|
75
|
+
title: z.ZodString;
|
|
76
|
+
type: z.ZodEnum<["element", "deployment", "dynamic"]>;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
title: string;
|
|
79
|
+
id: string;
|
|
80
|
+
type: "deployment" | "dynamic" | "element";
|
|
81
|
+
}, {
|
|
82
|
+
title: string;
|
|
83
|
+
id: string;
|
|
84
|
+
type: "deployment" | "dynamic" | "element";
|
|
85
|
+
}>, "many">;
|
|
86
|
+
export declare const includedInViews: (views: Iterable<LikeC4ViewModel>) => z.infer<typeof includedInViewsSchema>;
|
|
87
|
+
export declare const mkLocate: (languageServices: LikeC4LanguageServices, projectId: string) => (params: Locate.Params) => z.infer<typeof locationSchema>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { URI } from "vscode-uri";
|
|
1
2
|
import z from "zod";
|
|
3
|
+
import { ProjectsManager } from "../../workspace/index.js";
|
|
4
|
+
import { logger } from "../utils.js";
|
|
2
5
|
export const locationSchema = z.object({
|
|
3
|
-
|
|
6
|
+
path: z.string().describe("Path to the file"),
|
|
4
7
|
range: z.object({
|
|
5
8
|
start: z.object({
|
|
6
9
|
line: z.number(),
|
|
@@ -10,5 +13,30 @@ export const locationSchema = z.object({
|
|
|
10
13
|
line: z.number(),
|
|
11
14
|
character: z.number()
|
|
12
15
|
})
|
|
13
|
-
})
|
|
14
|
-
});
|
|
16
|
+
}).describe("Range in the file")
|
|
17
|
+
}).nullable();
|
|
18
|
+
export const projectIdSchema = z.string().refine((v) => true).optional().default(ProjectsManager.DefaultProjectId).describe('Project id (optional, will use "default" if not specified)');
|
|
19
|
+
export const includedInViewsSchema = z.array(z.object({
|
|
20
|
+
id: z.string().describe("View id"),
|
|
21
|
+
title: z.string().describe("View title"),
|
|
22
|
+
type: z.enum(["element", "deployment", "dynamic"]).describe("View type")
|
|
23
|
+
}));
|
|
24
|
+
export const includedInViews = (views) => {
|
|
25
|
+
return [...views].map((v) => ({
|
|
26
|
+
id: v.id,
|
|
27
|
+
title: v.titleOrId,
|
|
28
|
+
type: v.$view._type
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
export const mkLocate = (languageServices, projectId) => (params) => {
|
|
32
|
+
try {
|
|
33
|
+
const loc = languageServices.locate({ projectId, ...params });
|
|
34
|
+
return loc ? {
|
|
35
|
+
path: URI.parse(loc.uri).fsPath,
|
|
36
|
+
range: loc.range
|
|
37
|
+
} : null;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
logger.debug(`Failed to locate ${params}`, { error: e });
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export declare const findRelationships: (languageServices: import("../..").LikeC4LanguageServices) => [string, {
|
|
3
|
+
inputSchema?: {
|
|
4
|
+
element1: z.ZodString;
|
|
5
|
+
element2: z.ZodString;
|
|
6
|
+
project: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodString, ProjectId, string>>>;
|
|
7
|
+
} | undefined;
|
|
8
|
+
}, (args: {
|
|
9
|
+
[x: string]: any;
|
|
10
|
+
element1?: unknown;
|
|
11
|
+
element2?: unknown;
|
|
12
|
+
project?: unknown;
|
|
13
|
+
}, extra: import("@modelcontextprotocol/sdk/shared/protocol").RequestHandlerExtra<import("@modelcontextprotocol/sdk/types").ServerRequest, import("@modelcontextprotocol/sdk/types").ServerNotification>) => import("@modelcontextprotocol/sdk/types").CallToolResult | Promise<import("@modelcontextprotocol/sdk/types").CallToolResult>];
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { modelConnection } from "@likec4/core/model";
|
|
2
|
+
import { invariant, isSameHierarchy } from "@likec4/core/utils";
|
|
3
|
+
import z from "zod";
|
|
4
|
+
import { likec4Tool } from "../utils.js";
|
|
5
|
+
import { includedInViews, includedInViewsSchema, locationSchema, mkLocate, projectIdSchema } from "./_common.js";
|
|
6
|
+
const endpointSchema = z.object({
|
|
7
|
+
id: z.string(),
|
|
8
|
+
title: z.string(),
|
|
9
|
+
kind: z.string()
|
|
10
|
+
});
|
|
11
|
+
const searchResultSchema = z.object({
|
|
12
|
+
type: z.enum(["direct", "indirect"]).describe(
|
|
13
|
+
'Type of relationship, "direct" for direct relationships, "indirect" for relationships through nested elements'
|
|
14
|
+
),
|
|
15
|
+
source: endpointSchema,
|
|
16
|
+
target: endpointSchema,
|
|
17
|
+
kind: z.string().nullable().describe("Relationship kind"),
|
|
18
|
+
title: z.string().nullable().describe("Relationship title"),
|
|
19
|
+
description: z.string().nullable().describe("Relationship description"),
|
|
20
|
+
technology: z.string().nullable().describe("Relationship technology"),
|
|
21
|
+
tags: z.array(z.string()).describe("Relationship tags"),
|
|
22
|
+
includedInViews: includedInViewsSchema.describe("Views that include this relationship"),
|
|
23
|
+
sourceLocation: locationSchema
|
|
24
|
+
});
|
|
25
|
+
export const findRelationships = likec4Tool({
|
|
26
|
+
name: "find-relationships",
|
|
27
|
+
annotations: {
|
|
28
|
+
readOnlyHint: true,
|
|
29
|
+
idempotentHint: true,
|
|
30
|
+
title: "Find relationships between two elements"
|
|
31
|
+
},
|
|
32
|
+
description: `
|
|
33
|
+
Find relationships between two LikeC4 elements within a project.
|
|
34
|
+
|
|
35
|
+
What it does:
|
|
36
|
+
- Finds both direct relationships (element1 \u2194 element2) and indirect ones that arise via containment (e.g. via nested elements).
|
|
37
|
+
- Returns rich metadata for each relationship and where it appears in views.
|
|
38
|
+
|
|
39
|
+
Inputs:
|
|
40
|
+
- element1: string \u2014 Element ID (FQN)
|
|
41
|
+
- element2: string \u2014 Element ID (FQN)
|
|
42
|
+
- project: string (optional, defaults to "default") \u2014 Project id
|
|
43
|
+
|
|
44
|
+
Output:
|
|
45
|
+
- found: Relationship[]
|
|
46
|
+
|
|
47
|
+
Relationship (object) fields:
|
|
48
|
+
- type: "direct" | "indirect" \u2014 direct is between the specified endpoints; indirect is via nested elements
|
|
49
|
+
- source: Endpoint
|
|
50
|
+
- target: Endpoint
|
|
51
|
+
- kind: string|null \u2014 relationship kind from the model
|
|
52
|
+
- title: string|null \u2014 relationship title if provided
|
|
53
|
+
- description: string|null \u2014 relationship description text
|
|
54
|
+
- technology: string|null \u2014 relationship technology
|
|
55
|
+
- tags: string[] \u2014 relationship tags
|
|
56
|
+
- includedInViews: View[] \u2014 views where this relationship appears
|
|
57
|
+
- sourceLocation: { path: string, range: { start: { line: number, character: number }, end: { line: number, character: number } } } | null
|
|
58
|
+
|
|
59
|
+
Endpoint (object) fields:
|
|
60
|
+
- id: string \u2014 Element ID (FQN)
|
|
61
|
+
- title: string \u2014 element title
|
|
62
|
+
- kind: string \u2014 element kind
|
|
63
|
+
|
|
64
|
+
View (object) fields:
|
|
65
|
+
- id: string \u2014 view identifier
|
|
66
|
+
- title: string \u2014 view title
|
|
67
|
+
- type: "element" | "deployment" | "dynamic"
|
|
68
|
+
|
|
69
|
+
Notes:
|
|
70
|
+
- Read-only, idempotent; does not mutate the model. May trigger UI navigation in supporting clients.
|
|
71
|
+
- The order of results is not guaranteed.
|
|
72
|
+
|
|
73
|
+
Example:
|
|
74
|
+
Request:
|
|
75
|
+
{
|
|
76
|
+
"element1": "shop.frontend",
|
|
77
|
+
"element2": "shop.backend",
|
|
78
|
+
"project": "default"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Response:
|
|
82
|
+
{
|
|
83
|
+
"found": [
|
|
84
|
+
{
|
|
85
|
+
"type": "direct",
|
|
86
|
+
"source": { "id": "shop.frontend", "title": "Frontend", "kind": "component" },
|
|
87
|
+
"target": { "id": "shop.backend", "title": "Backend", "kind": "component" },
|
|
88
|
+
"kind": "sync",
|
|
89
|
+
"title": "Calls",
|
|
90
|
+
"description": "Frontend calls Backend",
|
|
91
|
+
"technology": "HTTP",
|
|
92
|
+
"tags": ["public"],
|
|
93
|
+
"includedInViews": [
|
|
94
|
+
{ "id": "system-overview", "title": "System Overview", "type": "element" }
|
|
95
|
+
],
|
|
96
|
+
"sourceLocation": {
|
|
97
|
+
"path": "/abs/path/project/model.c4",
|
|
98
|
+
"range": { "start": { "line": 12, "character": 0 }, "end": { "line": 14, "character": 0 } }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
`,
|
|
104
|
+
inputSchema: {
|
|
105
|
+
element1: z.string().describe("Element ID (FQN)"),
|
|
106
|
+
element2: z.string().describe("Element ID (FQN)"),
|
|
107
|
+
project: projectIdSchema
|
|
108
|
+
},
|
|
109
|
+
outputSchema: {
|
|
110
|
+
found: z.array(searchResultSchema)
|
|
111
|
+
}
|
|
112
|
+
}, async (languageServices, args) => {
|
|
113
|
+
const projectId = languageServices.projectsManager.ensureProjectId(args.project);
|
|
114
|
+
if (isSameHierarchy(args.element1, args.element2)) {
|
|
115
|
+
throw new Error("No relationships possible between parent-child");
|
|
116
|
+
}
|
|
117
|
+
const found = [];
|
|
118
|
+
const model = await languageServices.computedModel(projectId);
|
|
119
|
+
const el1 = model.findElement(args.element1);
|
|
120
|
+
invariant(el1, `Element "${args.element1}" not found in project "${projectId}"`);
|
|
121
|
+
const el2 = model.findElement(args.element2);
|
|
122
|
+
invariant(el2, `Element "${args.element2}" not found in project "${projectId}"`);
|
|
123
|
+
const locate = mkLocate(languageServices, projectId);
|
|
124
|
+
const relationships = modelConnection.findConnection(el1, el2, "both").flatMap((c) => [...c.relations]);
|
|
125
|
+
for (const relationship of relationships) {
|
|
126
|
+
const isDirect = relationship.source === el1 && relationship.target === el2 || relationship.source === el2 && relationship.target === el1;
|
|
127
|
+
found.push({
|
|
128
|
+
type: isDirect ? "direct" : "indirect",
|
|
129
|
+
source: {
|
|
130
|
+
id: relationship.source.id,
|
|
131
|
+
title: relationship.source.title,
|
|
132
|
+
kind: relationship.source.kind
|
|
133
|
+
},
|
|
134
|
+
target: {
|
|
135
|
+
id: relationship.target.id,
|
|
136
|
+
title: relationship.target.title,
|
|
137
|
+
kind: relationship.target.kind
|
|
138
|
+
},
|
|
139
|
+
kind: relationship.kind,
|
|
140
|
+
title: relationship.title,
|
|
141
|
+
description: relationship.description.text,
|
|
142
|
+
technology: relationship.technology,
|
|
143
|
+
tags: [...relationship.tags],
|
|
144
|
+
includedInViews: includedInViews(relationship.views()),
|
|
145
|
+
sourceLocation: locate({ relation: relationship.id })
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
found
|
|
150
|
+
};
|
|
151
|
+
});
|
|
@@ -3,32 +3,60 @@ import { likec4Tool } from "../utils.js";
|
|
|
3
3
|
export const listProjects = likec4Tool({
|
|
4
4
|
name: "list-projects",
|
|
5
5
|
description: `
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
List LikeC4 projects discoverable in the current workspace.
|
|
7
|
+
|
|
8
|
+
Request:
|
|
9
|
+
- No input parameters.
|
|
10
|
+
|
|
11
|
+
Response (JSON object):
|
|
12
|
+
- projects: Project[]
|
|
13
|
+
|
|
14
|
+
Project (object) fields:
|
|
15
|
+
- id: string \u2014 stable project identifier
|
|
16
|
+
- title: string \u2014 human-readable project title
|
|
17
|
+
- folder: string \u2014 absolute path to the project root
|
|
18
|
+
- sources: string[] \u2014 absolute file paths of related documents
|
|
19
|
+
|
|
20
|
+
Notes:
|
|
21
|
+
- Read-only, idempotent, no side effects.
|
|
22
|
+
- Safe to call repeatedly.
|
|
23
|
+
|
|
24
|
+
Example response:
|
|
25
|
+
{
|
|
26
|
+
"projects": [
|
|
27
|
+
{
|
|
28
|
+
"id": "docs",
|
|
29
|
+
"title": "Documentation",
|
|
30
|
+
"folder": "/abs/path/to/workspace/docs",
|
|
31
|
+
"sources": [
|
|
32
|
+
"/abs/path/to/workspace/docs/model/contexts.likec4",
|
|
33
|
+
"/abs/path/to/workspace/docs/model/relations.likec4"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
12
38
|
`,
|
|
13
39
|
annotations: {
|
|
14
|
-
readOnlyHint: true
|
|
40
|
+
readOnlyHint: true,
|
|
41
|
+
idempotentHint: true,
|
|
42
|
+
title: "List projects"
|
|
15
43
|
},
|
|
16
44
|
outputSchema: {
|
|
17
45
|
projects: z.array(z.object({
|
|
18
|
-
|
|
46
|
+
id: z.string(),
|
|
19
47
|
title: z.string(),
|
|
20
48
|
folder: z.string(),
|
|
21
49
|
sources: z.array(z.string())
|
|
22
50
|
}))
|
|
23
51
|
}
|
|
24
52
|
}, async (languageServices) => {
|
|
25
|
-
const projects =
|
|
53
|
+
const projects = languageServices.projects();
|
|
26
54
|
return {
|
|
27
55
|
projects: projects.map((p) => ({
|
|
28
|
-
|
|
56
|
+
id: p.id,
|
|
29
57
|
title: p.title,
|
|
30
|
-
folder: p.folder.
|
|
31
|
-
sources: p.documents
|
|
58
|
+
folder: p.folder.fsPath,
|
|
59
|
+
sources: p.documents.map((d) => d.fsPath)
|
|
32
60
|
}))
|
|
33
61
|
};
|
|
34
62
|
});
|
|
@@ -2,9 +2,10 @@ import z from 'zod';
|
|
|
2
2
|
export declare const openView: (languageServices: import("../..").LikeC4LanguageServices) => [string, {
|
|
3
3
|
inputSchema?: {
|
|
4
4
|
viewId: z.ZodString;
|
|
5
|
-
project: z.ZodOptional<z.ZodString
|
|
5
|
+
project: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodString, ProjectId, string>>>;
|
|
6
6
|
} | undefined;
|
|
7
7
|
}, (args: {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
[x: string]: any;
|
|
9
|
+
viewId?: unknown;
|
|
10
|
+
project?: unknown;
|
|
10
11
|
}, extra: import("@modelcontextprotocol/sdk/shared/protocol").RequestHandlerExtra<import("@modelcontextprotocol/sdk/types").ServerRequest, import("@modelcontextprotocol/sdk/types").ServerNotification>) => import("@modelcontextprotocol/sdk/types").CallToolResult | Promise<import("@modelcontextprotocol/sdk/types").CallToolResult>];
|
|
@@ -1,29 +1,52 @@
|
|
|
1
|
-
import { invariant } from "@likec4/core";
|
|
2
1
|
import z from "zod";
|
|
3
|
-
import { ProjectsManager } from "../../workspace/index.js";
|
|
4
2
|
import { likec4Tool } from "../utils.js";
|
|
3
|
+
import { locationSchema, mkLocate, projectIdSchema } from "./_common.js";
|
|
5
4
|
export const openView = likec4Tool({
|
|
6
5
|
name: "open-view",
|
|
7
6
|
description: `
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
Open a LikeC4 view in the editor's preview panel.
|
|
8
|
+
|
|
9
|
+
Request:
|
|
10
|
+
- viewId: string \u2014 view id (name)
|
|
11
|
+
- project: string (optional) \u2014 project id. Defaults to "default" if omitted.
|
|
12
|
+
|
|
13
|
+
Response (JSON object):
|
|
14
|
+
- location: { path: string, range: { start: { line: number, character: number }, end: { line: number, character: number } } } | null \u2014 source location of the view if available
|
|
15
|
+
|
|
16
|
+
Notes:
|
|
17
|
+
- Read-only and idempotent with respect to the project model. Triggers a UI action in the editor.
|
|
18
|
+
- Only one preview panel can be open at a time.
|
|
19
|
+
|
|
20
|
+
Example response:
|
|
21
|
+
{
|
|
22
|
+
"location": {
|
|
23
|
+
"path": "/abs/path/project/model.c4",
|
|
24
|
+
"range": { "start": { "line": 10, "character": 0 }, "end": { "line": 30, "character": 0 } }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`,
|
|
11
28
|
annotations: {
|
|
12
|
-
readOnlyHint: true
|
|
29
|
+
readOnlyHint: true,
|
|
30
|
+
idempotentHint: true,
|
|
31
|
+
title: "Open view in preview panel"
|
|
13
32
|
},
|
|
14
33
|
inputSchema: {
|
|
15
34
|
viewId: z.string().describe("View id (name)"),
|
|
16
|
-
project:
|
|
35
|
+
project: projectIdSchema
|
|
36
|
+
},
|
|
37
|
+
outputSchema: {
|
|
38
|
+
location: locationSchema
|
|
17
39
|
}
|
|
18
40
|
}, async (languageServices, args) => {
|
|
19
|
-
const projectId = args.project
|
|
20
|
-
const
|
|
21
|
-
invariant(project, `Project "${projectId}" not found`);
|
|
22
|
-
const model = await languageServices.computedModel(project.id);
|
|
41
|
+
const projectId = languageServices.projectsManager.ensureProjectId(args.project);
|
|
42
|
+
const model = await languageServices.computedModel(projectId);
|
|
23
43
|
const view = model.findView(args.viewId);
|
|
24
44
|
if (!view) {
|
|
25
|
-
throw new Error(`View with ID '${args.viewId}' not found in project ${
|
|
45
|
+
throw new Error(`View with ID '${args.viewId}' not found in project ${projectId}`);
|
|
26
46
|
}
|
|
27
|
-
await languageServices.views.openView(view.id,
|
|
28
|
-
|
|
47
|
+
await languageServices.views.openView(view.id, projectId);
|
|
48
|
+
const locate = mkLocate(languageServices, projectId);
|
|
49
|
+
return {
|
|
50
|
+
location: locate({ view: view.id })
|
|
51
|
+
};
|
|
29
52
|
});
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const readDeployment: (languageServices: import("../..").LikeC4LanguageServices) => [string, {
|
|
3
3
|
inputSchema?: {
|
|
4
|
-
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
project: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodString, ProjectId, string>>>;
|
|
5
6
|
} | undefined;
|
|
6
7
|
}, (args: {
|
|
7
|
-
|
|
8
|
+
[x: string]: any;
|
|
9
|
+
id?: unknown;
|
|
10
|
+
project?: unknown;
|
|
8
11
|
}, extra: import("@modelcontextprotocol/sdk/shared/protocol").RequestHandlerExtra<import("@modelcontextprotocol/sdk/types").ServerRequest, import("@modelcontextprotocol/sdk/types").ServerNotification>) => import("@modelcontextprotocol/sdk/types").CallToolResult | Promise<import("@modelcontextprotocol/sdk/types").CallToolResult>];
|