@svgrid/mcp 3.0.31 → 3.0.33

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/index.js CHANGED
@@ -18,9 +18,9 @@
18
18
  * npx @svgrid/mcp
19
19
  */
20
20
  import { createRequire } from 'node:module';
21
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
22
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
23
- import { CallToolRequestSchema, GetPromptRequestSchema, ListPromptsRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
21
+ // Our own stdio transport, not @modelcontextprotocol/sdk: the SDK's HTTP and
22
+ // OAuth dependencies were most of a cold npx install (see stdio-server.ts).
23
+ import { StdioMcpServer } from './stdio-server.js';
24
24
  import { CORE_TOOLS, PREVIEW_TOOL } from './tool-defs.js';
25
25
  import { PROMPTS, getPrompt } from './prompts.js';
26
26
  import { installedGrid, versionNote } from './installed.js';
@@ -101,7 +101,7 @@ const pkgVersion = (() => {
101
101
  return '0.0.0';
102
102
  }
103
103
  })();
104
- const server = new Server({ name: '@svgrid/mcp', version: pkgVersion }, {
104
+ const server = new StdioMcpServer({ name: '@svgrid/mcp', version: pkgVersion }, {
105
105
  // Tools alone was half the protocol. The corpus is a natural fit for
106
106
  // resources (the user attaches a doc, no tool call needed) and the common
107
107
  // tasks are a natural fit for prompts.
@@ -152,7 +152,7 @@ async function listedTools() {
152
152
  tools.push(...studioTools.STUDIO_TOOLS);
153
153
  return tools;
154
154
  }
155
- server.setRequestHandler(ListToolsRequestSchema, async () => {
155
+ server.setRequestHandler('tools/list', async () => {
156
156
  const tools = await listedTools();
157
157
  // Warm the corpus once this reply is on the wire, so its first load overlaps
158
158
  // the model choosing a tool rather than the first call.
@@ -160,8 +160,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
160
160
  return { tools };
161
161
  });
162
162
  // ---- resources ------------------------------------------------------------
163
- server.setRequestHandler(ListResourcesRequestSchema, async (req) => (await corpus()).resources.listResources(req.params?.cursor));
164
- server.setRequestHandler(ReadResourceRequestSchema, async (req) => {
163
+ server.setRequestHandler('resources/list', async (req) => (await corpus()).resources.listResources(req.params?.cursor));
164
+ server.setRequestHandler('resources/read', async (req) => {
165
165
  const { preview, resources } = await corpus();
166
166
  const found = preview.readPreviewResource(req.params.uri) ?? resources.readResource(req.params.uri);
167
167
  if (!found)
@@ -169,8 +169,8 @@ server.setRequestHandler(ReadResourceRequestSchema, async (req) => {
169
169
  return found;
170
170
  });
171
171
  // ---- prompts --------------------------------------------------------------
172
- server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts: PROMPTS }));
173
- server.setRequestHandler(GetPromptRequestSchema, async (req) => {
172
+ server.setRequestHandler('prompts/list', async () => ({ prompts: PROMPTS }));
173
+ server.setRequestHandler('prompts/get', async (req) => {
174
174
  const found = getPrompt(req.params.name, (req.params.arguments ?? {}));
175
175
  if (!found)
176
176
  throw new Error(`No SvGrid prompt named "${req.params.name}".`);
@@ -284,8 +284,11 @@ const LEGACY_TARGET = {
284
284
  get_doc: 'svgrid_get',
285
285
  get_api_reference: 'svgrid_get',
286
286
  };
287
- server.setRequestHandler(CallToolRequestSchema, async (req) => {
287
+ server.setRequestHandler('tools/call', async (req) => {
288
288
  const { name, arguments: rawArgs } = req.params;
289
+ // As the SDK answered it: a call that names no tool is invalid params.
290
+ if (typeof name !== 'string')
291
+ throw Object.assign(new Error('Invalid params: tools/call needs a tool name'), { code: -32602 });
289
292
  const args = (rawArgs ?? {});
290
293
  const [{ core: coreTools, preview }] = await Promise.all([corpus(), loadStudio()]);
291
294
  // Retrieval tools, old names mapped onto the new ones.
@@ -346,13 +349,12 @@ server.setRequestHandler(CallToolRequestSchema, async (req) => {
346
349
  };
347
350
  });
348
351
  async function main() {
349
- // Connect and nothing else: `initialize` is answered by the SDK and needs
350
- // neither the corpus nor enterprise. They load on the first request that
352
+ // Connect and nothing else: `initialize` is answered by the transport and
353
+ // needs neither the corpus nor enterprise. They load on the first request that
351
354
  // does (normally tools/list). Loading them eagerly after connect did not
352
355
  // help: the first read of the 12 MB corpus held the event loop for seconds,
353
356
  // and the initialize reply waited behind it.
354
- const transport = new StdioServerTransport();
355
- await server.connect(transport);
357
+ server.connect();
356
358
  process.stderr.write(`@svgrid/mcp ${pkgVersion} on stdio\n`);
357
359
  }
358
360
  /** The fuller banner, once the corpus is in, naming both grid versions. */
package/dist/preview.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare const UI_MIME_TYPE = "text/html;profile=mcp-app";
8
8
  * start failing in a way nobody is watching for. `tools/mcp-tools.test.ts` checks these
9
9
  * against the workspace so they cannot quietly rot either.
10
10
  */
11
- export declare const PREVIEW_GRID_WC_VERSION = "3.0.32";
11
+ export declare const PREVIEW_GRID_WC_VERSION = "3.0.34";
12
12
  export declare function previewResource(): {
13
13
  uri: string;
14
14
  name: string;
package/dist/preview.js CHANGED
@@ -27,7 +27,7 @@ export const UI_MIME_TYPE = 'text/html;profile=mcp-app';
27
27
  * start failing in a way nobody is watching for. `tools/mcp-tools.test.ts` checks these
28
28
  * against the workspace so they cannot quietly rot either.
29
29
  */
30
- export const PREVIEW_GRID_WC_VERSION = '3.0.32';
30
+ export const PREVIEW_GRID_WC_VERSION = '3.0.34';
31
31
  const EXT_APPS_VERSION = '1.7.5';
32
32
  const CDN = 'https://cdn.jsdelivr.net/npm';
33
33
  /**
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The MCP stdio transport this server needs, in place of
3
+ * @modelcontextprotocol/sdk.
4
+ *
5
+ * The SDK carries HTTP transports and OAuth (Express, Hono, JOSE, AJV and
6
+ * their dependencies), none of which a stdio server runs, and a cold
7
+ * `npx -y @svgrid/mcp` spent its time installing them: 111 packages, 23 to 38
8
+ * seconds to the `initialize` reply against a client's 30 second connect
9
+ * timeout, with the server itself starting in 0.3 s.
10
+ *
11
+ * What MCP over stdio is: JSON-RPC 2.0, one message per line on stdin and
12
+ * stdout. This answers `initialize` the way the SDK does (the client's
13
+ * protocol version when it is one of SUPPORTED_PROTOCOL_VERSIONS, else the
14
+ * latest), answers `ping`, and hands every other request to the handler
15
+ * registered for its method. Unknown methods get -32601 and a handler that
16
+ * throws gets -32603 with its message, as from the SDK. Notifications need no
17
+ * reply: `notifications/initialized` and `notifications/cancelled` are
18
+ * accepted and nothing else is sent. Requests run concurrently, as the SDK
19
+ * runs them, so a slow first tools/call does not hold up a ping.
20
+ */
21
+ import type { Readable, Writable } from 'node:stream';
22
+ export declare const LATEST_PROTOCOL_VERSION = "2025-11-25";
23
+ export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
24
+ export declare const ErrorCode: {
25
+ readonly ParseError: -32700;
26
+ readonly InvalidRequest: -32600;
27
+ readonly MethodNotFound: -32601;
28
+ readonly InvalidParams: -32602;
29
+ readonly InternalError: -32603;
30
+ };
31
+ /** A request as a handler receives it, the same shape the SDK passed. */
32
+ export type McpRequest = {
33
+ method: string;
34
+ params: Record<string, any>;
35
+ };
36
+ type Handler = (request: McpRequest) => unknown | Promise<unknown>;
37
+ export declare class StdioMcpServer {
38
+ private readonly serverInfo;
39
+ private readonly options;
40
+ private readonly handlers;
41
+ constructor(serverInfo: {
42
+ name: string;
43
+ version: string;
44
+ }, options: {
45
+ capabilities: Record<string, unknown>;
46
+ instructions?: string;
47
+ });
48
+ setRequestHandler(method: string, handler: Handler): void;
49
+ /**
50
+ * The reply to one message, or null when none is owed (a notification).
51
+ * Exported for tests; connect() feeds it each line.
52
+ */
53
+ handle(message: unknown): Promise<object | null>;
54
+ /** Read requests from `input`, one per line, and write the replies to `output`. */
55
+ connect(input?: Readable, output?: Writable): void;
56
+ private initialize;
57
+ private result;
58
+ private error;
59
+ }
60
+ export {};
@@ -0,0 +1,95 @@
1
+ export const LATEST_PROTOCOL_VERSION = '2025-11-25';
2
+ export const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, '2025-06-18', '2025-03-26', '2024-11-05', '2024-10-07'];
3
+ export const ErrorCode = {
4
+ ParseError: -32700,
5
+ InvalidRequest: -32600,
6
+ MethodNotFound: -32601,
7
+ InvalidParams: -32602,
8
+ InternalError: -32603,
9
+ };
10
+ export class StdioMcpServer {
11
+ serverInfo;
12
+ options;
13
+ handlers = new Map();
14
+ constructor(serverInfo, options) {
15
+ this.serverInfo = serverInfo;
16
+ this.options = options;
17
+ }
18
+ setRequestHandler(method, handler) {
19
+ this.handlers.set(method, handler);
20
+ }
21
+ /**
22
+ * The reply to one message, or null when none is owed (a notification).
23
+ * Exported for tests; connect() feeds it each line.
24
+ */
25
+ async handle(message) {
26
+ const m = (message ?? {});
27
+ const isRequest = m.id !== undefined && m.id !== null;
28
+ if (typeof m.method !== 'string') {
29
+ return isRequest ? this.error(m.id, ErrorCode.InvalidRequest, 'Invalid request: no method') : null;
30
+ }
31
+ // A notification never gets a reply, whatever it is.
32
+ if (!isRequest)
33
+ return null;
34
+ const params = m.params && typeof m.params === 'object' ? m.params : {};
35
+ try {
36
+ if (m.method === 'initialize')
37
+ return this.result(m.id, this.initialize(params));
38
+ if (m.method === 'ping')
39
+ return this.result(m.id, {});
40
+ const handler = this.handlers.get(m.method);
41
+ if (!handler)
42
+ return this.error(m.id, ErrorCode.MethodNotFound, `Method not found: ${m.method}`);
43
+ return this.result(m.id, (await handler({ method: m.method, params })) ?? {});
44
+ }
45
+ catch (err) {
46
+ const e = err;
47
+ const code = Number.isSafeInteger(e?.code) ? e.code : ErrorCode.InternalError;
48
+ return this.error(m.id, code, e?.message ?? String(err), e?.data);
49
+ }
50
+ }
51
+ /** Read requests from `input`, one per line, and write the replies to `output`. */
52
+ connect(input = process.stdin, output = process.stdout) {
53
+ let buffer = '';
54
+ const send = (reply) => {
55
+ if (reply)
56
+ output.write(JSON.stringify(reply) + '\n');
57
+ };
58
+ input.setEncoding('utf8');
59
+ input.on('data', (chunk) => {
60
+ buffer += chunk;
61
+ let nl;
62
+ while ((nl = buffer.indexOf('\n')) !== -1) {
63
+ const line = buffer.slice(0, nl).replace(/\r$/, '');
64
+ buffer = buffer.slice(nl + 1);
65
+ if (!line.trim())
66
+ continue;
67
+ let message;
68
+ try {
69
+ message = JSON.parse(line);
70
+ }
71
+ catch {
72
+ send(this.error(null, ErrorCode.ParseError, 'Parse error: a line was not JSON'));
73
+ continue;
74
+ }
75
+ // Not awaited: each request answers when it is ready.
76
+ void this.handle(message).then(send, (err) => process.stderr.write(`@svgrid/mcp: ${String(err)}\n`));
77
+ }
78
+ });
79
+ }
80
+ initialize(params) {
81
+ const requested = params.protocolVersion;
82
+ return {
83
+ protocolVersion: SUPPORTED_PROTOCOL_VERSIONS.includes(requested) ? requested : LATEST_PROTOCOL_VERSION,
84
+ capabilities: this.options.capabilities,
85
+ serverInfo: this.serverInfo,
86
+ ...(this.options.instructions ? { instructions: this.options.instructions } : {}),
87
+ };
88
+ }
89
+ result(id, result) {
90
+ return { jsonrpc: '2.0', id, result };
91
+ }
92
+ error(id, code, message, data) {
93
+ return { jsonrpc: '2.0', id, error: { code, message, ...(data !== undefined ? { data } : {}) } };
94
+ }
95
+ }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "commercial",
6
6
  "url": "https://svgrid.com/pricing"
7
7
  },
8
- "version": "3.0.31",
8
+ "version": "3.0.33",
9
9
  "description": "Model Context Protocol server for SvGrid, the Svelte 5 data grid: checks the code your AI writes against the real API surface, plus version-pinned docs, API reference and 373 demo sources.",
10
10
  "license": "MIT",
11
11
  "author": "jQWidgets <sales@jqwidgets.com>",
@@ -30,12 +30,10 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@modelcontextprotocol/sdk": "^1.0.4",
34
- "svelte": "^5.55.5",
35
- "zod": "^3.23.8"
33
+ "svelte": "^5.55.5"
36
34
  },
37
35
  "peerDependencies": {
38
- "@svgrid/enterprise": "^3.1.25"
36
+ "@svgrid/enterprise": "^3.1.27"
39
37
  },
40
38
  "peerDependenciesMeta": {
41
39
  "@svgrid/enterprise": {
@@ -45,7 +43,7 @@
45
43
  "devDependencies": {
46
44
  "@types/node": "^22.10.7",
47
45
  "typescript": "6.0.3",
48
- "@svgrid/enterprise": "^3.1.25"
46
+ "@svgrid/enterprise": "^3.1.27"
49
47
  },
50
48
  "engines": {
51
49
  "node": ">=18"
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "com.svgrid/svgrid",
4
4
  "title": "SvGrid",
5
5
  "description": "Checks AI-written SvGrid code against the real API, plus version-pinned Svelte 5 grid docs.",
6
- "version": "3.0.31",
6
+ "version": "3.0.33",
7
7
  "websiteUrl": "https://svgrid.com/docs/help/mcp-server/",
8
8
  "repository": {
9
9
  "url": "https://github.com/sv-grid/sv-grid",
@@ -15,7 +15,7 @@
15
15
  "registryType": "npm",
16
16
  "registryBaseUrl": "https://registry.npmjs.org",
17
17
  "identifier": "@svgrid/mcp",
18
- "version": "3.0.31",
18
+ "version": "3.0.33",
19
19
  "runtimeHint": "npx",
20
20
  "transport": {
21
21
  "type": "stdio"