pantheon-opencode 2.1.6 → 2.2.0-beta.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/CHANGELOG.md +37 -0
- package/package.json +7 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/build-plugin.mjs +1 -1
- package/scripts/install-mcp.mjs +55 -27
- package/src/agents/roster.json +562 -0
- package/src/mcp/pantheon-mcp-server.mjs +508 -0
- package/src/plugin/index.js +8577 -140
- package/src/plugin/index.ts +42 -14
- package/src/plugin.ts +52 -1
- package/src/plugins/tui/dist/tui.d.ts +66 -0
- package/src/plugins/tui/dist/tui.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui.js +1193 -365
- package/src/plugins/tui/dist/tui.js.map +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/plugins/tui/src/index.tsx +632 -71
- package/src/plugins/tui/src/pantheon-settings.tsx +64 -13
- package/src/plugins/tui/src/quota-state.ts +128 -0
- package/src/plugins/tui/src/tui-prefs.ts +161 -12
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* pantheon-mcp-server.mjs — 100% Native Node.js MCP server for Pantheon.
|
|
4
|
+
*
|
|
5
|
+
* Replaces Python-based FastMCP servers with native TypeScript/ESM running on Node.js >= 26.
|
|
6
|
+
* Zero Python dependencies, zero .venv required, 100% compatible with Windows Desktop,
|
|
7
|
+
* macOS, and Linux. Speaks MCP JSON-RPC 2.0 over standard I/O.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node src/mcp/pantheon-mcp-server.mjs --server pantheon-resources
|
|
11
|
+
* node src/mcp/pantheon-mcp-server.mjs --server pantheon-memory
|
|
12
|
+
* node src/mcp/pantheon-mcp-server.mjs --server pantheon-persistence
|
|
13
|
+
* node src/mcp/pantheon-mcp-server.mjs --server pantheon-code-mode
|
|
14
|
+
* node src/mcp/pantheon-mcp-server.mjs --server all
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { execFile } from 'node:child_process'
|
|
18
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
19
|
+
import { dirname, join, resolve } from 'node:path'
|
|
20
|
+
import { createInterface } from 'node:readline'
|
|
21
|
+
import { DatabaseSync } from 'node:sqlite'
|
|
22
|
+
import { fileURLToPath } from 'node:url'
|
|
23
|
+
|
|
24
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
25
|
+
const ROOT = resolve(__dirname, '..', '..')
|
|
26
|
+
|
|
27
|
+
// ── Argument Parsing ───────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
const args = process.argv.slice(2)
|
|
30
|
+
let serverType = 'all'
|
|
31
|
+
for (let i = 0; i < args.length; i++) {
|
|
32
|
+
if (args[i] === '--server' && args[i + 1]) {
|
|
33
|
+
serverType = args[i + 1]
|
|
34
|
+
i++
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ── Path Helpers ───────────────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
function getProjectRoot() {
|
|
41
|
+
return process.env.PANTHEON_PROJECT || process.cwd()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ── SQLite Memory Setup ────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
let dbInstance = null
|
|
47
|
+
function getMemoryDb() {
|
|
48
|
+
if (dbInstance) return dbInstance
|
|
49
|
+
const memoryDir = join(getProjectRoot(), '.pantheon', 'memory')
|
|
50
|
+
mkdirSync(memoryDir, { recursive: true })
|
|
51
|
+
const dbPath = join(memoryDir, 'pantheon_memory.db')
|
|
52
|
+
const db = new DatabaseSync(dbPath)
|
|
53
|
+
db.exec(`
|
|
54
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
55
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
56
|
+
namespace TEXT NOT NULL,
|
|
57
|
+
key TEXT NOT NULL,
|
|
58
|
+
value TEXT NOT NULL,
|
|
59
|
+
metadata TEXT,
|
|
60
|
+
created_at TEXT NOT NULL,
|
|
61
|
+
expires_at TEXT,
|
|
62
|
+
UNIQUE(namespace, key)
|
|
63
|
+
);
|
|
64
|
+
CREATE INDEX IF NOT EXISTS idx_memories_ns_key ON memories(namespace, key);
|
|
65
|
+
`)
|
|
66
|
+
dbInstance = db
|
|
67
|
+
return db
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── Tool Definitions ───────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
function getToolsForServer(type) {
|
|
73
|
+
const tools = []
|
|
74
|
+
|
|
75
|
+
if (type === 'all' || type === 'pantheon-memory') {
|
|
76
|
+
tools.push(
|
|
77
|
+
{
|
|
78
|
+
name: 'memory_store',
|
|
79
|
+
description:
|
|
80
|
+
'Store a memory entry with namespace, key, value, and optional metadata string.',
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
namespace: { type: 'string' },
|
|
85
|
+
key: { type: 'string' },
|
|
86
|
+
value: { type: 'string' },
|
|
87
|
+
metadata: { type: 'string' },
|
|
88
|
+
expires_at: { type: 'string' },
|
|
89
|
+
},
|
|
90
|
+
required: ['namespace', 'key', 'value'],
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'memory_search',
|
|
95
|
+
description: 'Search memories by keyword match in value or key.',
|
|
96
|
+
inputSchema: {
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {
|
|
99
|
+
query: { type: 'string' },
|
|
100
|
+
namespace: { type: 'string' },
|
|
101
|
+
limit: { type: 'number' },
|
|
102
|
+
},
|
|
103
|
+
required: ['query'],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'memory_recall',
|
|
108
|
+
description: 'Recall a specific memory entry by exact namespace and key.',
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: 'object',
|
|
111
|
+
properties: {
|
|
112
|
+
namespace: { type: 'string' },
|
|
113
|
+
key: { type: 'string' },
|
|
114
|
+
},
|
|
115
|
+
required: ['namespace', 'key'],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'memory_forget',
|
|
120
|
+
description: 'Delete a memory entry by namespace and key.',
|
|
121
|
+
inputSchema: {
|
|
122
|
+
type: 'object',
|
|
123
|
+
properties: {
|
|
124
|
+
namespace: { type: 'string' },
|
|
125
|
+
key: { type: 'string' },
|
|
126
|
+
},
|
|
127
|
+
required: ['namespace', 'key'],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'memory_list',
|
|
132
|
+
description: 'List memory entries for a namespace.',
|
|
133
|
+
inputSchema: {
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
|
+
namespace: { type: 'string' },
|
|
137
|
+
limit: { type: 'number' },
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'memory_stats',
|
|
143
|
+
description: 'Get memory storage statistics.',
|
|
144
|
+
inputSchema: { type: 'object', properties: {} },
|
|
145
|
+
},
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (type === 'all' || type === 'pantheon-persistence') {
|
|
150
|
+
tools.push(
|
|
151
|
+
{
|
|
152
|
+
name: 'persistence_save',
|
|
153
|
+
description: 'Save durable state JSON to .pantheon/persistence/<namespace>/<key>.json',
|
|
154
|
+
inputSchema: {
|
|
155
|
+
type: 'object',
|
|
156
|
+
properties: {
|
|
157
|
+
namespace: { type: 'string' },
|
|
158
|
+
key: { type: 'string' },
|
|
159
|
+
payload: { type: 'object' },
|
|
160
|
+
},
|
|
161
|
+
required: ['namespace', 'key', 'payload'],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'persistence_load',
|
|
166
|
+
description: 'Load durable state JSON from .pantheon/persistence/<namespace>/<key>.json',
|
|
167
|
+
inputSchema: {
|
|
168
|
+
type: 'object',
|
|
169
|
+
properties: {
|
|
170
|
+
namespace: { type: 'string' },
|
|
171
|
+
key: { type: 'string' },
|
|
172
|
+
},
|
|
173
|
+
required: ['namespace', 'key'],
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: 'persistence_list',
|
|
178
|
+
description: 'List durable state keys for a given namespace.',
|
|
179
|
+
inputSchema: {
|
|
180
|
+
type: 'object',
|
|
181
|
+
properties: {
|
|
182
|
+
namespace: { type: 'string' },
|
|
183
|
+
},
|
|
184
|
+
required: ['namespace'],
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (type === 'all' || type === 'pantheon-code-mode') {
|
|
191
|
+
tools.push({
|
|
192
|
+
name: 'execute_code_script',
|
|
193
|
+
description: 'Execute an orchestration script from .pantheon/code-mode/ directory.',
|
|
194
|
+
inputSchema: {
|
|
195
|
+
type: 'object',
|
|
196
|
+
properties: {
|
|
197
|
+
script: { type: 'string' },
|
|
198
|
+
args: { type: 'array', items: { type: 'string' } },
|
|
199
|
+
},
|
|
200
|
+
required: ['script'],
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return tools
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ── Resource Definitions ───────────────────────────────────────────────
|
|
209
|
+
|
|
210
|
+
function getResourcesForServer(type) {
|
|
211
|
+
if (type !== 'all' && type !== 'pantheon-resources') return []
|
|
212
|
+
return [
|
|
213
|
+
{
|
|
214
|
+
uri: 'pantheon://agents',
|
|
215
|
+
name: 'Pantheon Agents',
|
|
216
|
+
description: 'List of all Pantheon specialized agents and roles',
|
|
217
|
+
mimeType: 'text/markdown',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
uri: 'pantheon://skills',
|
|
221
|
+
name: 'Pantheon Skills',
|
|
222
|
+
description: 'List of all Pantheon skills with descriptions',
|
|
223
|
+
mimeType: 'text/markdown',
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
uri: 'pantheon://routing',
|
|
227
|
+
name: 'Pantheon Routing Rules',
|
|
228
|
+
description: 'Canonical orchestration routing configuration',
|
|
229
|
+
mimeType: 'text/yaml',
|
|
230
|
+
},
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ── Tool Execution Handler ─────────────────────────────────────────────
|
|
235
|
+
|
|
236
|
+
async function handleToolCall(name, params) {
|
|
237
|
+
switch (name) {
|
|
238
|
+
case 'memory_store': {
|
|
239
|
+
const db = getMemoryDb()
|
|
240
|
+
const now = new Date().toISOString()
|
|
241
|
+
const stmt = db.prepare(`
|
|
242
|
+
INSERT INTO memories (namespace, key, value, metadata, created_at, expires_at)
|
|
243
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
244
|
+
ON CONFLICT(namespace, key) DO UPDATE SET
|
|
245
|
+
value = excluded.value,
|
|
246
|
+
metadata = excluded.metadata,
|
|
247
|
+
created_at = excluded.created_at,
|
|
248
|
+
expires_at = excluded.expires_at
|
|
249
|
+
`)
|
|
250
|
+
stmt.run(
|
|
251
|
+
params.namespace,
|
|
252
|
+
params.key,
|
|
253
|
+
params.value,
|
|
254
|
+
params.metadata || null,
|
|
255
|
+
now,
|
|
256
|
+
params.expires_at || null,
|
|
257
|
+
)
|
|
258
|
+
return { status: 'stored', namespace: params.namespace, key: params.key }
|
|
259
|
+
}
|
|
260
|
+
case 'memory_recall': {
|
|
261
|
+
const db = getMemoryDb()
|
|
262
|
+
const row = db
|
|
263
|
+
.prepare(
|
|
264
|
+
'SELECT namespace, key, value, metadata, created_at, expires_at FROM memories WHERE namespace = ? AND key = ?',
|
|
265
|
+
)
|
|
266
|
+
.get(params.namespace, params.key)
|
|
267
|
+
return row || { error: 'not_found' }
|
|
268
|
+
}
|
|
269
|
+
case 'memory_search': {
|
|
270
|
+
const db = getMemoryDb()
|
|
271
|
+
const limit = params.limit || 10
|
|
272
|
+
let query =
|
|
273
|
+
'SELECT namespace, key, value, metadata, created_at FROM memories WHERE (value LIKE ? OR key LIKE ?)'
|
|
274
|
+
const queryParams = [`%${params.query}%`, `%${params.query}%`]
|
|
275
|
+
if (params.namespace) {
|
|
276
|
+
query += ' AND namespace = ?'
|
|
277
|
+
queryParams.push(params.namespace)
|
|
278
|
+
}
|
|
279
|
+
query += ' ORDER BY id DESC LIMIT ?'
|
|
280
|
+
queryParams.push(limit)
|
|
281
|
+
const rows = db.prepare(query).all(...queryParams)
|
|
282
|
+
return { count: rows.length, results: rows }
|
|
283
|
+
}
|
|
284
|
+
case 'memory_forget': {
|
|
285
|
+
const db = getMemoryDb()
|
|
286
|
+
const info = db
|
|
287
|
+
.prepare('DELETE FROM memories WHERE namespace = ? AND key = ?')
|
|
288
|
+
.run(params.namespace, params.key)
|
|
289
|
+
return { deleted: info.changes > 0, namespace: params.namespace, key: params.key }
|
|
290
|
+
}
|
|
291
|
+
case 'memory_list': {
|
|
292
|
+
const db = getMemoryDb()
|
|
293
|
+
const limit = params.limit || 50
|
|
294
|
+
let query = 'SELECT namespace, key, created_at FROM memories'
|
|
295
|
+
const queryParams = []
|
|
296
|
+
if (params.namespace) {
|
|
297
|
+
query += ' WHERE namespace = ?'
|
|
298
|
+
queryParams.push(params.namespace)
|
|
299
|
+
}
|
|
300
|
+
query += ' ORDER BY id DESC LIMIT ?'
|
|
301
|
+
queryParams.push(limit)
|
|
302
|
+
return db.prepare(query).all(...queryParams)
|
|
303
|
+
}
|
|
304
|
+
case 'memory_stats': {
|
|
305
|
+
const db = getMemoryDb()
|
|
306
|
+
const total = db.prepare('SELECT count(*) as count FROM memories').get()
|
|
307
|
+
const byNamespace = db
|
|
308
|
+
.prepare('SELECT namespace, count(*) as count FROM memories GROUP BY namespace')
|
|
309
|
+
.all()
|
|
310
|
+
return { total: total?.count || 0, byNamespace }
|
|
311
|
+
}
|
|
312
|
+
case 'persistence_save': {
|
|
313
|
+
const dir = join(getProjectRoot(), '.pantheon', 'persistence', params.namespace)
|
|
314
|
+
mkdirSync(dir, { recursive: true })
|
|
315
|
+
const filePath = join(dir, `${params.key}.json`)
|
|
316
|
+
writeFileSync(filePath, JSON.stringify(params.payload, null, 2), 'utf8')
|
|
317
|
+
return { status: 'saved', path: filePath }
|
|
318
|
+
}
|
|
319
|
+
case 'persistence_load': {
|
|
320
|
+
const filePath = join(
|
|
321
|
+
getProjectRoot(),
|
|
322
|
+
'.pantheon',
|
|
323
|
+
'persistence',
|
|
324
|
+
params.namespace,
|
|
325
|
+
`${params.key}.json`,
|
|
326
|
+
)
|
|
327
|
+
if (!existsSync(filePath)) return { error: 'not_found' }
|
|
328
|
+
return JSON.parse(readFileSync(filePath, 'utf8'))
|
|
329
|
+
}
|
|
330
|
+
case 'persistence_list': {
|
|
331
|
+
const dir = join(getProjectRoot(), '.pantheon', 'persistence', params.namespace)
|
|
332
|
+
if (!existsSync(dir)) return []
|
|
333
|
+
return readdirSync(dir)
|
|
334
|
+
.filter((f) => f.endsWith('.json'))
|
|
335
|
+
.map((f) => f.replace(/\.json$/, ''))
|
|
336
|
+
}
|
|
337
|
+
case 'execute_code_script': {
|
|
338
|
+
const codeDir = join(getProjectRoot(), '.pantheon', 'code-mode')
|
|
339
|
+
const scriptPath = join(codeDir, params.script)
|
|
340
|
+
if (!existsSync(scriptPath)) {
|
|
341
|
+
throw new Error(`Script ${params.script} not found in ${codeDir}`)
|
|
342
|
+
}
|
|
343
|
+
return new Promise((resolvePromise, _rejectPromise) => {
|
|
344
|
+
execFile(
|
|
345
|
+
process.execPath,
|
|
346
|
+
[scriptPath, ...(params.args || [])],
|
|
347
|
+
{ timeout: 30000 },
|
|
348
|
+
(err, stdout, stderr) => {
|
|
349
|
+
if (err) resolvePromise({ exitCode: err.code || 1, stderr: stderr || err.message })
|
|
350
|
+
else resolvePromise({ exitCode: 0, stdout })
|
|
351
|
+
},
|
|
352
|
+
)
|
|
353
|
+
})
|
|
354
|
+
}
|
|
355
|
+
default:
|
|
356
|
+
throw new Error(`Unknown tool: ${name}`)
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ── Resource Read Handler ──────────────────────────────────────────────
|
|
361
|
+
|
|
362
|
+
async function handleResourceRead(uri) {
|
|
363
|
+
if (uri === 'pantheon://agents') {
|
|
364
|
+
const agentsDir = join(ROOT, 'src', 'agents')
|
|
365
|
+
if (existsSync(agentsDir)) {
|
|
366
|
+
const files = readdirSync(agentsDir).filter((f) => f.endsWith('.md'))
|
|
367
|
+
const text = files.map((f) => `- **${f.replace('.md', '')}**`).join('\n')
|
|
368
|
+
return { contents: [{ uri, mimeType: 'text/markdown', text }] }
|
|
369
|
+
}
|
|
370
|
+
return { contents: [{ uri, mimeType: 'text/markdown', text: 'Agents directory not found.' }] }
|
|
371
|
+
}
|
|
372
|
+
if (uri === 'pantheon://skills') {
|
|
373
|
+
const skillsDir = join(ROOT, 'src', 'skills')
|
|
374
|
+
if (existsSync(skillsDir)) {
|
|
375
|
+
const dirs = readdirSync(skillsDir)
|
|
376
|
+
const text = dirs.map((d) => `- **${d}**`).join('\n')
|
|
377
|
+
return { contents: [{ uri, mimeType: 'text/markdown', text }] }
|
|
378
|
+
}
|
|
379
|
+
return { contents: [{ uri, mimeType: 'text/markdown', text: 'Skills directory not found.' }] }
|
|
380
|
+
}
|
|
381
|
+
if (uri === 'pantheon://routing') {
|
|
382
|
+
const routingFile = join(ROOT, 'src', 'routing.yml')
|
|
383
|
+
if (existsSync(routingFile)) {
|
|
384
|
+
return { contents: [{ uri, mimeType: 'text/yaml', text: readFileSync(routingFile, 'utf8') }] }
|
|
385
|
+
}
|
|
386
|
+
return { contents: [{ uri, mimeType: 'text/yaml', text: '# routing.yml not found' }] }
|
|
387
|
+
}
|
|
388
|
+
throw new Error(`Unknown resource: ${uri}`)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// ── MCP JSON-RPC Server Loop ───────────────────────────────────────────
|
|
392
|
+
|
|
393
|
+
const rl = createInterface({
|
|
394
|
+
input: process.stdin,
|
|
395
|
+
output: process.stdout,
|
|
396
|
+
terminal: false,
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
rl.on('line', async (line) => {
|
|
400
|
+
if (!line || line.trim() === '') return
|
|
401
|
+
let message
|
|
402
|
+
try {
|
|
403
|
+
message = JSON.parse(line)
|
|
404
|
+
} catch {
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const { id, method, params } = message
|
|
409
|
+
|
|
410
|
+
try {
|
|
411
|
+
if (method === 'initialize') {
|
|
412
|
+
const response = {
|
|
413
|
+
jsonrpc: '2.0',
|
|
414
|
+
id,
|
|
415
|
+
result: {
|
|
416
|
+
protocolVersion: '2024-11-05',
|
|
417
|
+
capabilities: {
|
|
418
|
+
tools: {},
|
|
419
|
+
resources: {},
|
|
420
|
+
},
|
|
421
|
+
serverInfo: {
|
|
422
|
+
name: `pantheon-${serverType}`,
|
|
423
|
+
version: '2.2.0',
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
}
|
|
427
|
+
process.stdout.write(`${JSON.stringify(response)}\n`)
|
|
428
|
+
return
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (method === 'notifications/initialized') {
|
|
432
|
+
return
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (method === 'tools/list') {
|
|
436
|
+
const tools = getToolsForServer(serverType)
|
|
437
|
+
const response = {
|
|
438
|
+
jsonrpc: '2.0',
|
|
439
|
+
id,
|
|
440
|
+
result: { tools },
|
|
441
|
+
}
|
|
442
|
+
process.stdout.write(`${JSON.stringify(response)}\n`)
|
|
443
|
+
return
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (method === 'tools/call') {
|
|
447
|
+
const { name, arguments: toolArgs } = params || {}
|
|
448
|
+
const output = await handleToolCall(name, toolArgs || {})
|
|
449
|
+
const response = {
|
|
450
|
+
jsonrpc: '2.0',
|
|
451
|
+
id,
|
|
452
|
+
result: {
|
|
453
|
+
content: [
|
|
454
|
+
{
|
|
455
|
+
type: 'text',
|
|
456
|
+
text: typeof output === 'string' ? output : JSON.stringify(output, null, 2),
|
|
457
|
+
},
|
|
458
|
+
],
|
|
459
|
+
},
|
|
460
|
+
}
|
|
461
|
+
process.stdout.write(`${JSON.stringify(response)}\n`)
|
|
462
|
+
return
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (method === 'resources/list') {
|
|
466
|
+
const resources = getResourcesForServer(serverType)
|
|
467
|
+
const response = {
|
|
468
|
+
jsonrpc: '2.0',
|
|
469
|
+
id,
|
|
470
|
+
result: { resources },
|
|
471
|
+
}
|
|
472
|
+
process.stdout.write(`${JSON.stringify(response)}\n`)
|
|
473
|
+
return
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (method === 'resources/read') {
|
|
477
|
+
const { uri } = params || {}
|
|
478
|
+
const result = await handleResourceRead(uri)
|
|
479
|
+
const response = {
|
|
480
|
+
jsonrpc: '2.0',
|
|
481
|
+
id,
|
|
482
|
+
result,
|
|
483
|
+
}
|
|
484
|
+
process.stdout.write(`${JSON.stringify(response)}\n`)
|
|
485
|
+
return
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (id !== undefined) {
|
|
489
|
+
process.stdout.write(
|
|
490
|
+
`${JSON.stringify({
|
|
491
|
+
jsonrpc: '2.0',
|
|
492
|
+
id,
|
|
493
|
+
error: { code: -32601, message: `Method not found: ${method}` },
|
|
494
|
+
})}\n`,
|
|
495
|
+
)
|
|
496
|
+
}
|
|
497
|
+
} catch (error) {
|
|
498
|
+
if (id !== undefined) {
|
|
499
|
+
process.stdout.write(
|
|
500
|
+
`${JSON.stringify({
|
|
501
|
+
jsonrpc: '2.0',
|
|
502
|
+
id,
|
|
503
|
+
error: { code: -32000, message: error?.message || 'Internal error' },
|
|
504
|
+
})}\n`,
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
})
|