@nowline/mcp 0.12.0 → 0.13.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/diagnostics.d.ts +7 -4
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +12 -8
- package/dist/diagnostics.js.map +1 -1
- package/dist/generated/ui-bundle.d.ts.map +1 -1
- package/dist/generated/ui-bundle.js +2 -2
- package/dist/generated/ui-bundle.js.map +1 -1
- package/dist/generated/version.d.ts +3 -0
- package/dist/generated/version.d.ts.map +1 -0
- package/dist/generated/version.js +5 -0
- package/dist/generated/version.js.map +1 -0
- package/dist/http.d.ts +1 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +48 -0
- package/dist/http.js.map +1 -1
- package/dist/index.js +13 -54
- package/dist/index.js.map +1 -1
- package/dist/path-guard.d.ts +43 -0
- package/dist/path-guard.d.ts.map +1 -0
- package/dist/path-guard.js +110 -0
- package/dist/path-guard.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +87 -58
- package/dist/server.js.map +1 -1
- package/dist/start.d.ts +30 -0
- package/dist/start.d.ts.map +1 -0
- package/dist/start.js +80 -0
- package/dist/start.js.map +1 -0
- package/package.json +14 -10
- package/src/diagnostics.ts +13 -10
- package/src/generated/ui-bundle.ts +2 -2
- package/src/generated/version.ts +5 -0
- package/src/http.ts +58 -1
- package/src/index.ts +14 -64
- package/src/path-guard.ts +134 -0
- package/src/server.ts +147 -67
- package/src/start.ts +101 -0
package/dist/start.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The one way to start the Nowline MCP server, shared by `npx @nowline/mcp`
|
|
2
|
+
// and `nowline --mcp`. Both entry points only parse their own flags and call
|
|
3
|
+
// startMcpServer, so `--root`, `--port` and the reported version mean the same
|
|
4
|
+
// thing in each (r1.f15: the CLI once built its own server without
|
|
5
|
+
// `rootConfigured`, so binary exports came back inline instead of saved).
|
|
6
|
+
//
|
|
7
|
+
// Spec: specs/mcp.md.
|
|
8
|
+
import { createServer } from 'node:http';
|
|
9
|
+
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
10
|
+
import { MCP_VERSION } from './generated/version.js';
|
|
11
|
+
import { createMcpHttpHandler } from './http.js';
|
|
12
|
+
import { expandRootPath } from './root-path.js';
|
|
13
|
+
import { createMcpServer } from './server.js';
|
|
14
|
+
/** A `--port` value that isn't an integer from 1 to 65535. */
|
|
15
|
+
export class InvalidPortError extends Error {
|
|
16
|
+
value;
|
|
17
|
+
constructor(value) {
|
|
18
|
+
super(`--port must be a number between 1 and 65535 (got ${value}).`);
|
|
19
|
+
this.value = value;
|
|
20
|
+
this.name = 'InvalidPortError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Parses `--port`, throwing {@link InvalidPortError} unless it is a whole number from 1 to 65535. */
|
|
24
|
+
export function parsePort(raw) {
|
|
25
|
+
const trimmed = raw.trim();
|
|
26
|
+
const port = /^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN;
|
|
27
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
28
|
+
throw new InvalidPortError(raw);
|
|
29
|
+
}
|
|
30
|
+
return port;
|
|
31
|
+
}
|
|
32
|
+
/** The {@link createMcpServer} options for a given `--root` and version. */
|
|
33
|
+
export function mcpServerOptions(root, version) {
|
|
34
|
+
// Expand mcpb tokens (${HOME}, ~, env vars) so a literal default from the
|
|
35
|
+
// .mcpb directory picker resolves to a real path.
|
|
36
|
+
const allowedRoot = expandRootPath(root);
|
|
37
|
+
return {
|
|
38
|
+
allowedRoot,
|
|
39
|
+
rootConfigured: allowedRoot !== undefined,
|
|
40
|
+
version: version ?? MCP_VERSION,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Starts the server and resolves when it stops: for stdio, when the client
|
|
45
|
+
* closes stdin; for HTTP, after SIGINT or SIGTERM closes the listener.
|
|
46
|
+
* Rejects with {@link InvalidPortError} before binding anything when `port` is bad.
|
|
47
|
+
*/
|
|
48
|
+
export async function startMcpServer(opts = {}) {
|
|
49
|
+
const port = opts.port === undefined ? undefined : parsePort(opts.port);
|
|
50
|
+
const serverOptions = mcpServerOptions(opts.root, opts.version);
|
|
51
|
+
if (port === undefined) {
|
|
52
|
+
const transport = new StdioServerTransport();
|
|
53
|
+
const closed = new Promise((resolve) => {
|
|
54
|
+
// Set before connect: the SDK wraps an existing onclose rather than replacing it.
|
|
55
|
+
transport.onclose = resolve;
|
|
56
|
+
});
|
|
57
|
+
await createMcpServer(serverOptions).connect(transport);
|
|
58
|
+
await closed;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Stateless Streamable HTTP: one server per request (see http.ts).
|
|
62
|
+
const httpServer = createServer(createMcpHttpHandler(() => createMcpServer(serverOptions)));
|
|
63
|
+
const onListening = opts.onListening ??
|
|
64
|
+
((url) => process.stderr.write(`nowline-mcp: Streamable HTTP listening on ${url}\n`));
|
|
65
|
+
await new Promise((resolve, reject) => {
|
|
66
|
+
const stop = () => httpServer.close();
|
|
67
|
+
httpServer.once('error', reject);
|
|
68
|
+
httpServer.once('close', () => {
|
|
69
|
+
process.off('SIGINT', stop);
|
|
70
|
+
process.off('SIGTERM', stop);
|
|
71
|
+
resolve();
|
|
72
|
+
});
|
|
73
|
+
httpServer.listen(port, '127.0.0.1', () => {
|
|
74
|
+
process.on('SIGINT', stop);
|
|
75
|
+
process.on('SIGTERM', stop);
|
|
76
|
+
onListening(`http://127.0.0.1:${port}`);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,mEAAmE;AACnE,0EAA0E;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,GAAG,EAAE;YAC1B,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC7B,OAAO,EAAE,CAAC;QACd,CAAC,CAAC,CAAC;QACH,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE;YACtC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC3B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC5B,WAAW,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nowline/mcp",
|
|
3
3
|
"mcpName": "io.nowline/nowline",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"description": "Nowline MCP server — lets AI agents create, edit, and render your roadmaps.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"engines": {
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"./http": {
|
|
27
27
|
"types": "./dist/http.d.ts",
|
|
28
28
|
"import": "./dist/http.js"
|
|
29
|
+
},
|
|
30
|
+
"./start": {
|
|
31
|
+
"types": "./dist/start.d.ts",
|
|
32
|
+
"import": "./dist/start.js"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"files": [
|
|
@@ -36,15 +40,15 @@
|
|
|
36
40
|
"@modelcontextprotocol/ext-apps": "^2.0.3",
|
|
37
41
|
"@modelcontextprotocol/node": "^2.1.1",
|
|
38
42
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
39
|
-
"@nowline/browser": "0.
|
|
40
|
-
"@nowline/config": "0.
|
|
41
|
-
"@nowline/core": "0.
|
|
42
|
-
"@nowline/export": "0.
|
|
43
|
-
"@nowline/export-core": "0.
|
|
44
|
-
"@nowline/layout": "0.
|
|
45
|
-
"@nowline/preview": "0.
|
|
46
|
-
"@nowline/preview-shell": "0.
|
|
47
|
-
"@nowline/share-link": "0.
|
|
43
|
+
"@nowline/browser": "0.13.0",
|
|
44
|
+
"@nowline/config": "0.13.0",
|
|
45
|
+
"@nowline/core": "0.13.0",
|
|
46
|
+
"@nowline/export": "0.13.0",
|
|
47
|
+
"@nowline/export-core": "0.13.0",
|
|
48
|
+
"@nowline/layout": "0.13.0",
|
|
49
|
+
"@nowline/preview": "0.13.0",
|
|
50
|
+
"@nowline/preview-shell": "0.13.0",
|
|
51
|
+
"@nowline/share-link": "0.13.0",
|
|
48
52
|
"@resvg/resvg-wasm": "^2.6.2",
|
|
49
53
|
"langium": "~4.4.0",
|
|
50
54
|
"zod": "^4.6.7"
|
package/src/diagnostics.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// MCP diagnostic helpers — maps Langium/core diagnostics to the MCP tool shape.
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
buildTransientDocument,
|
|
4
5
|
collectDocumentDiagnostics,
|
|
5
6
|
createNowlineServices,
|
|
7
|
+
type IncludePolicy,
|
|
6
8
|
inferCodeFromMessage,
|
|
7
9
|
isRoutedResolveDiagnostic,
|
|
8
|
-
type NowlineFile,
|
|
9
10
|
type ResolveDiagnostic,
|
|
10
11
|
resolveDiagnosticCode,
|
|
11
12
|
resolveDiagnosticSuggestion,
|
|
@@ -55,14 +56,8 @@ export function getMcpServices() {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
export async function buildDocument(source: string) {
|
|
58
|
-
const services = getMcpServices();
|
|
59
59
|
const uri = URI.parse(`memory:///mcp-${++docCounter}.nowline`);
|
|
60
|
-
|
|
61
|
-
source,
|
|
62
|
-
uri,
|
|
63
|
-
);
|
|
64
|
-
await services.shared.workspace.DocumentBuilder.build([doc], { validation: true });
|
|
65
|
-
return doc;
|
|
60
|
+
return buildTransientDocument(getMcpServices().shared, source, uri);
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
export function collectMcpDiagnostics(
|
|
@@ -191,15 +186,23 @@ export async function diagnosticsErrorBlock(
|
|
|
191
186
|
* Stage a validated document once for a tool call: the render, the export,
|
|
192
187
|
* the insights and the routed include diagnostics all read this one result.
|
|
193
188
|
* `doc` is the document `diagnosticsErrorBlock` (or `validate`) already built
|
|
194
|
-
* from `source`, so nothing is parsed again.
|
|
189
|
+
* from `source`, so nothing is parsed again. `includePolicy` confines
|
|
190
|
+
* includes as the CLI's `--include-root` does: an absolute include, or one
|
|
191
|
+
* that leaves the root before or after symlinks are resolved, is NL.E0208
|
|
192
|
+
* and is not read (`includePolicyFor` builds it for a guarded path).
|
|
195
193
|
*/
|
|
196
194
|
export function stageMcpRoadmap(
|
|
197
195
|
doc: Awaited<ReturnType<typeof buildDocument>>,
|
|
198
196
|
source: string,
|
|
199
197
|
inputs: RenderInputs,
|
|
200
198
|
host: HostEnv,
|
|
199
|
+
includePolicy: IncludePolicy,
|
|
201
200
|
): Promise<StageResult> {
|
|
202
|
-
return stageForExport(source, inputs, host, {
|
|
201
|
+
return stageForExport(source, inputs, host, {
|
|
202
|
+
document: doc,
|
|
203
|
+
services: getMcpServices(),
|
|
204
|
+
includePolicy,
|
|
205
|
+
});
|
|
203
206
|
}
|
|
204
207
|
|
|
205
208
|
/**
|