@rsconcept/rstool-mcp 0.1.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 +21 -0
- package/README.md +125 -0
- package/dist/bin/server.d.ts +1 -0
- package/dist/bin/server.js +18 -0
- package/dist/bin/server.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +2 -0
- package/dist/server-CzaNBfgR.js +323 -0
- package/dist/server-CzaNBfgR.js.map +1 -0
- package/package.json +64 -0
- package/src/bin/server.ts +16 -0
- package/src/index.ts +2 -0
- package/src/server.test.ts +38 -0
- package/src/server.ts +105 -0
- package/src/tools.ts +286 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 IRBorisov and Concept Portal contributors
|
|
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,125 @@
|
|
|
1
|
+
# @rsconcept/rstool-mcp
|
|
2
|
+
|
|
3
|
+
[Model Context Protocol](https://modelcontextprotocol.io/) adapter for [`@rsconcept/rstool`](https://www.npmjs.com/package/@rsconcept/rstool). Exposes the full `RSToolAgent` contract — sessions, constituent upserts, RSLang analysis, diagnostics, modeling, evaluation — as MCP **tools** over stdio, so any MCP-capable host (Cursor, Claude Desktop, your own client) can drive rstool natively.
|
|
4
|
+
|
|
5
|
+
If you do not need MCP, use `@rsconcept/rstool` directly (library API or stdio JSON wrapper).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @rsconcept/rstool-mcp
|
|
11
|
+
# or per-project:
|
|
12
|
+
npm install @rsconcept/rstool-mcp
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The package ships a `rstool-mcp` bin that launches the stdio server. It depends on `@rsconcept/rstool` and (transitively) `@rsconcept/domain`; no Portal checkout is required.
|
|
16
|
+
|
|
17
|
+
## Run
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx rstool-mcp
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The server announces readiness on stderr (`rstool-mcp server ready on stdio`) and then speaks the MCP protocol on stdin/stdout. There is no HTTP port.
|
|
24
|
+
|
|
25
|
+
## Configure in Cursor
|
|
26
|
+
|
|
27
|
+
Add the server to your Cursor MCP configuration (`~/.cursor/mcp.json`):
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"mcpServers": {
|
|
32
|
+
"rstool": {
|
|
33
|
+
"command": "npx",
|
|
34
|
+
"args": ["-y", "@rsconcept/rstool-mcp"]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Restart Cursor; the tools appear under the **rstool** server. Pin a version if you prefer reproducible installs:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"mcpServers": {
|
|
45
|
+
"rstool": {
|
|
46
|
+
"command": "npx",
|
|
47
|
+
"args": ["-y", "@rsconcept/rstool-mcp@0.1.0"]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Configure in Claude Desktop
|
|
54
|
+
|
|
55
|
+
Edit `claude_desktop_config.json` (`~/Library/Application Support/Claude/` on macOS, `%APPDATA%\Claude\` on Windows):
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"mcpServers": {
|
|
60
|
+
"rstool": {
|
|
61
|
+
"command": "npx",
|
|
62
|
+
"args": ["-y", "@rsconcept/rstool-mcp"]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Exposed tools
|
|
69
|
+
|
|
70
|
+
| MCP tool | Wraps | Notes |
|
|
71
|
+
|----------|-------|-------|
|
|
72
|
+
| `ping` | — | Liveness + `contractVersion`. |
|
|
73
|
+
| `list_methods` | — | Enumerate available tools. |
|
|
74
|
+
| `create_session` | `RSToolAgent.createSession` | Optional `initial` seed. |
|
|
75
|
+
| `add_or_update_constituenta` | `addOrUpdateConstituenta` | Single upsert. |
|
|
76
|
+
| `analyze_expression` | `analyzeExpression` | Parser + semantic. |
|
|
77
|
+
| `get_form_state` | `getFormState` | Current `SessionState`. |
|
|
78
|
+
| `list_diagnostics` | `listDiagnostics` | Filterable. |
|
|
79
|
+
| `commit_step` | `commitStep` | Records a `SessionRevision`. |
|
|
80
|
+
| `export_session` | `exportSession` | JSON string. |
|
|
81
|
+
| `import_session` | `importSession` | Restore from JSON. |
|
|
82
|
+
| `set_constituenta_value` | `setConstituentaValue` | Bind interpretable. |
|
|
83
|
+
| `set_constituenta_values` | `setConstituentaValues` | Batch bindings. |
|
|
84
|
+
| `clear_constituenta_values` | `clearConstituentaValues` | Reset values. |
|
|
85
|
+
| `get_model_state` | `getModelState` | Values + statuses. |
|
|
86
|
+
| `evaluate_expression` | `evaluateExpression` | Scratch evaluation. |
|
|
87
|
+
| `evaluate_constituenta` | `evaluateConstituenta` | Stored derived constituent. |
|
|
88
|
+
| `recalculate_model` | `recalculateModel` | Full recompute. |
|
|
89
|
+
|
|
90
|
+
Input schemas are intentionally permissive (`additionalProperties: true`) where the rstool input is structurally rich (e.g. `ConstituentaDraft`, `SessionState`); the wrapped `RSToolAgent` validates inputs at runtime and returns deterministic error responses, surfaced through `isError: true` on the MCP response.
|
|
91
|
+
|
|
92
|
+
## Programmatic use
|
|
93
|
+
|
|
94
|
+
If you want to build a custom transport (HTTP, in-process) instead of stdio:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { StreamableHttpServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
98
|
+
import { buildRSToolMcpServer } from '@rsconcept/rstool-mcp';
|
|
99
|
+
|
|
100
|
+
const server = buildRSToolMcpServer();
|
|
101
|
+
const transport = new StreamableHttpServerTransport();
|
|
102
|
+
await server.connect(transport);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or share a single `RSToolAgent` between multiple servers / requests:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { RSToolAgent } from '@rsconcept/rstool';
|
|
109
|
+
import { buildRSToolMcpServer } from '@rsconcept/rstool-mcp';
|
|
110
|
+
|
|
111
|
+
const tool = new RSToolAgent();
|
|
112
|
+
const server = buildRSToolMcpServer({ tool, name: 'my-rstool-mcp', version: '0.2.0' });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Companion docs
|
|
116
|
+
|
|
117
|
+
For RS language, the rstool contract, error codes, and common workflows, agents should read [`@rsconcept/rstool/docs`](https://www.npmjs.com/package/@rsconcept/rstool#agent-skill) and the bundled `rstool-helper` skill that ships with `@rsconcept/rstool`.
|
|
118
|
+
|
|
119
|
+
## Publishing
|
|
120
|
+
|
|
121
|
+
Maintainers: see [PUBLISHING.md](./PUBLISHING.md) for npm release steps.
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as buildRSToolMcpServer } from "../server-CzaNBfgR.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
//#region src/bin/server.ts
|
|
5
|
+
async function main() {
|
|
6
|
+
const server = buildRSToolMcpServer();
|
|
7
|
+
const transport = new StdioServerTransport();
|
|
8
|
+
await server.connect(transport);
|
|
9
|
+
process.stderr.write("rstool-mcp server ready on stdio\n");
|
|
10
|
+
}
|
|
11
|
+
main().catch((error) => {
|
|
12
|
+
process.stderr.write(`rstool-mcp fatal: ${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
export {};
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../../src/bin/server.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\n\nimport { buildRSToolMcpServer } from '../server';\n\nasync function main(): Promise<void> {\n const server = buildRSToolMcpServer();\n const transport = new StdioServerTransport();\n await server.connect(transport);\n process.stderr.write('rstool-mcp server ready on stdio\\n');\n}\n\nmain().catch(error => {\n process.stderr.write(`rstool-mcp fatal: ${error instanceof Error ? error.stack ?? error.message : String(error)}\\n`);\n process.exit(1);\n});\n"],"mappings":";;;;AAKA,eAAe,OAAsB;CACnC,MAAM,SAAS,qBAAqB;CACpC,MAAM,YAAY,IAAI,qBAAqB;CAC3C,MAAM,OAAO,QAAQ,SAAS;CAC9B,QAAQ,OAAO,MAAM,oCAAoC;AAC3D;AAEA,KAAK,EAAE,OAAM,UAAS;CACpB,QAAQ,OAAO,MAAM,qBAAqB,iBAAiB,QAAQ,MAAM,SAAS,MAAM,UAAU,OAAO,KAAK,EAAE,GAAG;CACnH,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { RSToolAgent } from "@rsconcept/rstool";
|
|
3
|
+
|
|
4
|
+
//#region src/server.d.ts
|
|
5
|
+
interface BuildRSToolMcpServerOptions {
|
|
6
|
+
/** Pre-built RSToolAgent. Defaults to a fresh in-memory instance. */
|
|
7
|
+
tool?: RSToolAgent;
|
|
8
|
+
/** Server name advertised to MCP clients. */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** Server version advertised to MCP clients. */
|
|
11
|
+
version?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build an MCP `McpServer` instance that exposes the `@rsconcept/rstool` contract.
|
|
15
|
+
*
|
|
16
|
+
* The returned server is not yet connected to a transport. Wrap it with a
|
|
17
|
+
* `StdioServerTransport` (for local subprocess hosts like Cursor and Claude Desktop) or
|
|
18
|
+
* an HTTP transport, then call `server.connect(transport)`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
23
|
+
* import { buildRSToolMcpServer } from '@rsconcept/rstool-mcp';
|
|
24
|
+
*
|
|
25
|
+
* const server = buildRSToolMcpServer();
|
|
26
|
+
* await server.connect(new StdioServerTransport());
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function buildRSToolMcpServer(options?: BuildRSToolMcpServerOptions): McpServer;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/tools.d.ts
|
|
32
|
+
interface ToolDefinition {
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
inputSchema: {
|
|
36
|
+
type: 'object';
|
|
37
|
+
properties: Record<string, unknown>;
|
|
38
|
+
required?: string[];
|
|
39
|
+
additionalProperties?: boolean;
|
|
40
|
+
};
|
|
41
|
+
invoke: (tool: RSToolAgent, args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
declare const TOOL_DEFINITIONS: ToolDefinition[];
|
|
44
|
+
//#endregion
|
|
45
|
+
export { type BuildRSToolMcpServerOptions, TOOL_DEFINITIONS, type ToolDefinition, buildRSToolMcpServer };
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { RSToolAgent } from "@rsconcept/rstool";
|
|
4
|
+
//#region src/tools.ts
|
|
5
|
+
const sessionId = {
|
|
6
|
+
type: "string",
|
|
7
|
+
description: "Session identifier returned from create_session or import_session."
|
|
8
|
+
};
|
|
9
|
+
const TOOL_DEFINITIONS = [
|
|
10
|
+
{
|
|
11
|
+
name: "ping",
|
|
12
|
+
description: "Liveness check; returns {pong: true} and the active rstool contract version.",
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {},
|
|
16
|
+
additionalProperties: false
|
|
17
|
+
},
|
|
18
|
+
invoke: (tool) => ({
|
|
19
|
+
pong: true,
|
|
20
|
+
contractVersion: tool.contractVersion
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "list_methods",
|
|
25
|
+
description: "List all rstool methods exposed as MCP tools.",
|
|
26
|
+
inputSchema: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {},
|
|
29
|
+
additionalProperties: false
|
|
30
|
+
},
|
|
31
|
+
invoke: () => TOOL_DEFINITIONS.map((definition) => definition.name)
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "create_session",
|
|
35
|
+
description: "Create a fresh in-memory rstool session. Returns a SessionHandle with sessionId and initial revision.",
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: { initial: {
|
|
39
|
+
type: "object",
|
|
40
|
+
description: "Optional partial SessionState seed (alias, title, constituents, etc.).",
|
|
41
|
+
additionalProperties: true
|
|
42
|
+
} },
|
|
43
|
+
additionalProperties: false
|
|
44
|
+
},
|
|
45
|
+
invoke: (tool, args) => tool.createSession(args.initial)
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "add_or_update_constituenta",
|
|
49
|
+
description: "Upsert a single constituent in the session. Provide alias, cstType, definitionFormal (may be \"\"), and optional term/definitionText/convention.",
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {
|
|
53
|
+
sessionId,
|
|
54
|
+
input: {
|
|
55
|
+
type: "object",
|
|
56
|
+
description: "AddOrUpdateConstituentaInput. Required keys: alias, cstType, definitionFormal.",
|
|
57
|
+
additionalProperties: true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
required: ["sessionId", "input"]
|
|
61
|
+
},
|
|
62
|
+
invoke: (tool, args) => tool.addOrUpdateConstituenta(String(args.sessionId), args.input)
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "analyze_expression",
|
|
66
|
+
description: "Run parser + semantic analysis on a scratch RSLang expression in the session context. Returns typification, valueClass, success flag and diagnostics.",
|
|
67
|
+
inputSchema: {
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: {
|
|
70
|
+
sessionId,
|
|
71
|
+
input: {
|
|
72
|
+
type: "object",
|
|
73
|
+
description: "AnalyzeExpressionInput. Required keys: expression, cstType.",
|
|
74
|
+
properties: {
|
|
75
|
+
expression: { type: "string" },
|
|
76
|
+
cstType: { type: "string" },
|
|
77
|
+
alias: { type: "string" }
|
|
78
|
+
},
|
|
79
|
+
required: ["expression", "cstType"],
|
|
80
|
+
additionalProperties: true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
required: ["sessionId", "input"]
|
|
84
|
+
},
|
|
85
|
+
invoke: (tool, args) => tool.analyzeExpression(String(args.sessionId), args.input)
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "get_form_state",
|
|
89
|
+
description: "Return the full SessionState (constituents, revision, alias, title, etc.).",
|
|
90
|
+
inputSchema: {
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: { sessionId },
|
|
93
|
+
required: ["sessionId"]
|
|
94
|
+
},
|
|
95
|
+
invoke: (tool, args) => tool.getFormState(String(args.sessionId))
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "list_diagnostics",
|
|
99
|
+
description: "List diagnostics across the session, optionally filtered by constituentId / severity / classes.",
|
|
100
|
+
inputSchema: {
|
|
101
|
+
type: "object",
|
|
102
|
+
properties: {
|
|
103
|
+
sessionId,
|
|
104
|
+
filters: {
|
|
105
|
+
type: "object",
|
|
106
|
+
description: "Optional ListDiagnosticsFilters object.",
|
|
107
|
+
additionalProperties: true
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
required: ["sessionId"]
|
|
111
|
+
},
|
|
112
|
+
invoke: (tool, args) => tool.listDiagnostics(String(args.sessionId), args.filters)
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "commit_step",
|
|
116
|
+
description: "Record a session revision with an optional human-readable message.",
|
|
117
|
+
inputSchema: {
|
|
118
|
+
type: "object",
|
|
119
|
+
properties: {
|
|
120
|
+
sessionId,
|
|
121
|
+
message: { type: "string" }
|
|
122
|
+
},
|
|
123
|
+
required: ["sessionId"]
|
|
124
|
+
},
|
|
125
|
+
invoke: (tool, args) => tool.commitStep(String(args.sessionId), args.message)
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "export_session",
|
|
129
|
+
description: "Serialize the session to a JSON string suitable for import_session.",
|
|
130
|
+
inputSchema: {
|
|
131
|
+
type: "object",
|
|
132
|
+
properties: { sessionId },
|
|
133
|
+
required: ["sessionId"]
|
|
134
|
+
},
|
|
135
|
+
invoke: (tool, args) => tool.exportSession(String(args.sessionId))
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "import_session",
|
|
139
|
+
description: "Import a session previously produced by export_session. Returns a fresh SessionHandle pointing at the restored state.",
|
|
140
|
+
inputSchema: {
|
|
141
|
+
type: "object",
|
|
142
|
+
properties: { payload: {
|
|
143
|
+
type: "string",
|
|
144
|
+
description: "JSON payload from export_session."
|
|
145
|
+
} },
|
|
146
|
+
required: ["payload"]
|
|
147
|
+
},
|
|
148
|
+
invoke: (tool, args) => tool.importSession(String(args.payload))
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "set_constituenta_value",
|
|
152
|
+
description: "Bind or assign a value to a single interpretable constituent (basic, constant, structure). Inferrable constituents (term, axiom, statement) cannot be set directly.",
|
|
153
|
+
inputSchema: {
|
|
154
|
+
type: "object",
|
|
155
|
+
properties: {
|
|
156
|
+
sessionId,
|
|
157
|
+
input: {
|
|
158
|
+
type: "object",
|
|
159
|
+
description: "SetConstituentaValueInput. Required keys: target (id), value.",
|
|
160
|
+
additionalProperties: true
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
required: ["sessionId", "input"]
|
|
164
|
+
},
|
|
165
|
+
invoke: (tool, args) => tool.setConstituentaValue(String(args.sessionId), args.input)
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "set_constituenta_values",
|
|
169
|
+
description: "Batch variant of set_constituenta_value: assign values to multiple interpretable constituents.",
|
|
170
|
+
inputSchema: {
|
|
171
|
+
type: "object",
|
|
172
|
+
properties: {
|
|
173
|
+
sessionId,
|
|
174
|
+
input: {
|
|
175
|
+
type: "object",
|
|
176
|
+
description: "SetConstituentaValuesInput. Required keys: values (list of {target, value}).",
|
|
177
|
+
additionalProperties: true
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
required: ["sessionId", "input"]
|
|
181
|
+
},
|
|
182
|
+
invoke: (tool, args) => tool.setConstituentaValues(String(args.sessionId), args.input)
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: "clear_constituenta_values",
|
|
186
|
+
description: "Clear current values for one or more constituents and reset dependents to NOT_PROCESSED.",
|
|
187
|
+
inputSchema: {
|
|
188
|
+
type: "object",
|
|
189
|
+
properties: {
|
|
190
|
+
sessionId,
|
|
191
|
+
input: {
|
|
192
|
+
type: "object",
|
|
193
|
+
description: "ClearConstituentaValuesInput. Required keys: targets (list of ids).",
|
|
194
|
+
additionalProperties: true
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
required: ["sessionId", "input"]
|
|
198
|
+
},
|
|
199
|
+
invoke: (tool, args) => tool.clearConstituentaValues(String(args.sessionId), args.input)
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "get_model_state",
|
|
203
|
+
description: "Return the SessionModelState — current values and evaluation statuses for every constituent.",
|
|
204
|
+
inputSchema: {
|
|
205
|
+
type: "object",
|
|
206
|
+
properties: { sessionId },
|
|
207
|
+
required: ["sessionId"]
|
|
208
|
+
},
|
|
209
|
+
invoke: (tool, args) => tool.getModelState(String(args.sessionId))
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "evaluate_expression",
|
|
213
|
+
description: "Evaluate a scratch RSLang expression against the current bindings without storing it. Returns value + evaluation status.",
|
|
214
|
+
inputSchema: {
|
|
215
|
+
type: "object",
|
|
216
|
+
properties: {
|
|
217
|
+
sessionId,
|
|
218
|
+
input: {
|
|
219
|
+
type: "object",
|
|
220
|
+
description: "EvaluateExpressionInput. Required keys: expression. Optional: cstType, alias.",
|
|
221
|
+
properties: {
|
|
222
|
+
expression: { type: "string" },
|
|
223
|
+
cstType: { type: "string" },
|
|
224
|
+
alias: { type: "string" }
|
|
225
|
+
},
|
|
226
|
+
required: ["expression"],
|
|
227
|
+
additionalProperties: true
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
required: ["sessionId", "input"]
|
|
231
|
+
},
|
|
232
|
+
invoke: (tool, args) => tool.evaluateExpression(String(args.sessionId), args.input)
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: "evaluate_constituenta",
|
|
236
|
+
description: "Evaluate a stored derived constituent (term, axiom, statement) using the current bindings.",
|
|
237
|
+
inputSchema: {
|
|
238
|
+
type: "object",
|
|
239
|
+
properties: {
|
|
240
|
+
sessionId,
|
|
241
|
+
input: {
|
|
242
|
+
type: "object",
|
|
243
|
+
description: "EvaluateConstituentaInput. Required keys: target (id).",
|
|
244
|
+
additionalProperties: true
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
required: ["sessionId", "input"]
|
|
248
|
+
},
|
|
249
|
+
invoke: (tool, args) => tool.evaluateConstituenta(String(args.sessionId), args.input)
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "recalculate_model",
|
|
253
|
+
description: "Recompute every interpretable / inferrable constituent using current bindings. Returns the updated SessionModelState.",
|
|
254
|
+
inputSchema: {
|
|
255
|
+
type: "object",
|
|
256
|
+
properties: { sessionId },
|
|
257
|
+
required: ["sessionId"]
|
|
258
|
+
},
|
|
259
|
+
invoke: (tool, args) => tool.recalculateModel(String(args.sessionId))
|
|
260
|
+
}
|
|
261
|
+
];
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/server.ts
|
|
264
|
+
/**
|
|
265
|
+
* Build an MCP `McpServer` instance that exposes the `@rsconcept/rstool` contract.
|
|
266
|
+
*
|
|
267
|
+
* The returned server is not yet connected to a transport. Wrap it with a
|
|
268
|
+
* `StdioServerTransport` (for local subprocess hosts like Cursor and Claude Desktop) or
|
|
269
|
+
* an HTTP transport, then call `server.connect(transport)`.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```ts
|
|
273
|
+
* import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
274
|
+
* import { buildRSToolMcpServer } from '@rsconcept/rstool-mcp';
|
|
275
|
+
*
|
|
276
|
+
* const server = buildRSToolMcpServer();
|
|
277
|
+
* await server.connect(new StdioServerTransport());
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
function buildRSToolMcpServer(options = {}) {
|
|
281
|
+
const tool = options.tool ?? new RSToolAgent();
|
|
282
|
+
const server = new McpServer({
|
|
283
|
+
name: options.name ?? "rstool-mcp",
|
|
284
|
+
version: options.version ?? "0.1.0"
|
|
285
|
+
}, { capabilities: { tools: {} } });
|
|
286
|
+
const definitionByName = new Map(TOOL_DEFINITIONS.map((definition) => [definition.name, definition]));
|
|
287
|
+
server.server.setRequestHandler(ListToolsRequestSchema, () => Promise.resolve({ tools: TOOL_DEFINITIONS.map((definition) => ({
|
|
288
|
+
name: definition.name,
|
|
289
|
+
description: definition.description,
|
|
290
|
+
inputSchema: definition.inputSchema
|
|
291
|
+
})) }));
|
|
292
|
+
server.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
293
|
+
const definition = definitionByName.get(request.params.name);
|
|
294
|
+
if (!definition) return {
|
|
295
|
+
isError: true,
|
|
296
|
+
content: [{
|
|
297
|
+
type: "text",
|
|
298
|
+
text: `Unknown rstool tool: ${request.params.name}`
|
|
299
|
+
}]
|
|
300
|
+
};
|
|
301
|
+
try {
|
|
302
|
+
const result = await definition.invoke(tool, request.params.arguments ?? {});
|
|
303
|
+
return { content: [{
|
|
304
|
+
type: "text",
|
|
305
|
+
text: typeof result === "string" ? result : JSON.stringify(result, null, 2)
|
|
306
|
+
}] };
|
|
307
|
+
} catch (error) {
|
|
308
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
309
|
+
return {
|
|
310
|
+
isError: true,
|
|
311
|
+
content: [{
|
|
312
|
+
type: "text",
|
|
313
|
+
text: `rstool error in ${definition.name}: ${message}`
|
|
314
|
+
}]
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
return server;
|
|
319
|
+
}
|
|
320
|
+
//#endregion
|
|
321
|
+
export { TOOL_DEFINITIONS as n, buildRSToolMcpServer as t };
|
|
322
|
+
|
|
323
|
+
//# sourceMappingURL=server-CzaNBfgR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-CzaNBfgR.js","names":[],"sources":["../src/tools.ts","../src/server.ts"],"sourcesContent":["/**\n * MCP tool definitions for the @rsconcept/rstool contract.\n *\n * Schemas are intentionally permissive (additionalProperties: true) where the rstool input\n * is structurally rich (e.g. ConstituentaDraft, SessionState). The wrapped RSToolAgent\n * validates inputs at runtime and returns deterministic error responses.\n */\n\nimport { type RSToolAgent } from '@rsconcept/rstool';\n\nexport interface ToolDefinition {\n name: string;\n description: string;\n inputSchema: {\n type: 'object';\n properties: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n };\n invoke: (tool: RSToolAgent, args: Record<string, unknown>) => unknown | Promise<unknown>;\n}\n\nconst sessionId = {\n type: 'string',\n description: 'Session identifier returned from create_session or import_session.'\n};\n\nexport const TOOL_DEFINITIONS: ToolDefinition[] = [\n {\n name: 'ping',\n description: 'Liveness check; returns {pong: true} and the active rstool contract version.',\n inputSchema: { type: 'object', properties: {}, additionalProperties: false },\n invoke: tool => ({ pong: true, contractVersion: tool.contractVersion })\n },\n {\n name: 'list_methods',\n description: 'List all rstool methods exposed as MCP tools.',\n inputSchema: { type: 'object', properties: {}, additionalProperties: false },\n invoke: () => TOOL_DEFINITIONS.map(definition => definition.name)\n },\n {\n name: 'create_session',\n description:\n 'Create a fresh in-memory rstool session. Returns a SessionHandle with sessionId and initial revision.',\n inputSchema: {\n type: 'object',\n properties: {\n initial: {\n type: 'object',\n description: 'Optional partial SessionState seed (alias, title, constituents, etc.).',\n additionalProperties: true\n }\n },\n additionalProperties: false\n },\n invoke: (tool, args) => tool.createSession(args.initial as never)\n },\n {\n name: 'add_or_update_constituenta',\n description:\n 'Upsert a single constituent in the session. Provide alias, cstType, definitionFormal (may be \"\"), and optional term/definitionText/convention.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n input: {\n type: 'object',\n description: 'AddOrUpdateConstituentaInput. Required keys: alias, cstType, definitionFormal.',\n additionalProperties: true\n }\n },\n required: ['sessionId', 'input']\n },\n invoke: (tool, args) =>\n tool.addOrUpdateConstituenta(String(args.sessionId), args.input as never)\n },\n {\n name: 'analyze_expression',\n description:\n 'Run parser + semantic analysis on a scratch RSLang expression in the session context. Returns typification, valueClass, success flag and diagnostics.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n input: {\n type: 'object',\n description: 'AnalyzeExpressionInput. Required keys: expression, cstType.',\n properties: {\n expression: { type: 'string' },\n cstType: { type: 'string' },\n alias: { type: 'string' }\n },\n required: ['expression', 'cstType'],\n additionalProperties: true\n }\n },\n required: ['sessionId', 'input']\n },\n invoke: (tool, args) =>\n tool.analyzeExpression(String(args.sessionId), args.input as never)\n },\n {\n name: 'get_form_state',\n description: 'Return the full SessionState (constituents, revision, alias, title, etc.).',\n inputSchema: {\n type: 'object',\n properties: { sessionId },\n required: ['sessionId']\n },\n invoke: (tool, args) => tool.getFormState(String(args.sessionId))\n },\n {\n name: 'list_diagnostics',\n description:\n 'List diagnostics across the session, optionally filtered by constituentId / severity / classes.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n filters: {\n type: 'object',\n description: 'Optional ListDiagnosticsFilters object.',\n additionalProperties: true\n }\n },\n required: ['sessionId']\n },\n invoke: (tool, args) =>\n tool.listDiagnostics(String(args.sessionId), args.filters as never)\n },\n {\n name: 'commit_step',\n description: 'Record a session revision with an optional human-readable message.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n message: { type: 'string' }\n },\n required: ['sessionId']\n },\n invoke: (tool, args) =>\n tool.commitStep(String(args.sessionId), args.message as string | undefined)\n },\n {\n name: 'export_session',\n description: 'Serialize the session to a JSON string suitable for import_session.',\n inputSchema: {\n type: 'object',\n properties: { sessionId },\n required: ['sessionId']\n },\n invoke: (tool, args) => tool.exportSession(String(args.sessionId))\n },\n {\n name: 'import_session',\n description:\n 'Import a session previously produced by export_session. Returns a fresh SessionHandle pointing at the restored state.',\n inputSchema: {\n type: 'object',\n properties: {\n payload: { type: 'string', description: 'JSON payload from export_session.' }\n },\n required: ['payload']\n },\n invoke: (tool, args) => tool.importSession(String(args.payload))\n },\n {\n name: 'set_constituenta_value',\n description:\n 'Bind or assign a value to a single interpretable constituent (basic, constant, structure). Inferrable constituents (term, axiom, statement) cannot be set directly.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n input: {\n type: 'object',\n description: 'SetConstituentaValueInput. Required keys: target (id), value.',\n additionalProperties: true\n }\n },\n required: ['sessionId', 'input']\n },\n invoke: (tool, args) =>\n tool.setConstituentaValue(String(args.sessionId), args.input as never)\n },\n {\n name: 'set_constituenta_values',\n description: 'Batch variant of set_constituenta_value: assign values to multiple interpretable constituents.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n input: {\n type: 'object',\n description: 'SetConstituentaValuesInput. Required keys: values (list of {target, value}).',\n additionalProperties: true\n }\n },\n required: ['sessionId', 'input']\n },\n invoke: (tool, args) =>\n tool.setConstituentaValues(String(args.sessionId), args.input as never)\n },\n {\n name: 'clear_constituenta_values',\n description: 'Clear current values for one or more constituents and reset dependents to NOT_PROCESSED.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n input: {\n type: 'object',\n description: 'ClearConstituentaValuesInput. Required keys: targets (list of ids).',\n additionalProperties: true\n }\n },\n required: ['sessionId', 'input']\n },\n invoke: (tool, args) =>\n tool.clearConstituentaValues(String(args.sessionId), args.input as never)\n },\n {\n name: 'get_model_state',\n description: 'Return the SessionModelState — current values and evaluation statuses for every constituent.',\n inputSchema: {\n type: 'object',\n properties: { sessionId },\n required: ['sessionId']\n },\n invoke: (tool, args) => tool.getModelState(String(args.sessionId))\n },\n {\n name: 'evaluate_expression',\n description:\n 'Evaluate a scratch RSLang expression against the current bindings without storing it. Returns value + evaluation status.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n input: {\n type: 'object',\n description: 'EvaluateExpressionInput. Required keys: expression. Optional: cstType, alias.',\n properties: {\n expression: { type: 'string' },\n cstType: { type: 'string' },\n alias: { type: 'string' }\n },\n required: ['expression'],\n additionalProperties: true\n }\n },\n required: ['sessionId', 'input']\n },\n invoke: (tool, args) =>\n tool.evaluateExpression(String(args.sessionId), args.input as never)\n },\n {\n name: 'evaluate_constituenta',\n description: 'Evaluate a stored derived constituent (term, axiom, statement) using the current bindings.',\n inputSchema: {\n type: 'object',\n properties: {\n sessionId,\n input: {\n type: 'object',\n description: 'EvaluateConstituentaInput. Required keys: target (id).',\n additionalProperties: true\n }\n },\n required: ['sessionId', 'input']\n },\n invoke: (tool, args) =>\n tool.evaluateConstituenta(String(args.sessionId), args.input as never)\n },\n {\n name: 'recalculate_model',\n description: 'Recompute every interpretable / inferrable constituent using current bindings. Returns the updated SessionModelState.',\n inputSchema: {\n type: 'object',\n properties: { sessionId },\n required: ['sessionId']\n },\n invoke: (tool, args) => tool.recalculateModel(String(args.sessionId))\n }\n];\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema\n} from '@modelcontextprotocol/sdk/types.js';\n\nimport { RSToolAgent } from '@rsconcept/rstool';\n\nimport { TOOL_DEFINITIONS, type ToolDefinition } from './tools';\n\nexport interface BuildRSToolMcpServerOptions {\n /** Pre-built RSToolAgent. Defaults to a fresh in-memory instance. */\n tool?: RSToolAgent;\n /** Server name advertised to MCP clients. */\n name?: string;\n /** Server version advertised to MCP clients. */\n version?: string;\n}\n\n/**\n * Build an MCP `McpServer` instance that exposes the `@rsconcept/rstool` contract.\n *\n * The returned server is not yet connected to a transport. Wrap it with a\n * `StdioServerTransport` (for local subprocess hosts like Cursor and Claude Desktop) or\n * an HTTP transport, then call `server.connect(transport)`.\n *\n * @example\n * ```ts\n * import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\n * import { buildRSToolMcpServer } from '@rsconcept/rstool-mcp';\n *\n * const server = buildRSToolMcpServer();\n * await server.connect(new StdioServerTransport());\n * ```\n */\nexport function buildRSToolMcpServer(options: BuildRSToolMcpServerOptions = {}): McpServer {\n const tool = options.tool ?? new RSToolAgent();\n const server = new McpServer(\n {\n name: options.name ?? 'rstool-mcp',\n version: options.version ?? '0.1.0'\n },\n {\n capabilities: {\n tools: {}\n }\n }\n );\n\n const definitionByName = new Map<string, ToolDefinition>(\n TOOL_DEFINITIONS.map(definition => [definition.name, definition])\n );\n\n server.server.setRequestHandler(ListToolsRequestSchema, () =>\n Promise.resolve({\n tools: TOOL_DEFINITIONS.map(definition => ({\n name: definition.name,\n description: definition.description,\n inputSchema: definition.inputSchema\n }))\n })\n );\n\n server.server.setRequestHandler(CallToolRequestSchema, async request => {\n const definition = definitionByName.get(request.params.name);\n if (!definition) {\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: `Unknown rstool tool: ${request.params.name}`\n }\n ]\n };\n }\n\n try {\n const result = await definition.invoke(tool, request.params.arguments ?? {});\n const text =\n typeof result === 'string' ? result : JSON.stringify(result, null, 2);\n return {\n content: [\n {\n type: 'text' as const,\n text\n }\n ]\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n isError: true,\n content: [\n {\n type: 'text' as const,\n text: `rstool error in ${definition.name}: ${message}`\n }\n ]\n };\n }\n });\n\n return server;\n}\n"],"mappings":";;;;AAsBA,MAAM,YAAY;CAChB,MAAM;CACN,aAAa;AACf;AAEA,MAAa,mBAAqC;CAChD;EACE,MAAM;EACN,aAAa;EACb,aAAa;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Protocol (MCP) adapter that exposes the @rsconcept/rstool RSToolAgent contract over MCP stdio. Works with Cursor, Claude Desktop, and any MCP-capable host.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "IRBorisov",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/IRBorisov/ConceptPortal.git",
|
|
10
|
+
"directory": "rsconcept/rstool-mcp"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://portal.acconcept.ru",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"rslang",
|
|
15
|
+
"rsform",
|
|
16
|
+
"rstool",
|
|
17
|
+
"mcp",
|
|
18
|
+
"model-context-protocol",
|
|
19
|
+
"agent",
|
|
20
|
+
"llm",
|
|
21
|
+
"cursor",
|
|
22
|
+
"claude"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"rstool-mcp": "dist/bin/server.js"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"src",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsdown",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"start": "tsx src/bin/server.ts",
|
|
48
|
+
"prepublishOnly": "npm run build"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@modelcontextprotocol/sdk": "^1.21.1",
|
|
52
|
+
"@rsconcept/rstool": "^0.4.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^25.9.1",
|
|
56
|
+
"tsdown": "^0.22.0",
|
|
57
|
+
"tsx": "^4.21.0",
|
|
58
|
+
"typescript": "^6.0.3",
|
|
59
|
+
"vitest": "^4.1.5"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
|
|
4
|
+
import { buildRSToolMcpServer } from '../server';
|
|
5
|
+
|
|
6
|
+
async function main(): Promise<void> {
|
|
7
|
+
const server = buildRSToolMcpServer();
|
|
8
|
+
const transport = new StdioServerTransport();
|
|
9
|
+
await server.connect(transport);
|
|
10
|
+
process.stderr.write('rstool-mcp server ready on stdio\n');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
main().catch(error => {
|
|
14
|
+
process.stderr.write(`rstool-mcp fatal: ${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { buildRSToolMcpServer } from './server';
|
|
4
|
+
import { TOOL_DEFINITIONS } from './tools';
|
|
5
|
+
|
|
6
|
+
describe('buildRSToolMcpServer', () => {
|
|
7
|
+
it('exposes the full rstool contract as MCP tools', () => {
|
|
8
|
+
const server = buildRSToolMcpServer();
|
|
9
|
+
expect(server).toBeDefined();
|
|
10
|
+
expect(TOOL_DEFINITIONS.map(t => t.name)).toEqual([
|
|
11
|
+
'ping',
|
|
12
|
+
'list_methods',
|
|
13
|
+
'create_session',
|
|
14
|
+
'add_or_update_constituenta',
|
|
15
|
+
'analyze_expression',
|
|
16
|
+
'get_form_state',
|
|
17
|
+
'list_diagnostics',
|
|
18
|
+
'commit_step',
|
|
19
|
+
'export_session',
|
|
20
|
+
'import_session',
|
|
21
|
+
'set_constituenta_value',
|
|
22
|
+
'set_constituenta_values',
|
|
23
|
+
'clear_constituenta_values',
|
|
24
|
+
'get_model_state',
|
|
25
|
+
'evaluate_expression',
|
|
26
|
+
'evaluate_constituenta',
|
|
27
|
+
'recalculate_model'
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('each tool has a permissive but well-formed input schema', () => {
|
|
32
|
+
for (const definition of TOOL_DEFINITIONS) {
|
|
33
|
+
expect(definition.inputSchema.type).toBe('object');
|
|
34
|
+
expect(typeof definition.description).toBe('string');
|
|
35
|
+
expect(definition.description.length).toBeGreaterThan(0);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import {
|
|
3
|
+
CallToolRequestSchema,
|
|
4
|
+
ListToolsRequestSchema
|
|
5
|
+
} from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
|
|
7
|
+
import { RSToolAgent } from '@rsconcept/rstool';
|
|
8
|
+
|
|
9
|
+
import { TOOL_DEFINITIONS, type ToolDefinition } from './tools';
|
|
10
|
+
|
|
11
|
+
export interface BuildRSToolMcpServerOptions {
|
|
12
|
+
/** Pre-built RSToolAgent. Defaults to a fresh in-memory instance. */
|
|
13
|
+
tool?: RSToolAgent;
|
|
14
|
+
/** Server name advertised to MCP clients. */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** Server version advertised to MCP clients. */
|
|
17
|
+
version?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build an MCP `McpServer` instance that exposes the `@rsconcept/rstool` contract.
|
|
22
|
+
*
|
|
23
|
+
* The returned server is not yet connected to a transport. Wrap it with a
|
|
24
|
+
* `StdioServerTransport` (for local subprocess hosts like Cursor and Claude Desktop) or
|
|
25
|
+
* an HTTP transport, then call `server.connect(transport)`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
30
|
+
* import { buildRSToolMcpServer } from '@rsconcept/rstool-mcp';
|
|
31
|
+
*
|
|
32
|
+
* const server = buildRSToolMcpServer();
|
|
33
|
+
* await server.connect(new StdioServerTransport());
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function buildRSToolMcpServer(options: BuildRSToolMcpServerOptions = {}): McpServer {
|
|
37
|
+
const tool = options.tool ?? new RSToolAgent();
|
|
38
|
+
const server = new McpServer(
|
|
39
|
+
{
|
|
40
|
+
name: options.name ?? 'rstool-mcp',
|
|
41
|
+
version: options.version ?? '0.1.0'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
capabilities: {
|
|
45
|
+
tools: {}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const definitionByName = new Map<string, ToolDefinition>(
|
|
51
|
+
TOOL_DEFINITIONS.map(definition => [definition.name, definition])
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
server.server.setRequestHandler(ListToolsRequestSchema, () =>
|
|
55
|
+
Promise.resolve({
|
|
56
|
+
tools: TOOL_DEFINITIONS.map(definition => ({
|
|
57
|
+
name: definition.name,
|
|
58
|
+
description: definition.description,
|
|
59
|
+
inputSchema: definition.inputSchema
|
|
60
|
+
}))
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
server.server.setRequestHandler(CallToolRequestSchema, async request => {
|
|
65
|
+
const definition = definitionByName.get(request.params.name);
|
|
66
|
+
if (!definition) {
|
|
67
|
+
return {
|
|
68
|
+
isError: true,
|
|
69
|
+
content: [
|
|
70
|
+
{
|
|
71
|
+
type: 'text' as const,
|
|
72
|
+
text: `Unknown rstool tool: ${request.params.name}`
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const result = await definition.invoke(tool, request.params.arguments ?? {});
|
|
80
|
+
const text =
|
|
81
|
+
typeof result === 'string' ? result : JSON.stringify(result, null, 2);
|
|
82
|
+
return {
|
|
83
|
+
content: [
|
|
84
|
+
{
|
|
85
|
+
type: 'text' as const,
|
|
86
|
+
text
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
92
|
+
return {
|
|
93
|
+
isError: true,
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: 'text' as const,
|
|
97
|
+
text: `rstool error in ${definition.name}: ${message}`
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return server;
|
|
105
|
+
}
|
package/src/tools.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool definitions for the @rsconcept/rstool contract.
|
|
3
|
+
*
|
|
4
|
+
* Schemas are intentionally permissive (additionalProperties: true) where the rstool input
|
|
5
|
+
* is structurally rich (e.g. ConstituentaDraft, SessionState). The wrapped RSToolAgent
|
|
6
|
+
* validates inputs at runtime and returns deterministic error responses.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { type RSToolAgent } from '@rsconcept/rstool';
|
|
10
|
+
|
|
11
|
+
export interface ToolDefinition {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
inputSchema: {
|
|
15
|
+
type: 'object';
|
|
16
|
+
properties: Record<string, unknown>;
|
|
17
|
+
required?: string[];
|
|
18
|
+
additionalProperties?: boolean;
|
|
19
|
+
};
|
|
20
|
+
invoke: (tool: RSToolAgent, args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const sessionId = {
|
|
24
|
+
type: 'string',
|
|
25
|
+
description: 'Session identifier returned from create_session or import_session.'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const TOOL_DEFINITIONS: ToolDefinition[] = [
|
|
29
|
+
{
|
|
30
|
+
name: 'ping',
|
|
31
|
+
description: 'Liveness check; returns {pong: true} and the active rstool contract version.',
|
|
32
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
33
|
+
invoke: tool => ({ pong: true, contractVersion: tool.contractVersion })
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'list_methods',
|
|
37
|
+
description: 'List all rstool methods exposed as MCP tools.',
|
|
38
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
39
|
+
invoke: () => TOOL_DEFINITIONS.map(definition => definition.name)
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'create_session',
|
|
43
|
+
description:
|
|
44
|
+
'Create a fresh in-memory rstool session. Returns a SessionHandle with sessionId and initial revision.',
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
initial: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
description: 'Optional partial SessionState seed (alias, title, constituents, etc.).',
|
|
51
|
+
additionalProperties: true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
additionalProperties: false
|
|
55
|
+
},
|
|
56
|
+
invoke: (tool, args) => tool.createSession(args.initial as never)
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'add_or_update_constituenta',
|
|
60
|
+
description:
|
|
61
|
+
'Upsert a single constituent in the session. Provide alias, cstType, definitionFormal (may be ""), and optional term/definitionText/convention.',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
sessionId,
|
|
66
|
+
input: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
description: 'AddOrUpdateConstituentaInput. Required keys: alias, cstType, definitionFormal.',
|
|
69
|
+
additionalProperties: true
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
required: ['sessionId', 'input']
|
|
73
|
+
},
|
|
74
|
+
invoke: (tool, args) =>
|
|
75
|
+
tool.addOrUpdateConstituenta(String(args.sessionId), args.input as never)
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'analyze_expression',
|
|
79
|
+
description:
|
|
80
|
+
'Run parser + semantic analysis on a scratch RSLang expression in the session context. Returns typification, valueClass, success flag and diagnostics.',
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
sessionId,
|
|
85
|
+
input: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
description: 'AnalyzeExpressionInput. Required keys: expression, cstType.',
|
|
88
|
+
properties: {
|
|
89
|
+
expression: { type: 'string' },
|
|
90
|
+
cstType: { type: 'string' },
|
|
91
|
+
alias: { type: 'string' }
|
|
92
|
+
},
|
|
93
|
+
required: ['expression', 'cstType'],
|
|
94
|
+
additionalProperties: true
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
required: ['sessionId', 'input']
|
|
98
|
+
},
|
|
99
|
+
invoke: (tool, args) =>
|
|
100
|
+
tool.analyzeExpression(String(args.sessionId), args.input as never)
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'get_form_state',
|
|
104
|
+
description: 'Return the full SessionState (constituents, revision, alias, title, etc.).',
|
|
105
|
+
inputSchema: {
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: { sessionId },
|
|
108
|
+
required: ['sessionId']
|
|
109
|
+
},
|
|
110
|
+
invoke: (tool, args) => tool.getFormState(String(args.sessionId))
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'list_diagnostics',
|
|
114
|
+
description:
|
|
115
|
+
'List diagnostics across the session, optionally filtered by constituentId / severity / classes.',
|
|
116
|
+
inputSchema: {
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: {
|
|
119
|
+
sessionId,
|
|
120
|
+
filters: {
|
|
121
|
+
type: 'object',
|
|
122
|
+
description: 'Optional ListDiagnosticsFilters object.',
|
|
123
|
+
additionalProperties: true
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
required: ['sessionId']
|
|
127
|
+
},
|
|
128
|
+
invoke: (tool, args) =>
|
|
129
|
+
tool.listDiagnostics(String(args.sessionId), args.filters as never)
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: 'commit_step',
|
|
133
|
+
description: 'Record a session revision with an optional human-readable message.',
|
|
134
|
+
inputSchema: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: {
|
|
137
|
+
sessionId,
|
|
138
|
+
message: { type: 'string' }
|
|
139
|
+
},
|
|
140
|
+
required: ['sessionId']
|
|
141
|
+
},
|
|
142
|
+
invoke: (tool, args) =>
|
|
143
|
+
tool.commitStep(String(args.sessionId), args.message as string | undefined)
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'export_session',
|
|
147
|
+
description: 'Serialize the session to a JSON string suitable for import_session.',
|
|
148
|
+
inputSchema: {
|
|
149
|
+
type: 'object',
|
|
150
|
+
properties: { sessionId },
|
|
151
|
+
required: ['sessionId']
|
|
152
|
+
},
|
|
153
|
+
invoke: (tool, args) => tool.exportSession(String(args.sessionId))
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'import_session',
|
|
157
|
+
description:
|
|
158
|
+
'Import a session previously produced by export_session. Returns a fresh SessionHandle pointing at the restored state.',
|
|
159
|
+
inputSchema: {
|
|
160
|
+
type: 'object',
|
|
161
|
+
properties: {
|
|
162
|
+
payload: { type: 'string', description: 'JSON payload from export_session.' }
|
|
163
|
+
},
|
|
164
|
+
required: ['payload']
|
|
165
|
+
},
|
|
166
|
+
invoke: (tool, args) => tool.importSession(String(args.payload))
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: 'set_constituenta_value',
|
|
170
|
+
description:
|
|
171
|
+
'Bind or assign a value to a single interpretable constituent (basic, constant, structure). Inferrable constituents (term, axiom, statement) cannot be set directly.',
|
|
172
|
+
inputSchema: {
|
|
173
|
+
type: 'object',
|
|
174
|
+
properties: {
|
|
175
|
+
sessionId,
|
|
176
|
+
input: {
|
|
177
|
+
type: 'object',
|
|
178
|
+
description: 'SetConstituentaValueInput. Required keys: target (id), value.',
|
|
179
|
+
additionalProperties: true
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
required: ['sessionId', 'input']
|
|
183
|
+
},
|
|
184
|
+
invoke: (tool, args) =>
|
|
185
|
+
tool.setConstituentaValue(String(args.sessionId), args.input as never)
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: 'set_constituenta_values',
|
|
189
|
+
description: 'Batch variant of set_constituenta_value: assign values to multiple interpretable constituents.',
|
|
190
|
+
inputSchema: {
|
|
191
|
+
type: 'object',
|
|
192
|
+
properties: {
|
|
193
|
+
sessionId,
|
|
194
|
+
input: {
|
|
195
|
+
type: 'object',
|
|
196
|
+
description: 'SetConstituentaValuesInput. Required keys: values (list of {target, value}).',
|
|
197
|
+
additionalProperties: true
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
required: ['sessionId', 'input']
|
|
201
|
+
},
|
|
202
|
+
invoke: (tool, args) =>
|
|
203
|
+
tool.setConstituentaValues(String(args.sessionId), args.input as never)
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: 'clear_constituenta_values',
|
|
207
|
+
description: 'Clear current values for one or more constituents and reset dependents to NOT_PROCESSED.',
|
|
208
|
+
inputSchema: {
|
|
209
|
+
type: 'object',
|
|
210
|
+
properties: {
|
|
211
|
+
sessionId,
|
|
212
|
+
input: {
|
|
213
|
+
type: 'object',
|
|
214
|
+
description: 'ClearConstituentaValuesInput. Required keys: targets (list of ids).',
|
|
215
|
+
additionalProperties: true
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
required: ['sessionId', 'input']
|
|
219
|
+
},
|
|
220
|
+
invoke: (tool, args) =>
|
|
221
|
+
tool.clearConstituentaValues(String(args.sessionId), args.input as never)
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: 'get_model_state',
|
|
225
|
+
description: 'Return the SessionModelState — current values and evaluation statuses for every constituent.',
|
|
226
|
+
inputSchema: {
|
|
227
|
+
type: 'object',
|
|
228
|
+
properties: { sessionId },
|
|
229
|
+
required: ['sessionId']
|
|
230
|
+
},
|
|
231
|
+
invoke: (tool, args) => tool.getModelState(String(args.sessionId))
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
name: 'evaluate_expression',
|
|
235
|
+
description:
|
|
236
|
+
'Evaluate a scratch RSLang expression against the current bindings without storing it. Returns value + evaluation status.',
|
|
237
|
+
inputSchema: {
|
|
238
|
+
type: 'object',
|
|
239
|
+
properties: {
|
|
240
|
+
sessionId,
|
|
241
|
+
input: {
|
|
242
|
+
type: 'object',
|
|
243
|
+
description: 'EvaluateExpressionInput. Required keys: expression. Optional: cstType, alias.',
|
|
244
|
+
properties: {
|
|
245
|
+
expression: { type: 'string' },
|
|
246
|
+
cstType: { type: 'string' },
|
|
247
|
+
alias: { type: 'string' }
|
|
248
|
+
},
|
|
249
|
+
required: ['expression'],
|
|
250
|
+
additionalProperties: true
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
required: ['sessionId', 'input']
|
|
254
|
+
},
|
|
255
|
+
invoke: (tool, args) =>
|
|
256
|
+
tool.evaluateExpression(String(args.sessionId), args.input as never)
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: 'evaluate_constituenta',
|
|
260
|
+
description: 'Evaluate a stored derived constituent (term, axiom, statement) using the current bindings.',
|
|
261
|
+
inputSchema: {
|
|
262
|
+
type: 'object',
|
|
263
|
+
properties: {
|
|
264
|
+
sessionId,
|
|
265
|
+
input: {
|
|
266
|
+
type: 'object',
|
|
267
|
+
description: 'EvaluateConstituentaInput. Required keys: target (id).',
|
|
268
|
+
additionalProperties: true
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
required: ['sessionId', 'input']
|
|
272
|
+
},
|
|
273
|
+
invoke: (tool, args) =>
|
|
274
|
+
tool.evaluateConstituenta(String(args.sessionId), args.input as never)
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
name: 'recalculate_model',
|
|
278
|
+
description: 'Recompute every interpretable / inferrable constituent using current bindings. Returns the updated SessionModelState.',
|
|
279
|
+
inputSchema: {
|
|
280
|
+
type: 'object',
|
|
281
|
+
properties: { sessionId },
|
|
282
|
+
required: ['sessionId']
|
|
283
|
+
},
|
|
284
|
+
invoke: (tool, args) => tool.recalculateModel(String(args.sessionId))
|
|
285
|
+
}
|
|
286
|
+
];
|