@stone-js/mcp-dev 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright © 2026 Stone Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # Stone.js · MCP dev server
2
+
3
+ [![npm](https://img.shields.io/npm/v/@stone-js/mcp-dev)](https://www.npmjs.com/package/@stone-js/mcp-dev)
4
+ [![CI](https://github.com/stone-foundation/stone-js-framework/actions/workflows/ci.yml/badge.svg)](https://github.com/stone-foundation/stone-js-framework/actions/workflows/ci.yml)
5
+ [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=stone-foundation_stone-js-framework&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=stone-foundation_stone-js-framework)
6
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+ [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
8
+
9
+ > Serve Stone.js's knowledge to your coding agent. One command — `stone mcp` — starts an MCP server exposing the framework's concepts, modules and best-practices (plus your own tools), so the LLM masters the context while you master the domain.
10
+
11
+ Part of **[Stone.js](https://stonejs.dev)**, the reference implementation of the
12
+ [Continuum Architecture](https://evens-stone.github.io/continuum-manifesto/manifesto): write your
13
+ domain once, and the context (runtime, protocol, caller) applies to it at run time.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm i -D @stone-js/mcp-dev
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Add the command to your app with the `@McpDev()` decorator (or register `mcpDevBlueprint`):
24
+
25
+ ```ts
26
+ import { McpDev } from '@stone-js/mcp-dev'
27
+ import { StoneApp } from '@stone-js/core'
28
+
29
+ @McpDev()
30
+ @StoneApp({ name: 'my-app' })
31
+ export class Application {}
32
+ ```
33
+
34
+ Then start the server from your project:
35
+
36
+ ```bash
37
+ stone mcp
38
+ ```
39
+
40
+ `stone mcp` starts an MCP server over **stdio** and keeps running until you press `Ctrl+C`, exactly
41
+ like `stone dev`. It hands the [MCP SDK](https://github.com/modelcontextprotocol) the built-in
42
+ framework-knowledge tools and lets the SDK own the protocol and run the handlers — these are dev and
43
+ knowledge helpers, not your domain, so they do not need to traverse the kernel. Every tool call is
44
+ logged to **stderr** (stdout is reserved for the JSON-RPC protocol) so you watch the agent think in
45
+ real time.
46
+
47
+ ### Register it for your agent
48
+
49
+ Let `stone mcp` write `.mcp.json` for you (create or merge, never clobbering your own config):
50
+
51
+ ```bash
52
+ stone mcp --init
53
+ ```
54
+
55
+ Or add the entry yourself (Claude Code, Cursor, Claude Desktop, …):
56
+
57
+ ```jsonc
58
+ { "mcpServers": {
59
+ "stone": { "command": "stone", "args": ["mcp"] }
60
+ } }
61
+ ```
62
+
63
+ `.mcp.json` can be committed or `.gitignore`d per developer.
64
+
65
+ ### Framework-knowledge tools
66
+
67
+ | Tool | What it returns |
68
+ |---|---|
69
+ | `stone_search` | Search the knowledge base (concepts, modules, best-practices, gaps). |
70
+ | `stone_concept` | Explain a core concept by id (omit id to list them all). |
71
+ | `stone_docs` | Links to the authoritative documentation. |
72
+ | `stone_modules` | The ecosystem modules and what each does. |
73
+ | `stone_best_practices` | Conventions and anti-patterns, each with its rationale. |
74
+ | `stone_gaps` | What the framework does not (yet) provide, and what to reach for. |
75
+ | `stone_brief` | The full agent brief (`llms-full.txt`). |
76
+
77
+ ### App-introspection tools
78
+
79
+ These read *your* app's resolved blueprint (read-only, secrets redacted), so the agent understands
80
+ the app you are building, not just the framework:
81
+
82
+ | Tool | What it returns |
83
+ |---|---|
84
+ | `stone_app` | App name, env, active platform, and counts of routes/commands/providers/adapters. |
85
+ | `stone_routes` | The route tree (path, methods, name, handler, middleware). |
86
+ | `stone_commands` | The CLI commands (name, alias, args, description). |
87
+ | `stone_adapters` | Registered adapters (platform, alias, default/current) and the active platform. |
88
+ | `stone_providers` | The service providers. |
89
+ | `stone_kernel` | The kernel pipeline: event handler, middleware, error handlers. |
90
+ | `stone_key_routes` | Key-routing definitions (event-bus / realtime): key to handler. |
91
+ | `stone_config` | A resolved `stone.*` config value by dotted key (secrets redacted); omit the key to list them. |
92
+
93
+ ### Your own tools
94
+
95
+ Add project-specific tools (they run in-process, so they receive their arguments directly). Set the
96
+ server name, `instructions`, or enable the GitHub report tools under `stone.mcpDev`:
97
+
98
+ ```ts
99
+ import { McpDev } from '@stone-js/mcp-dev'
100
+
101
+ @McpDev({
102
+ name: 'my-app-dev',
103
+ tools: [
104
+ { name: 'db_schema', description: 'Return the current DB schema', handler: () => readSchema() }
105
+ ],
106
+ report: { token: process.env.GITHUB_TOKEN!, repo: 'my-org/my-app' }
107
+ })
108
+ @StoneApp({ name: 'my-app' })
109
+ export class Application {}
110
+ ```
111
+
112
+ The knowledge base and `llms.txt` helpers are also exported directly (`stoneMcpTools`,
113
+ `searchKnowledge`, `generateLlmsTxt`, `generateLlmsFullTxt`) if you want to serve them elsewhere.
114
+
115
+ ## Agent Skills
116
+
117
+ The package ships [Agent Skills](https://agentskills.io) (`stone-js`, `stone-js-routing`,
118
+ `stone-js-adapters`) under [`skills/`](./skills): portable `SKILL.md` folders that teach a
119
+ skills-compatible agent the framework's conventions on demand. They complement the MCP tools (the
120
+ tools introspect the app; the skills say how to build it). Copy the ones you want into your agent's
121
+ skills directory:
122
+
123
+ ```bash
124
+ mkdir -p .claude/skills
125
+ cp -R node_modules/@stone-js/mcp-dev/skills/stone-js* .claude/skills/
126
+ ```
127
+
128
+ ## Documentation
129
+
130
+ Full documentation: **[stonejs.dev/docs/extensions/mcp](https://stonejs.dev/docs/extensions/mcp)**.
131
+
132
+ ## License
133
+
134
+ [MIT](https://opensource.org/licenses/MIT) © Evens Pierre ("Mr. Stone") and the Stone.js contributors.
@@ -0,0 +1,62 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { McpDevLogger, McpDevOptions, McpToolDef } from './declarations';
3
+ /**
4
+ * An MCP tool result payload (the SDK content shape).
5
+ */
6
+ export interface McpToolResult {
7
+ content: Array<{
8
+ type: 'text';
9
+ text: string;
10
+ }>;
11
+ isError?: boolean;
12
+ }
13
+ /**
14
+ * Wrap any handler return value as MCP text content (JSON for structured data).
15
+ *
16
+ * @param result - The value a tool handler returned.
17
+ * @returns The MCP content payload.
18
+ */
19
+ export declare function toToolContent(result: unknown): McpToolResult;
20
+ /**
21
+ * Create the activity logger. It writes to **stderr** (never stdout, which the stdio transport
22
+ * reserves for the JSON-RPC protocol); a no-op when `quiet` is set.
23
+ *
24
+ * @param quiet - Silence the log.
25
+ * @returns The logger.
26
+ */
27
+ export declare function createStderrLogger(quiet?: boolean): McpDevLogger;
28
+ /**
29
+ * Resolve the full tool list: the built-in framework-knowledge tools, the optional GitHub report
30
+ * tools, then the app's own tools.
31
+ *
32
+ * @param options - The dev-server options.
33
+ * @returns The merged tool list.
34
+ */
35
+ export declare function resolveTools(options: McpDevOptions): McpToolDef[];
36
+ /**
37
+ * Build the SDK callback for one tool: log the call to stderr, run the handler, log the outcome,
38
+ * and wrap the result (or the error) as MCP content.
39
+ *
40
+ * @param tool - The tool definition.
41
+ * @param log - The activity logger.
42
+ * @returns The SDK tool callback.
43
+ */
44
+ export declare function createToolCallback(tool: McpToolDef, log: McpDevLogger): (args: Record<string, unknown>) => Promise<McpToolResult>;
45
+ /**
46
+ * Build a fully-configured MCP server: advertise the instructions and register every resolved tool
47
+ * with its logging callback. The handlers run in-process (dev/knowledge helpers, not the domain).
48
+ *
49
+ * @param options - The dev-server options.
50
+ * @param log - The activity logger.
51
+ * @returns The configured MCP server.
52
+ */
53
+ export declare function buildMcpServer(options: McpDevOptions, log: McpDevLogger): McpServer;
54
+ /**
55
+ * Start the MCP dev server over stdio and keep it alive until the process is interrupted.
56
+ *
57
+ * The stdio transport speaks JSON-RPC on stdout and keeps the event loop alive by reading stdin,
58
+ * so `Ctrl+C` (SIGINT) stops it, exactly like `stone dev`.
59
+ *
60
+ * @param options - The dev-server options.
61
+ */
62
+ export declare function startMcpDevServer(options: McpDevOptions): Promise<void>;
@@ -0,0 +1,19 @@
1
+ import { McpDevOptions } from '../../declarations';
2
+ import { ClassType } from '@stone-js/core';
3
+ /**
4
+ * Options for the `McpDev` decorator.
5
+ */
6
+ export interface McpDevDecoratorOptions extends McpDevOptions {
7
+ }
8
+ /**
9
+ * Browser stub of `@McpDev()`: a no-op.
10
+ *
11
+ * The dev MCP server (`stone mcp`) is a Node-only, development concern. Stubbing the decorator for
12
+ * the browser keeps an isomorphic app compiling and inert there, without dragging the CLI command,
13
+ * the MCP SDK server, or `node:fs` into the browser bundle (which would break a SPA). The real
14
+ * decorator lives in the Node build.
15
+ *
16
+ * @param _options - Ignored in the browser.
17
+ * @returns A no-op class decorator.
18
+ */
19
+ export declare const McpDev: <T extends ClassType = ClassType>(_options?: McpDevDecoratorOptions) => ClassDecorator;
@@ -0,0 +1,18 @@
1
+ import { McpDevOptions } from '../../declarations';
2
+ import { McpDevBlueprint } from '../../options/McpDevBlueprint';
3
+ /**
4
+ * Browser stub of the MCP dev blueprint.
5
+ *
6
+ * It carries the config bucket but wires **no** blueprint middleware, so importing it into a browser
7
+ * bundle never pulls the Node-only `stone mcp` command, its server (`@modelcontextprotocol/sdk`,
8
+ * stdio) or the filesystem. The `stone mcp` command is a development, Node-only concern; in the
9
+ * browser this keeps the app compiling and inert.
10
+ */
11
+ export declare const mcpDevBlueprint: McpDevBlueprint;
12
+ /**
13
+ * Browser stub of `defineMcpDev`: returns the config bucket with no Node wiring.
14
+ *
15
+ * @param options - The MCP dev options.
16
+ * @returns The (inert) blueprint.
17
+ */
18
+ export declare function defineMcpDev(options?: McpDevOptions): McpDevBlueprint;
@@ -0,0 +1,37 @@
1
+ import { classDecoratorLegacyWrapper } from '@stone-js/core';
2
+
3
+ /**
4
+ * Browser stub of `@McpDev()`: a no-op.
5
+ *
6
+ * The dev MCP server (`stone mcp`) is a Node-only, development concern. Stubbing the decorator for
7
+ * the browser keeps an isomorphic app compiling and inert there, without dragging the CLI command,
8
+ * the MCP SDK server, or `node:fs` into the browser bundle (which would break a SPA). The real
9
+ * decorator lives in the Node build.
10
+ *
11
+ * @param _options - Ignored in the browser.
12
+ * @returns A no-op class decorator.
13
+ */
14
+ const McpDev = (_options = {}) => {
15
+ return classDecoratorLegacyWrapper((_target, _context) => { });
16
+ };
17
+
18
+ /**
19
+ * Browser stub of the MCP dev blueprint.
20
+ *
21
+ * It carries the config bucket but wires **no** blueprint middleware, so importing it into a browser
22
+ * bundle never pulls the Node-only `stone mcp` command, its server (`@modelcontextprotocol/sdk`,
23
+ * stdio) or the filesystem. The `stone mcp` command is a development, Node-only concern; in the
24
+ * browser this keeps the app compiling and inert.
25
+ */
26
+ const mcpDevBlueprint = { stone: { mcpDev: {} } };
27
+ /**
28
+ * Browser stub of `defineMcpDev`: returns the config bucket with no Node wiring.
29
+ *
30
+ * @param options - The MCP dev options.
31
+ * @returns The (inert) blueprint.
32
+ */
33
+ function defineMcpDev(options = {}) {
34
+ return { stone: { mcpDev: options } };
35
+ }
36
+
37
+ export { McpDev, defineMcpDev, mcpDevBlueprint };
@@ -0,0 +1,27 @@
1
+ import { IContainer, IncomingEvent } from '@stone-js/core';
2
+ import { CommandOptions } from '../declarations';
3
+ /**
4
+ * Configuration for the `mcp` command.
5
+ */
6
+ export declare const mcpCommandOptions: CommandOptions;
7
+ /**
8
+ * Starts the MCP dev server from the `stone mcp` command.
9
+ *
10
+ * It reads `stone.mcpDev` from the blueprint (server name, instructions, your tools) and lets the
11
+ * MCP SDK own the protocol and tool execution: framework knowledge helpers do not need to traverse
12
+ * the kernel. `--name` / `--quiet` flags override the configured values.
13
+ */
14
+ export declare class McpCommand {
15
+ private readonly container;
16
+ /**
17
+ * @param container - The dependency injection container.
18
+ * @throws {McpDevError} If the container is not provided.
19
+ */
20
+ constructor(container: IContainer);
21
+ /**
22
+ * Handle the `mcp` command: start the server and keep it running until interrupted.
23
+ *
24
+ * @param event - The incoming CLI event carrying the parsed flags.
25
+ */
26
+ handle(event: IncomingEvent): Promise<void>;
27
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The platform tag the CLI adapter runs under. Re-declared locally (rather than imported) to keep
3
+ * this package decoupled from `@stone-js/node-cli-adapter`; the value must match the adapter's.
4
+ */
5
+ export declare const NODE_CONSOLE_PLATFORM: string;
6
+ /** The default MCP server name when the app declares none. */
7
+ export declare const DEFAULT_MCP_SERVER_NAME: string;
8
+ /** The default MCP server version. */
9
+ export declare const DEFAULT_MCP_SERVER_VERSION: string;
10
+ /**
11
+ * The default `instructions` advertised to the agent: what this server is and how to use it.
12
+ */
13
+ export declare const DEFAULT_MCP_INSTRUCTIONS: string;
@@ -0,0 +1,115 @@
1
+ /** A core architectural concept of Stone.js. */
2
+ export interface Concept {
3
+ /** Slug id (e.g. `continuum`). */
4
+ id: string;
5
+ /** Human title. */
6
+ title: string;
7
+ /** One-paragraph explanation. */
8
+ summary: string;
9
+ }
10
+ /** A module of the ecosystem. */
11
+ export interface ModuleInfo {
12
+ /** npm package name. */
13
+ package: string;
14
+ /** One-line description. */
15
+ summary: string;
16
+ /** Where it sits in the architecture. */
17
+ tier: 'primitive' | 'core' | 'crosscutting' | 'adapter' | 'frontend' | 'extension' | 'tooling';
18
+ }
19
+ /** A framework convention (with its rationale). */
20
+ export interface BestPractice {
21
+ /** The rule. */
22
+ rule: string;
23
+ /** Why it exists. */
24
+ why: string;
25
+ }
26
+ /** Something the framework does not (yet) provide. */
27
+ export interface Gap {
28
+ /** The capability. */
29
+ name: string;
30
+ /** `planned` (on the roadmap) or `missing` (integrate a third party). */
31
+ status: 'planned' | 'missing';
32
+ /** Guidance. */
33
+ note: string;
34
+ }
35
+ /** The machine-readable map of Stone.js. */
36
+ export interface KnowledgeBase {
37
+ name: string;
38
+ tagline: string;
39
+ version: string;
40
+ concepts: Concept[];
41
+ modules: ModuleInfo[];
42
+ bestPractices: BestPractice[];
43
+ gaps: Gap[];
44
+ }
45
+ /**
46
+ * A tool definition exposed to the agent over MCP. The `handler` runs in-process (the dev server
47
+ * hands the SDK the callback directly): these are framework-knowledge and dev helpers, not your
48
+ * domain, so they do not traverse the kernel.
49
+ */
50
+ export interface McpToolDef {
51
+ name: string;
52
+ description?: string;
53
+ inputSchema?: Record<string, unknown>;
54
+ handler: (args: Record<string, unknown>) => unknown | Promise<unknown>;
55
+ }
56
+ /**
57
+ * Options for the GitHub report tools: open a bug/feature issue straight from the dev loop.
58
+ */
59
+ export interface ReportToolsOptions {
60
+ /** GitHub token with `issues:write` on the target repo. */
61
+ token: string;
62
+ /** Target repository as `owner/repo`. */
63
+ repo: string;
64
+ /** Injectable fetch (defaults to the global). Mainly for testing. */
65
+ fetch?: typeof fetch;
66
+ }
67
+ /**
68
+ * A logger for the dev server's activity. It writes to **stderr** so stdout stays reserved for the
69
+ * MCP protocol (stdio transport speaks JSON-RPC on stdout — any other write there corrupts it).
70
+ */
71
+ export type McpDevLogger = (message: string) => void;
72
+ /**
73
+ * Minimal yargs builder surface used to declare the command's options. Re-declared locally so the
74
+ * package stays decoupled from `@stone-js/node-cli-adapter` (the CLI adapter passes the real
75
+ * yargs builder at run time; this only shapes the callback).
76
+ */
77
+ export interface IArgv {
78
+ option: (name: string, options: {
79
+ type?: string;
80
+ alias?: string;
81
+ desc?: string;
82
+ default?: unknown;
83
+ }) => IArgv;
84
+ positional: (name: string, options: Record<string, unknown>) => IArgv;
85
+ }
86
+ /**
87
+ * CLI command options, structurally compatible with `@stone-js/node-cli-adapter`'s `CommandOptions`.
88
+ */
89
+ export interface CommandOptions {
90
+ name: string;
91
+ alias?: string | string[];
92
+ args?: string | string[];
93
+ desc?: string;
94
+ options?: (yargs: IArgv) => IArgv;
95
+ }
96
+ /**
97
+ * Options for the MCP dev server, exposed on the blueprint under `stone.mcpDev`.
98
+ *
99
+ * `stone mcp` starts an MCP server (stdio) that hands the SDK the built-in framework-knowledge
100
+ * tools merged with yours, and logs every tool call to stderr so you watch the agent think.
101
+ */
102
+ export interface McpDevOptions {
103
+ /** The MCP server name advertised to the agent. */
104
+ name?: string;
105
+ /** The MCP server version. */
106
+ version?: string;
107
+ /** The `instructions` string advertised to the agent (the Continuum contract). */
108
+ instructions?: string;
109
+ /** Your own tools, merged with the built-in framework-knowledge tools. */
110
+ tools?: McpToolDef[];
111
+ /** Enable the GitHub bug/feature report tools by passing a token + repo. */
112
+ report?: ReportToolsOptions;
113
+ /** Silence the stderr activity log. */
114
+ quiet?: boolean;
115
+ }
@@ -0,0 +1,24 @@
1
+ import { McpDevOptions } from '../declarations';
2
+ import { ClassType } from '@stone-js/core';
3
+ /**
4
+ * Options for the `McpDev` decorator.
5
+ */
6
+ export interface McpDevDecoratorOptions extends McpDevOptions {
7
+ }
8
+ /**
9
+ * A class decorator that adds the `stone mcp` command to your app.
10
+ *
11
+ * Declarative counterpart of registering {@link mcpDevBlueprint}: apply it to your app class to
12
+ * expose the framework-knowledge tools (plus any you declare) to a coding agent over MCP.
13
+ *
14
+ * @param options - The MCP dev options (server name, instructions, your tools).
15
+ * @returns A class decorator.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * @McpDev({ tools: [myTool] })
20
+ * @StoneApp({ name: 'my-app' })
21
+ * export class Application {}
22
+ * ```
23
+ */
24
+ export declare const McpDev: <T extends ClassType = ClassType>(options?: McpDevDecoratorOptions) => ClassDecorator;
@@ -0,0 +1,7 @@
1
+ import { ErrorOptions, RuntimeError } from '@stone-js/core';
2
+ /**
3
+ * Custom error for the MCP dev module.
4
+ */
5
+ export declare class McpDevError extends RuntimeError {
6
+ constructor(message: string, options?: ErrorOptions);
7
+ }
@@ -0,0 +1,13 @@
1
+ export * from './McpDevServer';
2
+ export * from './commands/McpCommand';
3
+ export * from './constants';
4
+ export * from './declarations';
5
+ export * from './decorators/McpDev';
6
+ export * from './errors/McpDevError';
7
+ export * from './introspection';
8
+ export * from './knowledge';
9
+ export * from './llms';
10
+ export * from './mcpJson';
11
+ export * from './middleware/BlueprintMiddleware';
12
+ export * from './options/McpDevBlueprint';
13
+ export * from './tools';