@rsconcept/rstool-mcp 0.1.6 → 0.3.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/README.md +37 -27
- package/dist/bin/server.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/server-CM8yRC3G.js +372 -0
- package/dist/server-CM8yRC3G.js.map +1 -0
- package/package.json +2 -2
- package/src/server.test.ts +27 -26
- package/src/server.ts +43 -32
- package/src/tools.ts +228 -164
- package/dist/server-CzaNBfgR.js +0 -323
- package/dist/server-CzaNBfgR.js.map +0 -1
package/dist/server-CzaNBfgR.js
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;GAAE,MAAM;GAAU,YAAY,CAAC;GAAG,sBAAsB;EAAM;EAC3E,SAAQ,UAAS;GAAE,MAAM;GAAM,iBAAiB,KAAK;EAAgB;CACvE;CACA;EACE,MAAM;EACN,aAAa;EACb,aAAa;GAA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