@lushly-dev/violet-server 0.0.0-stage → 0.3.0-preview.1
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 +21 -0
- package/README.md +15 -2
- package/dist/api.d.ts +57 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +318 -0
- package/dist/api.js.map +1 -0
- package/dist/bin.d.ts +9 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +22 -0
- package/dist/bin.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +30 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +134 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/generator.d.ts +28 -0
- package/dist/tools/generator.d.ts.map +1 -0
- package/dist/tools/generator.js +36 -0
- package/dist/tools/generator.js.map +1 -0
- package/dist/transports/stdio.d.ts +17 -0
- package/dist/transports/stdio.d.ts.map +1 -0
- package/dist/transports/stdio.js +35 -0
- package/dist/transports/stdio.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +76 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lushly
|
|
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
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lushly-dev/violet-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MCP server and local REST API for Violet Design, a hierarchical design token platform. Every Violet command is exposed as an MCP tool with the same input schema and result as the CLI.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @lushly-dev/violet-server@preview
|
|
7
|
+
npx violet-mcp # MCP over stdio
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { createApiServer, createMcpServer, generateTools, startStdioServer } from '@lushly-dev/violet-server';
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## License
|
|
15
|
+
|
|
16
|
+
MIT
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Violet Design REST API Server
|
|
3
|
+
*
|
|
4
|
+
* Simple HTTP server that exposes commands via REST.
|
|
5
|
+
* This is the same command layer that MCP uses - just a different transport.
|
|
6
|
+
*
|
|
7
|
+
* Uses Node.js built-in http module to avoid extra dependencies.
|
|
8
|
+
*
|
|
9
|
+
* Security defaults:
|
|
10
|
+
* - Binds to 127.0.0.1 only (override with `host` / VIOLET_API_HOST).
|
|
11
|
+
* - Optional shared-secret auth via VIOLET_API_TOKEN (Bearer or X-API-Key).
|
|
12
|
+
* A token is REQUIRED when binding a non-loopback host.
|
|
13
|
+
* - CORS is restricted to an allow-list (VIOLET_CORS_ORIGINS), never `*`.
|
|
14
|
+
* - Commands that shell out (`validate`) or inspect the host (`doctor`) are
|
|
15
|
+
* not exposed over HTTP.
|
|
16
|
+
* - Request bodies are capped (1 MB by default).
|
|
17
|
+
*/
|
|
18
|
+
import { createServer } from 'node:http';
|
|
19
|
+
export interface ApiServerOptions {
|
|
20
|
+
port?: number;
|
|
21
|
+
/** Interface to bind. Defaults to VIOLET_API_HOST or 127.0.0.1 (loopback only). */
|
|
22
|
+
host?: string;
|
|
23
|
+
useMemory?: boolean;
|
|
24
|
+
dbPath?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Shared secret. When set, /api/commands and /api/command require
|
|
27
|
+
* `Authorization: Bearer <token>` or `X-API-Key: <token>`.
|
|
28
|
+
* Defaults to VIOLET_API_TOKEN. REQUIRED when binding a non-loopback host.
|
|
29
|
+
*/
|
|
30
|
+
token?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Browser origins allowed via CORS. Defaults to VIOLET_CORS_ORIGINS
|
|
33
|
+
* (comma separated) or the web dev server origins on port 3000.
|
|
34
|
+
*/
|
|
35
|
+
corsOrigins?: string[];
|
|
36
|
+
/** Maximum request body size in bytes (default 1 MB). */
|
|
37
|
+
maxBodyBytes?: number;
|
|
38
|
+
/** Suppress startup logging. */
|
|
39
|
+
silent?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Default allowed browser origins: the Vite dev server of packages/web. */
|
|
42
|
+
export declare const DEFAULT_CORS_ORIGINS: string[];
|
|
43
|
+
/** Default request body limit (1 MB). */
|
|
44
|
+
export declare const DEFAULT_MAX_BODY_BYTES: number;
|
|
45
|
+
/**
|
|
46
|
+
* Commands that are never exposed over HTTP.
|
|
47
|
+
* - `validate` shells out (`pnpm test`) on the server host.
|
|
48
|
+
* - `doctor` inspects the host environment.
|
|
49
|
+
*/
|
|
50
|
+
export declare const HTTP_EXCLUDED_COMMANDS: ReadonlySet<string>;
|
|
51
|
+
/** True when `host` only accepts connections from the local machine. */
|
|
52
|
+
export declare function isLoopbackHost(host: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Create and start the REST API server
|
|
55
|
+
*/
|
|
56
|
+
export declare function createApiServer(options?: ApiServerOptions): Promise<ReturnType<typeof createServer>>;
|
|
57
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAA6C,YAAY,EAAE,MAAM,WAAW,CAAC;AAapF,MAAM,WAAW,gBAAgB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,UAAqD,CAAC;AAEvF,yCAAyC;AACzC,eAAO,MAAM,sBAAsB,QAAc,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,MAAM,CAAmC,CAAC;AAI3F,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGpD;AAgGD;;GAEG;AACH,wBAAsB,eAAe,CACpC,OAAO,GAAE,gBAAqB,GAC5B,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAyN1C"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Violet Design REST API Server
|
|
3
|
+
*
|
|
4
|
+
* Simple HTTP server that exposes commands via REST.
|
|
5
|
+
* This is the same command layer that MCP uses - just a different transport.
|
|
6
|
+
*
|
|
7
|
+
* Uses Node.js built-in http module to avoid extra dependencies.
|
|
8
|
+
*
|
|
9
|
+
* Security defaults:
|
|
10
|
+
* - Binds to 127.0.0.1 only (override with `host` / VIOLET_API_HOST).
|
|
11
|
+
* - Optional shared-secret auth via VIOLET_API_TOKEN (Bearer or X-API-Key).
|
|
12
|
+
* A token is REQUIRED when binding a non-loopback host.
|
|
13
|
+
* - CORS is restricted to an allow-list (VIOLET_CORS_ORIGINS), never `*`.
|
|
14
|
+
* - Commands that shell out (`validate`) or inspect the host (`doctor`) are
|
|
15
|
+
* not exposed over HTTP.
|
|
16
|
+
* - Request bodies are capped (1 MB by default).
|
|
17
|
+
*/
|
|
18
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
19
|
+
import { realpathSync } from 'node:fs';
|
|
20
|
+
import { createServer } from 'node:http';
|
|
21
|
+
import { pathToFileURL } from 'node:url';
|
|
22
|
+
import { createMemoryDatabase, createSQLiteDatabase, initializeCore, registry, } from '@lushly-dev/violet-afd';
|
|
23
|
+
import { nanoid } from 'nanoid';
|
|
24
|
+
/** Default allowed browser origins: the Vite dev server of packages/web. */
|
|
25
|
+
export const DEFAULT_CORS_ORIGINS = ['http://localhost:3000', 'http://127.0.0.1:3000'];
|
|
26
|
+
/** Default request body limit (1 MB). */
|
|
27
|
+
export const DEFAULT_MAX_BODY_BYTES = 1024 * 1024;
|
|
28
|
+
/**
|
|
29
|
+
* Commands that are never exposed over HTTP.
|
|
30
|
+
* - `validate` shells out (`pnpm test`) on the server host.
|
|
31
|
+
* - `doctor` inspects the host environment.
|
|
32
|
+
*/
|
|
33
|
+
export const HTTP_EXCLUDED_COMMANDS = new Set(['validate', 'doctor']);
|
|
34
|
+
const LOOPBACK_HOSTNAMES = new Set(['localhost', '127.0.0.1', '::1', '[::1]']);
|
|
35
|
+
/** True when `host` only accepts connections from the local machine. */
|
|
36
|
+
export function isLoopbackHost(host) {
|
|
37
|
+
const h = host.toLowerCase();
|
|
38
|
+
return LOOPBACK_HOSTNAMES.has(h) || /^127(\.\d{1,3}){3}$/.test(h);
|
|
39
|
+
}
|
|
40
|
+
class HttpError extends Error {
|
|
41
|
+
status;
|
|
42
|
+
code;
|
|
43
|
+
constructor(status, code, message) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.status = status;
|
|
46
|
+
this.code = code;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse request body as a JSON object, enforcing a size limit.
|
|
51
|
+
* An empty body yields `{}`.
|
|
52
|
+
*/
|
|
53
|
+
async function parseBody(req, maxBytes) {
|
|
54
|
+
const tooLargeError = () => new HttpError(413, 'PAYLOAD_TOO_LARGE', `Request body exceeds ${maxBytes} bytes`);
|
|
55
|
+
const declared = Number(req.headers['content-length']);
|
|
56
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
57
|
+
req.resume();
|
|
58
|
+
throw tooLargeError();
|
|
59
|
+
}
|
|
60
|
+
const raw = await new Promise((resolve, reject) => {
|
|
61
|
+
const chunks = [];
|
|
62
|
+
let size = 0;
|
|
63
|
+
let tooLarge = false;
|
|
64
|
+
req.on('data', (chunk) => {
|
|
65
|
+
if (tooLarge)
|
|
66
|
+
return;
|
|
67
|
+
size += chunk.length;
|
|
68
|
+
if (size > maxBytes) {
|
|
69
|
+
tooLarge = true;
|
|
70
|
+
chunks.length = 0;
|
|
71
|
+
return; // keep draining, but stop buffering
|
|
72
|
+
}
|
|
73
|
+
chunks.push(chunk);
|
|
74
|
+
});
|
|
75
|
+
req.on('end', () => tooLarge ? reject(tooLargeError()) : resolve(Buffer.concat(chunks).toString('utf8')));
|
|
76
|
+
req.on('error', reject);
|
|
77
|
+
});
|
|
78
|
+
if (raw.trim() === '')
|
|
79
|
+
return {};
|
|
80
|
+
let parsed;
|
|
81
|
+
try {
|
|
82
|
+
parsed = JSON.parse(raw);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
throw new HttpError(400, 'INVALID_JSON', 'Request body is not valid JSON');
|
|
86
|
+
}
|
|
87
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
88
|
+
throw new HttpError(400, 'INVALID_BODY', 'Request body must be a JSON object');
|
|
89
|
+
}
|
|
90
|
+
return parsed;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create command context
|
|
94
|
+
*/
|
|
95
|
+
function createContext(db) {
|
|
96
|
+
return {
|
|
97
|
+
db,
|
|
98
|
+
actor: 'api',
|
|
99
|
+
traceId: nanoid(),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function tokensMatch(provided, expected) {
|
|
103
|
+
const a = Buffer.from(provided);
|
|
104
|
+
const b = Buffer.from(expected);
|
|
105
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
106
|
+
}
|
|
107
|
+
function extractToken(req) {
|
|
108
|
+
const auth = req.headers.authorization;
|
|
109
|
+
if (typeof auth === 'string') {
|
|
110
|
+
const match = /^Bearer\s+(.+)$/i.exec(auth);
|
|
111
|
+
if (match)
|
|
112
|
+
return match[1].trim();
|
|
113
|
+
}
|
|
114
|
+
const key = req.headers['x-api-key'];
|
|
115
|
+
return typeof key === 'string' ? key : undefined;
|
|
116
|
+
}
|
|
117
|
+
function parseOriginList(value) {
|
|
118
|
+
if (!value)
|
|
119
|
+
return undefined;
|
|
120
|
+
const list = value
|
|
121
|
+
.split(',')
|
|
122
|
+
.map((s) => s.trim())
|
|
123
|
+
.filter(Boolean);
|
|
124
|
+
return list.length > 0 ? list : undefined;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create and start the REST API server
|
|
128
|
+
*/
|
|
129
|
+
export async function createApiServer(options = {}) {
|
|
130
|
+
const { port = 3001, host = process.env.VIOLET_API_HOST || '127.0.0.1', useMemory = true, dbPath = './violet.db', maxBodyBytes = DEFAULT_MAX_BODY_BYTES, silent = false, } = options;
|
|
131
|
+
const token = options.token ?? (process.env.VIOLET_API_TOKEN || undefined);
|
|
132
|
+
const corsOrigins = (options.corsOrigins ??
|
|
133
|
+
parseOriginList(process.env.VIOLET_CORS_ORIGINS) ??
|
|
134
|
+
DEFAULT_CORS_ORIGINS)
|
|
135
|
+
.map((o) => o.replace(/\/$/, ''))
|
|
136
|
+
.filter((o) => o !== '*');
|
|
137
|
+
const allowedOrigins = new Set(corsOrigins);
|
|
138
|
+
const loopback = isLoopbackHost(host);
|
|
139
|
+
if (!loopback && !token) {
|
|
140
|
+
throw new Error(`Refusing to bind the Violet API to non-loopback host "${host}" without authentication. Set VIOLET_API_TOKEN (or the token option) or bind to 127.0.0.1.`);
|
|
141
|
+
}
|
|
142
|
+
// Initialize core and register all commands
|
|
143
|
+
initializeCore();
|
|
144
|
+
// Create database
|
|
145
|
+
const db = useMemory ? createMemoryDatabase() : await createSQLiteDatabase(dbPath);
|
|
146
|
+
const send = (res, data, status = 200, extraHeaders = {}) => {
|
|
147
|
+
res.writeHead(status, { 'Content-Type': 'application/json', ...extraHeaders });
|
|
148
|
+
res.end(JSON.stringify(data));
|
|
149
|
+
};
|
|
150
|
+
const fail = (res, status, code, message, headers = {}) => send(res, { success: false, error: { code, message } }, status, headers);
|
|
151
|
+
const server = createServer(async (req, res) => {
|
|
152
|
+
const path = new URL(req.url || '/', 'http://localhost').pathname;
|
|
153
|
+
const origin = typeof req.headers.origin === 'string' ? req.headers.origin : undefined;
|
|
154
|
+
// Defend against DNS rebinding when only reachable via loopback.
|
|
155
|
+
if (loopback) {
|
|
156
|
+
const hostHeader = req.headers.host ?? '';
|
|
157
|
+
const hostname = hostHeader.startsWith('[')
|
|
158
|
+
? hostHeader.slice(0, hostHeader.indexOf(']') + 1)
|
|
159
|
+
: hostHeader.split(':')[0];
|
|
160
|
+
if (!isLoopbackHost(hostname)) {
|
|
161
|
+
fail(res, 403, 'FORBIDDEN_HOST', 'Unexpected Host header');
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Browser requests must come from an allow-listed origin.
|
|
166
|
+
const corsHeaders = { Vary: 'Origin' };
|
|
167
|
+
if (origin !== undefined) {
|
|
168
|
+
if (!allowedOrigins.has(origin)) {
|
|
169
|
+
fail(res, 403, 'FORBIDDEN_ORIGIN', 'Origin not allowed', corsHeaders);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
corsHeaders['Access-Control-Allow-Origin'] = origin;
|
|
173
|
+
}
|
|
174
|
+
// Handle CORS preflight
|
|
175
|
+
if (req.method === 'OPTIONS') {
|
|
176
|
+
res.writeHead(204, {
|
|
177
|
+
...corsHeaders,
|
|
178
|
+
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
179
|
+
'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-API-Key',
|
|
180
|
+
'Access-Control-Max-Age': '600',
|
|
181
|
+
});
|
|
182
|
+
res.end();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
// Health check (unauthenticated, reveals nothing sensitive)
|
|
187
|
+
if (path === '/api/health' && req.method === 'GET') {
|
|
188
|
+
send(res, { status: 'ok', timestamp: new Date().toISOString() }, 200, corsHeaders);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const isCommandRoute = (path === '/api/commands' && req.method === 'GET') ||
|
|
192
|
+
(path === '/api/command' && req.method === 'POST');
|
|
193
|
+
if (isCommandRoute && token) {
|
|
194
|
+
const provided = extractToken(req);
|
|
195
|
+
if (!provided || !tokensMatch(provided, token)) {
|
|
196
|
+
fail(res, 401, 'UNAUTHORIZED', 'Missing or invalid API token', {
|
|
197
|
+
...corsHeaders,
|
|
198
|
+
'WWW-Authenticate': 'Bearer',
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// List available commands
|
|
204
|
+
if (path === '/api/commands' && req.method === 'GET') {
|
|
205
|
+
const commands = registry
|
|
206
|
+
.list()
|
|
207
|
+
.filter((cmd) => !HTTP_EXCLUDED_COMMANDS.has(cmd.name))
|
|
208
|
+
.map((cmd) => {
|
|
209
|
+
const deprecated = registry.get(cmd.name)?.deprecated;
|
|
210
|
+
return {
|
|
211
|
+
name: cmd.name,
|
|
212
|
+
description: cmd.description,
|
|
213
|
+
category: cmd.name.split('.')[0],
|
|
214
|
+
...(deprecated ? { deprecated: true, replacement: deprecated.replacement } : {}),
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
send(res, { success: true, data: { commands } }, 200, corsHeaders);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
// Execute command
|
|
221
|
+
if (path === '/api/command' && req.method === 'POST') {
|
|
222
|
+
const body = await parseBody(req, maxBodyBytes);
|
|
223
|
+
const { command, input = {} } = body;
|
|
224
|
+
if (typeof command !== 'string' || !command) {
|
|
225
|
+
fail(res, 400, 'MISSING_COMMAND', 'Command name required', corsHeaders);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (HTTP_EXCLUDED_COMMANDS.has(command)) {
|
|
229
|
+
fail(res, 403, 'COMMAND_NOT_ALLOWED', `Command is not available over HTTP: ${command}`, corsHeaders);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const cmd = registry.get(command);
|
|
233
|
+
if (!cmd) {
|
|
234
|
+
send(res, {
|
|
235
|
+
success: false,
|
|
236
|
+
error: {
|
|
237
|
+
code: 'COMMAND_NOT_FOUND',
|
|
238
|
+
message: `Unknown command: ${command}`,
|
|
239
|
+
suggestion: 'Use GET /api/commands to list available commands',
|
|
240
|
+
},
|
|
241
|
+
}, 404, corsHeaders);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const context = createContext(db);
|
|
245
|
+
const result = await registry.execute(command, input, context);
|
|
246
|
+
// RFC 9745: a deprecated command is still served, flagged for the caller. The successor
|
|
247
|
+
// link is the hosted OpenAPI path (`tokens.compare` -> /api/v1/tokens/compare); here the
|
|
248
|
+
// replacement runs through this same route by name.
|
|
249
|
+
const deprecation = cmd.deprecated
|
|
250
|
+
? {
|
|
251
|
+
Deprecation: 'true',
|
|
252
|
+
Link: `</api/v1/${cmd.deprecated.replacement.replaceAll('.', '/')}>; rel="successor-version"`,
|
|
253
|
+
}
|
|
254
|
+
: {};
|
|
255
|
+
send(res, result, 200, { ...corsHeaders, ...deprecation });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
// 404 for unknown routes
|
|
259
|
+
fail(res, 404, 'NOT_FOUND', `Unknown route: ${path}`, corsHeaders);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
if (res.headersSent) {
|
|
263
|
+
res.end();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (error instanceof HttpError) {
|
|
267
|
+
const headers = error.status === 413 ? { ...corsHeaders, Connection: 'close' } : corsHeaders;
|
|
268
|
+
fail(res, error.status, error.code, error.message, headers);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
272
|
+
fail(res, 500, 'EXECUTION_ERROR', message, corsHeaders);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
await new Promise((resolve, reject) => {
|
|
276
|
+
server.once('error', reject);
|
|
277
|
+
server.listen(port, host, () => {
|
|
278
|
+
server.off('error', reject);
|
|
279
|
+
resolve();
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
if (!silent) {
|
|
283
|
+
const actualPort = server.address().port;
|
|
284
|
+
console.log(`Violet API Server running at http://${host}:${actualPort}`);
|
|
285
|
+
console.log(` Commands: ${registry.list().length - HTTP_EXCLUDED_COMMANDS.size} exposed`);
|
|
286
|
+
console.log(` Database: ${useMemory ? 'memory' : 'sqlite'}`);
|
|
287
|
+
console.log(` Auth: ${token ? 'token required' : 'none (loopback only)'}`);
|
|
288
|
+
}
|
|
289
|
+
return server;
|
|
290
|
+
}
|
|
291
|
+
/** True when this module is the process entry point (not merely imported). */
|
|
292
|
+
function isEntryPoint() {
|
|
293
|
+
const entry = process.argv[1];
|
|
294
|
+
if (!entry)
|
|
295
|
+
return false;
|
|
296
|
+
try {
|
|
297
|
+
return import.meta.url === pathToFileURL(realpathSync(entry)).href;
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
return import.meta.url === pathToFileURL(entry).href;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Run directly
|
|
304
|
+
if (isEntryPoint()) {
|
|
305
|
+
// VIOLET_DB_PATH serves an existing SQLite database (e.g. one seeded with
|
|
306
|
+
// `violet demo seed`); without it the server starts with an in-memory database.
|
|
307
|
+
// VIOLET_API_PORT moves it off 3001, e.g. for the web end-to-end tests.
|
|
308
|
+
const dbPath = process.env.VIOLET_DB_PATH;
|
|
309
|
+
const port = process.env.VIOLET_API_PORT ? Number(process.env.VIOLET_API_PORT) : undefined;
|
|
310
|
+
createApiServer({
|
|
311
|
+
...(dbPath ? { useMemory: false, dbPath } : {}),
|
|
312
|
+
...(port ? { port } : {}),
|
|
313
|
+
}).catch((error) => {
|
|
314
|
+
console.error(error instanceof Error ? error.message : error);
|
|
315
|
+
process.exit(1);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAA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AAC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;;GAKG"}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Violet MCP Server Binary
|
|
4
|
+
*
|
|
5
|
+
* Standalone binary for running the MCP server.
|
|
6
|
+
* Can be used directly: npx violet-mcp
|
|
7
|
+
*/
|
|
8
|
+
import { startStdioServer } from './transports/stdio.js';
|
|
9
|
+
// Parse command line arguments
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
const useMemory = args.includes('--memory');
|
|
12
|
+
const dbPathIndex = args.findIndex((a) => a === '--db' || a === '--database');
|
|
13
|
+
const dbPath = dbPathIndex >= 0 ? args[dbPathIndex + 1] : undefined;
|
|
14
|
+
// Start server
|
|
15
|
+
startStdioServer({
|
|
16
|
+
useMemory,
|
|
17
|
+
dbPath,
|
|
18
|
+
}).catch((error) => {
|
|
19
|
+
console.error('[violet-mcp] Fatal error:', error);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,+BAA+B;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,YAAY,CAAC,CAAC;AAC9E,MAAM,MAAM,GAAG,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAEpE,eAAe;AACf,gBAAgB,CAAC;IAChB,SAAS;IACT,MAAM;CACN,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAClB,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Violet Design MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Model Context Protocol server exposing all Violet commands as AI tools.
|
|
5
|
+
*/
|
|
6
|
+
export { createMcpServer, type ServerOptions } from './server.js';
|
|
7
|
+
export { generateTools, type McpTool } from './tools/generator.js';
|
|
8
|
+
export { startStdioServer } from './transports/stdio.js';
|
|
9
|
+
export { createApiServer, type ApiServerOptions } from './api.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Violet Design MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Model Context Protocol server exposing all Violet commands as AI tools.
|
|
5
|
+
*/
|
|
6
|
+
export { createMcpServer } from './server.js';
|
|
7
|
+
export { generateTools } from './tools/generator.js';
|
|
8
|
+
export { startStdioServer } from './transports/stdio.js';
|
|
9
|
+
export { createApiServer } from './api.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAsB,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,aAAa,EAAgB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Violet Design MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Creates an MCP server that exposes all Violet commands as AI tools.
|
|
5
|
+
* Uses the official @modelcontextprotocol/sdk for protocol compliance.
|
|
6
|
+
*/
|
|
7
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
/**
|
|
9
|
+
* Server configuration options
|
|
10
|
+
*/
|
|
11
|
+
export interface ServerOptions {
|
|
12
|
+
/** Path to SQLite database (or ':memory:' for in-memory) */
|
|
13
|
+
dbPath?: string;
|
|
14
|
+
/** Use in-memory database instead of SQLite */
|
|
15
|
+
useMemory?: boolean;
|
|
16
|
+
/** Server name */
|
|
17
|
+
name?: string;
|
|
18
|
+
/** Server version */
|
|
19
|
+
version?: string;
|
|
20
|
+
/** Skip initializing core (use when core is already initialized) */
|
|
21
|
+
skipInit?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create and configure the Violet MCP server
|
|
25
|
+
*
|
|
26
|
+
* @param options Server configuration
|
|
27
|
+
* @returns Configured McpServer instance
|
|
28
|
+
*/
|
|
29
|
+
export declare function createMcpServer(options?: ServerOptions): Promise<McpServer>;
|
|
30
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,kBAAkB;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,qBAAqB;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,SAAS,CAAC,CAmJrF"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Violet Design MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Creates an MCP server that exposes all Violet commands as AI tools.
|
|
5
|
+
* Uses the official @modelcontextprotocol/sdk for protocol compliance.
|
|
6
|
+
*/
|
|
7
|
+
import { MemoryDatabase, SQLiteDatabase, initializeCore, registry, } from '@lushly-dev/violet-afd';
|
|
8
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
9
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
10
|
+
import { generateTools } from './tools/generator.js';
|
|
11
|
+
import { PACKAGE_VERSION } from './version.js';
|
|
12
|
+
/**
|
|
13
|
+
* Create and configure the Violet MCP server
|
|
14
|
+
*
|
|
15
|
+
* @param options Server configuration
|
|
16
|
+
* @returns Configured McpServer instance
|
|
17
|
+
*/
|
|
18
|
+
export async function createMcpServer(options = {}) {
|
|
19
|
+
const { dbPath = './violet.db', useMemory = false, name = 'violet-design', version = PACKAGE_VERSION, skipInit = false, } = options;
|
|
20
|
+
// Initialize core and register all commands (unless skipped)
|
|
21
|
+
if (!skipInit) {
|
|
22
|
+
initializeCore();
|
|
23
|
+
}
|
|
24
|
+
// Create database instance
|
|
25
|
+
const db = useMemory ? new MemoryDatabase() : new SQLiteDatabase(dbPath);
|
|
26
|
+
// Create MCP server
|
|
27
|
+
const server = new McpServer({
|
|
28
|
+
name,
|
|
29
|
+
version,
|
|
30
|
+
}, {
|
|
31
|
+
capabilities: {
|
|
32
|
+
tools: {},
|
|
33
|
+
},
|
|
34
|
+
instructions: `Violet Design is a hierarchical design token management platform.
|
|
35
|
+
|
|
36
|
+
Available command categories:
|
|
37
|
+
- node.*: Manage nodes in the design token tree. A deprecated node can carry sunsetAt (YYYY-MM-DD, the day it goes away) and replacedBy (the node that replaces it); null clears either. A date without a replacement, or a deprecated replacement, comes back as a warning.
|
|
38
|
+
- nodes.graph: The hierarchy as a graph (parent, include, copy edges, change counts, optional token trace)
|
|
39
|
+
- token.*: Add, override, subtract, reset, and copy tokens
|
|
40
|
+
- tokens.resolve: Get all resolved tokens for a node
|
|
41
|
+
- tokens.matrix: Resolve tokens across many nodes and show how each value got there
|
|
42
|
+
- tokens.compare: Put 2–4 nodes side by side and get only the tokens that differ (onlyDifferent: false for all), each cell flagged when it differs from the first node, with per-category counts and a similarity per pair. Use it for "why does X look different from Y?"
|
|
43
|
+
- tokens.catalog: Find tokens by words, category, tier or status, and see where they are customized
|
|
44
|
+
- export.*: Export tokens to JSON, CSS, SCSS, or TypeScript
|
|
45
|
+
- import.*: Import tokens from JSON files
|
|
46
|
+
- constraints.*: Define and validate design constraints
|
|
47
|
+
- analyze.violations: Every constraint violation across a subtree, with node, rule, values, source and owner
|
|
48
|
+
- analyze.health: Health per node for managers: own customizations by category, drift against a baseline ('parent' by default, 'root', or a node id), violations by severity, owner, status, coupling (mix-ins, borrows, borrowers), subtree totals, deprecation plans (sunset date, days left, replacement, usage), and flags for redundant overrides, sibling borrows, deprecated nodes with children, sunsets without a replacement, deprecated replacements and nodes kept past their sunset. Sort by drift, violations or customizations.
|
|
49
|
+
- analyze.trends: Is it getting better or worse? Changes per UTC day for a node and its descendants (since defaults to 90d), and the rule issues open now spread over the days their failing values were last set, with a running count. Issues fixed since are not counted on earlier days; days with a check recorded by analyze.snapshot carry the true count (recorded), and summary.history counts the issues that appeared and were fixed from one recorded check to the next.
|
|
50
|
+
- analyze.snapshot: Check the rules on a subtree (rootId) or every tree and store the results, for rule-check history in analyze.trends. Run it on a schedule, not on every read.
|
|
51
|
+
- specimen.get: The specimen role map of a node's tree and, for each component specimen (button, input, card, text, link, checkbox, focus), which token draws each role on the node, whether it resolves and whether it passes the CSS validator.
|
|
52
|
+
- specimen.set: Map component roles to tokens ({ button: { background: 'btn.bg' } }) on the root of a node's tree, for systems not named <component>.<role>. Merges by default; a null token removes a role; replace: true replaces the map. Only known components, roles and tokens defined in the tree.
|
|
53
|
+
- audit.list: Query the audit log by node (optionally its subtree), token, event types, actor and time range (ISO dates or spans like 30d), newest first with limit/offset paging and counts per day across every match
|
|
54
|
+
- changes.impact: Preview add/override/subtract/reset changes on a node without writing them: which nodes change, which are shielded by their own customization, how the change reaches them (inheritance, include, copy), violations introduced or resolved, and the commands to apply it. Use it before any token.* write.
|
|
55
|
+
- analyze.*: Compliance reports, deviation analysis, node comparison
|
|
56
|
+
|
|
57
|
+
All commands return structured results with 'success', 'data', and 'error' fields.
|
|
58
|
+
Error responses include 'code', 'message', and 'suggestion' for recovery guidance.`,
|
|
59
|
+
});
|
|
60
|
+
// Register all commands as tools.
|
|
61
|
+
//
|
|
62
|
+
// We serve the tool list and handle calls via the low-level protocol handlers
|
|
63
|
+
// so that clients see each command's real JSON input schema and the command
|
|
64
|
+
// receives the caller's actual arguments (the high-level `server.tool(name,
|
|
65
|
+
// description, cb)` overload has no input schema and hands the callback its
|
|
66
|
+
// `extra` object instead of the arguments).
|
|
67
|
+
const tools = generateTools();
|
|
68
|
+
const toolNames = new Set(tools.map((tool) => tool.name));
|
|
69
|
+
server.server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
70
|
+
tools: tools.map((tool) => ({
|
|
71
|
+
name: tool.name,
|
|
72
|
+
description: tool.description,
|
|
73
|
+
inputSchema: tool.inputSchema,
|
|
74
|
+
})),
|
|
75
|
+
}));
|
|
76
|
+
server.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
77
|
+
const toolName = request.params.name;
|
|
78
|
+
const args = request.params.arguments ?? {};
|
|
79
|
+
if (!toolNames.has(toolName)) {
|
|
80
|
+
return {
|
|
81
|
+
content: [
|
|
82
|
+
{
|
|
83
|
+
type: 'text',
|
|
84
|
+
text: JSON.stringify({
|
|
85
|
+
success: false,
|
|
86
|
+
error: {
|
|
87
|
+
code: 'COMMAND_NOT_FOUND',
|
|
88
|
+
message: `Unknown tool '${toolName}'`,
|
|
89
|
+
suggestion: 'List available tools with tools/list',
|
|
90
|
+
},
|
|
91
|
+
}, null, 2),
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
isError: true,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// Execute command through registry (validates input against the zod schema)
|
|
98
|
+
const result = await registry.execute(toolName, args, { db });
|
|
99
|
+
// Format as MCP tool result
|
|
100
|
+
if (result.success) {
|
|
101
|
+
return {
|
|
102
|
+
content: [
|
|
103
|
+
{
|
|
104
|
+
type: 'text',
|
|
105
|
+
text: JSON.stringify({
|
|
106
|
+
success: true,
|
|
107
|
+
data: result.data,
|
|
108
|
+
confidence: result.confidence,
|
|
109
|
+
reasoning: result.reasoning,
|
|
110
|
+
warnings: result.warnings,
|
|
111
|
+
metadata: result.metadata,
|
|
112
|
+
}, null, 2),
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Return error response
|
|
118
|
+
return {
|
|
119
|
+
content: [
|
|
120
|
+
{
|
|
121
|
+
type: 'text',
|
|
122
|
+
text: JSON.stringify({
|
|
123
|
+
success: false,
|
|
124
|
+
error: result.error,
|
|
125
|
+
metadata: result.metadata,
|
|
126
|
+
}, null, 2),
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
isError: true,
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
return server;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEN,cAAc,EACd,cAAc,EACd,cAAc,EACd,QAAQ,GACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAsB/C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAO,GAAkB,EAAE;IAChE,MAAM,EACL,MAAM,GAAG,aAAa,EACtB,SAAS,GAAG,KAAK,EACjB,IAAI,GAAG,eAAe,EACtB,OAAO,GAAG,eAAe,EACzB,QAAQ,GAAG,KAAK,GAChB,GAAG,OAAO,CAAC;IAEZ,6DAA6D;IAC7D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,cAAc,EAAE,CAAC;IAClB,CAAC;IAED,2BAA2B;IAC3B,MAAM,EAAE,GAAa,SAAS,CAAC,CAAC,CAAC,IAAI,cAAc,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+
/**
|
|
2
|
+
* MCP Tool Generator
|
|
3
|
+
*
|
|
4
|
+
* Auto-generates MCP tool definitions from the Violet command registry.
|
|
5
|
+
* This ensures all commands are automatically exposed to AI agents.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* MCP Tool definition
|
|
9
|
+
*/
|
|
10
|
+
export interface McpTool {
|
|
11
|
+
/** Tool name (matches command name) */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Human-readable description */
|
|
14
|
+
description: string;
|
|
15
|
+
/** JSON Schema for input validation */
|
|
16
|
+
inputSchema: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generate MCP tools from the command registry
|
|
20
|
+
*
|
|
21
|
+
* @returns Array of MCP tool definitions
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateTools(): McpTool[];
|
|
24
|
+
/**
|
|
25
|
+
* Get a single tool definition by name
|
|
26
|
+
*/
|
|
27
|
+
export declare function getTool(name: string): McpTool | undefined;
|
|
28
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/tools/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,MAAM,WAAW,OAAO;IACvB,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IAEb,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IAEpB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,EAAE,CAUzC;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CASzD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Generator
|
|
3
|
+
*
|
|
4
|
+
* Auto-generates MCP tool definitions from the Violet command registry.
|
|
5
|
+
* This ensures all commands are automatically exposed to AI agents.
|
|
6
|
+
*/
|
|
7
|
+
import { registry, toJsonSchema } from '@lushly-dev/violet-afd';
|
|
8
|
+
/**
|
|
9
|
+
* Generate MCP tools from the command registry
|
|
10
|
+
*
|
|
11
|
+
* @returns Array of MCP tool definitions
|
|
12
|
+
*/
|
|
13
|
+
export function generateTools() {
|
|
14
|
+
const commands = registry.list();
|
|
15
|
+
return commands.map((cmd) => {
|
|
16
|
+
return {
|
|
17
|
+
name: cmd.name,
|
|
18
|
+
description: cmd.description,
|
|
19
|
+
inputSchema: registry.getInputJsonSchema(cmd.name) ?? { type: 'object', properties: {} },
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get a single tool definition by name
|
|
25
|
+
*/
|
|
26
|
+
export function getTool(name) {
|
|
27
|
+
const command = registry.get(name);
|
|
28
|
+
if (!command)
|
|
29
|
+
return undefined;
|
|
30
|
+
return {
|
|
31
|
+
name: command.name,
|
|
32
|
+
description: command.description,
|
|
33
|
+
inputSchema: toJsonSchema(command.inputSchema),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/tools/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAgBhE;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEjC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3B,OAAO;YACN,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,WAAW,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;SACxF,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY;IACnC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAE/B,OAAO;QACN,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,WAAW,EAAE,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC;KAC9C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stdio Transport
|
|
3
|
+
*
|
|
4
|
+
* Starts the MCP server with stdio transport for CLI and agent usage.
|
|
5
|
+
* This is the primary way to run the Violet MCP server.
|
|
6
|
+
*/
|
|
7
|
+
import { type ServerOptions } from '../server.js';
|
|
8
|
+
/**
|
|
9
|
+
* Start the MCP server with stdio transport
|
|
10
|
+
*
|
|
11
|
+
* This function starts the server and blocks until the connection is closed.
|
|
12
|
+
* Typically invoked via: `violet mcp start`
|
|
13
|
+
*
|
|
14
|
+
* @param options Server configuration
|
|
15
|
+
*/
|
|
16
|
+
export declare function startStdioServer(options?: ServerOptions): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=stdio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../src/transports/stdio.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,cAAc,CAAC;AAEnE;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBjF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stdio Transport
|
|
3
|
+
*
|
|
4
|
+
* Starts the MCP server with stdio transport for CLI and agent usage.
|
|
5
|
+
* This is the primary way to run the Violet MCP server.
|
|
6
|
+
*/
|
|
7
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
+
import { createMcpServer } from '../server.js';
|
|
9
|
+
/**
|
|
10
|
+
* Start the MCP server with stdio transport
|
|
11
|
+
*
|
|
12
|
+
* This function starts the server and blocks until the connection is closed.
|
|
13
|
+
* Typically invoked via: `violet mcp start`
|
|
14
|
+
*
|
|
15
|
+
* @param options Server configuration
|
|
16
|
+
*/
|
|
17
|
+
export async function startStdioServer(options = {}) {
|
|
18
|
+
const server = await createMcpServer(options);
|
|
19
|
+
const transport = new StdioServerTransport();
|
|
20
|
+
await server.connect(transport);
|
|
21
|
+
// Log to stderr (stdout is for MCP protocol)
|
|
22
|
+
console.error(`[violet-mcp] Server started (${options.useMemory ? 'memory' : options.dbPath || './violet.db'})`);
|
|
23
|
+
// Keep the process alive
|
|
24
|
+
process.on('SIGINT', async () => {
|
|
25
|
+
console.error('[violet-mcp] Shutting down...');
|
|
26
|
+
await server.close();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
});
|
|
29
|
+
process.on('SIGTERM', async () => {
|
|
30
|
+
console.error('[violet-mcp] Shutting down...');
|
|
31
|
+
await server.close();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=stdio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../src/transports/stdio.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAsB,eAAe,EAAE,MAAM,cAAc,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAO,GAAkB,EAAE;IACjE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,6CAA6C;IAC7C,OAAO,CAAC,KAAK,CACZ,gCACC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,aAClD,GAAG,CACH,CAAC;IAEF,yBAAyB;IACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QAC/B,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAC/C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;QAChC,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAC/C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAEA,+FAA+F;AAC/F,eAAO,MAAM,eAAe,EAAE,MAErB,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
/** This package's version, read from its manifest so a release bump needs no source change. */
|
|
3
|
+
export const PACKAGE_VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
4
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,eAAe,GAAW,IAAI,CAAC,KAAK,CAChD,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CACjE,CAAC,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lushly-dev/violet-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0-preview.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Falkicon",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/lushly-dev/afd.git",
|
|
9
|
+
"directory": "endpoints/violet-server"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/lushly-dev/afd#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/lushly-dev/afd/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"violet",
|
|
20
|
+
"design-tokens",
|
|
21
|
+
"mcp",
|
|
22
|
+
"rest-api",
|
|
23
|
+
"agent-first"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=24"
|
|
27
|
+
},
|
|
28
|
+
"description": "Violet Design MCP Server - AI agent interface",
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./server": {
|
|
38
|
+
"import": "./dist/server.js",
|
|
39
|
+
"types": "./dist/server.d.ts"
|
|
40
|
+
},
|
|
41
|
+
"./api": {
|
|
42
|
+
"import": "./dist/api.js",
|
|
43
|
+
"types": "./dist/api.d.ts"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@modelcontextprotocol/sdk": "^1.31.0",
|
|
48
|
+
"nanoid": "^6.0.2",
|
|
49
|
+
"zod": "^4.6.7",
|
|
50
|
+
"@lushly-dev/violet-afd": "0.3.0-preview.1",
|
|
51
|
+
"@lushly-dev/violet-core": "0.3.0-preview.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@biomejs/biome": "^2.6.6",
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
57
|
+
"typescript": "^7.0.2",
|
|
58
|
+
"vitest": "^5.1.0"
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"dist",
|
|
62
|
+
"README.md",
|
|
63
|
+
"LICENSE"
|
|
64
|
+
],
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc",
|
|
67
|
+
"dev": "tsc --watch",
|
|
68
|
+
"api": "node dist/api.js",
|
|
69
|
+
"api:dev": "tsc && node dist/api.js",
|
|
70
|
+
"lint": "biome check src/",
|
|
71
|
+
"test": "vitest run",
|
|
72
|
+
"test:watch": "vitest",
|
|
73
|
+
"test:coverage": "vitest run --coverage",
|
|
74
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
75
|
+
},
|
|
76
|
+
"bin": {
|
|
77
|
+
"violet-mcp": "./dist/bin.js"
|
|
78
|
+
}
|
|
6
79
|
}
|