local-mcp-manager 0.5.4 → 0.9.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.
@@ -0,0 +1,70 @@
1
+ import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol'
2
+ import { z } from 'zod'
3
+ import { createContract, METHODS, NAMESPACE } from '../src/workbench/contract.js'
4
+ import { McpWebError } from './web.js'
5
+
6
+ const initializers = []
7
+ class WorkbenchRemote extends TypertRemoteService {
8
+ constructor(ctx, manager) {
9
+ super(ctx, NAMESPACE)
10
+ this.manager = manager
11
+ for (const init of initializers) init.call(this)
12
+ }
13
+
14
+ async dispatch(method, ...args) {
15
+ // The Gateway supplies the authenticated principal on this context-bound
16
+ // receiver. Do not use a browser flag or a missing identity as permission.
17
+ if (this.ctx.invocation?.peer?.principal?.kind !== 'owner') {
18
+ return { ok: false, code: 'FORBIDDEN', message: '仅主机所有者可管理 MCP 服务器。' }
19
+ }
20
+ try {
21
+ return { ok: true, data: await this.manager[method](...args) }
22
+ } catch (error) {
23
+ if (error instanceof McpWebError) {
24
+ return { ok: false, code: error.code, message: error.message }
25
+ }
26
+ // Do not echo arbitrary runtime exception messages or connection data.
27
+ return { ok: false, code: 'INTERNAL', message: '管理操作未完成。请刷新核对当前状态,再决定是否重试。' }
28
+ }
29
+ }
30
+
31
+ overview() { return this.dispatch('directory') }
32
+ getServer(input) { return this.dispatch('getServer', input) }
33
+ getToolSchema(input) { return this.dispatch('getToolSchema', input) }
34
+ reviewTool(input) { return this.dispatch('reviewTool', input) }
35
+ saveServer(input) { return this.dispatch('saveServer', input) }
36
+ removeServer(input) { return this.dispatch('removeServer', input) }
37
+ setServerEnabled(input) { return this.dispatch('setServerEnabled', input) }
38
+ setToolPolicy(input) { return this.dispatch('setToolPolicy', input) }
39
+ connect(input) { return this.dispatch('connect', input) }
40
+ refresh(input) { return this.dispatch('refresh', input) }
41
+ aggregate() { return this.dispatch('aggregate') }
42
+ invokeTool(input) { return this.dispatch('invokeTool', input) }
43
+ testServer(input) { return this.dispatch('testServer', input) }
44
+ exportConfig(input) { return this.dispatch('exportConfig', input) }
45
+ importConfig(input) { return this.dispatch('importConfig', input) }
46
+ setServerTags(input) { return this.dispatch('setServerTags', input) }
47
+ healthStatus() { return this.dispatch('healthStatus') }
48
+ healthConfig(input) { return this.dispatch('healthConfig', input) }
49
+ registrySearch(input) { return this.dispatch('registrySearch', input) }
50
+ readResource(input) { return this.dispatch('readResource', input) }
51
+ resourceWatches(input) { return this.dispatch('resourceWatches', input) }
52
+ setResourceWatch(input) { return this.dispatch('setResourceWatch', input) }
53
+ getPrompt(input) { return this.dispatch('getPrompt', input) }
54
+ statsOverview(input) { return this.dispatch('statsOverview', input) }
55
+ logTail(input) { return this.dispatch('logTail', input) }
56
+ logConfig(input) { return this.dispatch('logConfig', input) }
57
+ }
58
+ for (const method of METHODS) {
59
+ Remote(WorkbenchRemote.prototype[method], {
60
+ name: method, kind: 'method', static: false, private: false,
61
+ addInitializer: init => { initializers.push(init) },
62
+ })
63
+ }
64
+
65
+ export async function mountWorkbench(ctx, manager) {
66
+ // Directory registration is owned by the optional Host fiber and releases on
67
+ // disable/unload, even when the native panel is absent on a desktop host.
68
+ await ctx.typert.register(createContract(z).host)
69
+ new WorkbenchRemote(ctx, manager)
70
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "MCP manager",
4
+ "description": "Manage this host’s MCP connections, tools and approval rules. The dsh-go native panel and Web workbench share the same servers."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "MCP 管理器",
4
+ "description": "管理这台主机上的 MCP 连接、工具和调用策略。手机原生面板和 Web 工作台使用同一组服务器。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,10 +1,20 @@
1
1
  {
2
2
  "name": "local-mcp-manager",
3
- "version": "0.5.4",
4
- "publishConfig": {"access": "public", "registry": "https://registry.npmjs.org"},
3
+ "version": "0.9.0",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "registry": "https://registry.npmjs.org"
7
+ },
5
8
  "type": "module",
6
9
  "main": "lib/index.js",
7
- "description": "面向 dsh-go 原生界面的 MCP 管理适配插件,不保证其他平台可用。",
10
+ "exports": {
11
+ ".": "./lib/index.js",
12
+ "./client": "./dist/workbench.js",
13
+ "./package.json": "./package.json",
14
+ "./locale/*.json": "./locale/*.json",
15
+ "./icon": "./assets/mcp-manager.svg"
16
+ },
17
+ "description": "装进 DSH 的桌面 MCP 运维台:迁移连接、试运行、复核工具与排查故障,兼容 dsh-go 原生面板。",
8
18
  "license": "MIT",
9
19
  "author": "Aouky7",
10
20
  "repository": {
@@ -13,23 +23,73 @@
13
23
  },
14
24
  "homepage": "https://github.com/Aouky7/dsh-go-mcp-manager#readme",
15
25
  "bugs": "https://github.com/Aouky7/dsh-go-mcp-manager/issues",
16
- "keywords": ["dsh-go", "mcp", "native-plugin", "mcp-manager"],
17
- "files": ["lib/", "cordis.patch.yml", "README.md", "CHANGELOG.md", "LICENSE", "THIRD_PARTY_NOTICES.md"],
26
+ "keywords": [
27
+ "dsh-go",
28
+ "dsh",
29
+ "mcp",
30
+ "mcp-manager"
31
+ ],
32
+ "files": [
33
+ "lib/",
34
+ "src/workbench/contract.js",
35
+ "dist/workbench.js",
36
+ "assets/mcp-manager.svg",
37
+ "locale/*.json",
38
+ "cordis.patch.yml",
39
+ "README.md",
40
+ "CHANGELOG.md",
41
+ "LICENSE",
42
+ "THIRD_PARTY_NOTICES.md"
43
+ ],
18
44
  "scripts": {
19
- "test": "node --test test/*.test.js",
20
- "test:core": "node --test test/http.test.js test/runtime.test.js test/projection.test.js test/startup.test.js",
45
+ "build:web": "node scripts/build-workbench.mjs",
46
+ "check:web": "node scripts/build-workbench.mjs --check",
47
+ "prepack": "npm run check:web",
48
+ "test": "node --test test/*.test.js test/*.test.mjs",
49
+ "test:desktop": "node scripts/test-desktop.mjs",
50
+ "test:browser": "node test/workbench-browser.mjs",
51
+ "test:cold-start": "node test/workbench-cold-start.mjs",
52
+ "test:core": "node --test test/http.test.js test/runtime.test.js test/projection.test.js test/startup.test.js test/workbench-data.test.js",
21
53
  "test:native": "node --test test/manager.test.js test/native-headers.test.js test/optimization.test.js test/ui-redesign.test.js test/edge-fixes.test.js test/release-native.test.js"
22
54
  },
23
- "engines": {"node": ">=22.19.0", "dsh": ">=0.2.2-rc.1 <0.3.0-0"},
24
- "dsh": {"bundle": {"patch": "./cordis.patch.yml"}},
55
+ "engines": {
56
+ "node": ">=22.19.0",
57
+ "dsh": ">=0.2.2-rc.1"
58
+ },
59
+ "dsh": {
60
+ "bundle": {
61
+ "patch": "./cordis.patch.yml"
62
+ },
63
+ "client": {
64
+ "platform": "web",
65
+ "immediately": true,
66
+ "inject": [
67
+ "@deepseek-ai/dsh-api-gateway",
68
+ "@deepseek-ai/dsh-api-remote-access",
69
+ "@deepseek-ai/dsh-client-locale",
70
+ "@deepseek-ai/dsh-client-ui-layout",
71
+ "@deepseek-ai/dsh-client-ui-sidebar"
72
+ ]
73
+ }
74
+ },
25
75
  "peerDependencies": {
26
76
  "@deepseek-ai/cordis": "~4.1.0",
27
- "@deepseek-ai/schemastery": "~3.19.0",
28
- "@deepseek-ai/dsh-mcp-client": "0.2.2-rc.1",
29
- "@deepseek-ai/dsh-credentials": "0.2.2-rc.1",
30
- "@deepseek-ai/dsh-subprocess": "0.2.2-rc.1"
77
+ "@deepseek-ai/dsh-credentials": ">=0.2.2-rc.1",
78
+ "@deepseek-ai/dsh-mcp-client": ">=0.2.2-rc.1",
79
+ "@deepseek-ai/dsh-subprocess": ">=0.2.2-rc.1",
80
+ "@deepseek-ai/dsh-typert-protocol": ">=0.2.2-rc.1",
81
+ "@deepseek-ai/schemastery": "~3.19.0"
82
+ },
83
+ "dependencies": {
84
+ "@modelcontextprotocol/client": "2.4.0",
85
+ "zod": "4.6.6"
86
+ },
87
+ "devDependencies": {
88
+ "playwright-core": "1.65.1",
89
+ "react": "19.1.0",
90
+ "react-dom": "19.1.0",
91
+ "react-test-renderer": "19.1.0"
31
92
  },
32
- "dependencies": {"@modelcontextprotocol/client": "2.3.0"},
33
93
  "overrides": {
34
94
  "@modelcontextprotocol/client": "$@modelcontextprotocol/client",
35
95
  "zod": "4.6.6",
@@ -38,11 +98,33 @@
38
98
  "dshGo": {
39
99
  "v": 1,
40
100
  "minApp": "1.1.0",
41
- "title": {"zh": "MCP 管理器", "en": "MCP Manager"},
101
+ "title": {
102
+ "zh": "MCP 管理器",
103
+ "en": "MCP Manager"
104
+ },
42
105
  "icon": "server",
43
106
  "contributes": {
44
- "composer.tools": [{"id": "mcp-open", "label": "MCP", "icon": "server", "panel": "mcp-manager"}],
45
- "panels": [{"id": "mcp-manager", "title": "MCP 管理器", "icon": "server", "placement": ["features", "session.tab", "chat.panel"], "presentation": "page"}]
107
+ "composer.tools": [
108
+ {
109
+ "id": "mcp-open",
110
+ "label": "MCP",
111
+ "icon": "server",
112
+ "panel": "mcp-manager"
113
+ }
114
+ ],
115
+ "panels": [
116
+ {
117
+ "id": "mcp-manager",
118
+ "title": "MCP 管理器",
119
+ "icon": "server",
120
+ "placement": [
121
+ "features",
122
+ "session.tab",
123
+ "chat.panel"
124
+ ],
125
+ "presentation": "page"
126
+ }
127
+ ]
46
128
  }
47
129
  }
48
130
  }
@@ -0,0 +1,198 @@
1
+ // One strict contract for the bundled Host and browser. Do not include native
2
+ // forms, stored credential references, or unbounded runtime snapshots here.
3
+ export const PACKAGE = 'local-mcp-manager'
4
+ export const NAMESPACE = 'mcpManagerWorkbench'
5
+ export const PANEL_ID = 'mcp-manager-workbench'
6
+ export const METHODS = Object.freeze([
7
+ 'overview', 'getServer', 'getToolSchema', 'saveServer', 'removeServer', 'setServerEnabled', 'setToolPolicy', 'connect', 'refresh',
8
+ 'aggregate', 'invokeTool', 'testServer', 'exportConfig', 'importConfig', 'setServerTags', 'healthStatus', 'healthConfig',
9
+ 'registrySearch', 'readResource', 'getPrompt', 'statsOverview', 'logTail', 'logConfig', 'reviewTool', 'resourceWatches', 'setResourceWatch',
10
+ ])
11
+
12
+ export function createContract(z) {
13
+ const id = z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,31}$/)
14
+ const revision = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
15
+ const transport = z.enum(['streamable-http', 'sse', 'stdio'])
16
+ const section = z.enum(['connection', 'tools', 'activity', 'config'])
17
+ const count = z.number().int().nonnegative()
18
+ const stamp = z.number().nonnegative()
19
+ const pairName = z.string().trim().min(1).max(128)
20
+ const pairs = z.array(z.union([
21
+ z.strictObject({ name: pairName, keep: z.literal(true) }),
22
+ z.strictObject({ name: pairName, value: z.string().max(2000) }),
23
+ ])).max(16)
24
+ const configInput = {
25
+ url: z.string().max(2000), command: z.string().max(300),
26
+ args: z.array(z.string().max(2000)).max(64), cwd: z.string().max(1000),
27
+ timeoutMs: z.number().int().min(1000).max(180000),
28
+ }
29
+ const serverInput = z.strictObject({ id, transport, name: z.string().max(80),
30
+ url: configInput.url.optional(), command: configInput.command.optional(),
31
+ args: configInput.args.optional(), cwd: configInput.cwd.optional(), timeoutMs: configInput.timeoutMs,
32
+ enabled: z.boolean(), requireApproval: z.boolean(), headers: pairs, env: pairs,
33
+ tags: z.array(z.string().trim().min(1).max(24)).max(8).optional() })
34
+ const endpoint = z.strictObject({ id, revision })
35
+ const toolStamp = z.string().min(1).max(80)
36
+ const failure = z.strictObject({ ok: z.literal(false), code: z.string().min(1).max(64), message: z.string().min(1).max(512) })
37
+ const mutation = z.strictObject({ revision })
38
+ const accepted = z.strictObject({ revision, accepted: z.literal(true) })
39
+ const lastCheck = z.strictObject({ at: stamp, durationMs: stamp, ok: z.boolean() })
40
+ const faultCode = z.string().max(128).optional()
41
+ const faultMessage = z.string().max(512).optional()
42
+ const directoryRow = {
43
+ id, name: z.string().max(80), transport, enabled: z.boolean(),
44
+ status: z.enum(['connected', 'connecting', 'disconnected', 'reconnecting', 'disabled', 'error']),
45
+ error: z.strictObject({ code: faultCode, message: faultMessage }).nullable(),
46
+ lastCheck: lastCheck.nullable(), counts: z.strictObject({ tools: count, enabledTools: count }), refreshing: z.boolean(),
47
+ tags: z.array(z.string().max(24)).max(8),
48
+ }
49
+ const directory = z.strictObject({ revision, active: z.boolean(), autoConnect: z.boolean(), servers: z.array(z.strictObject(directoryRow)).max(32) })
50
+ const pairView = z.strictObject({ name: pairName, hasValue: z.boolean() })
51
+ const details = {
52
+ connection: z.strictObject({
53
+ target: z.string().max(512), serverInfo: z.strictObject({ name: z.string().max(512).optional(), version: z.string().max(128).optional() }).nullable(),
54
+ retries: count, nextRetryAt: stamp.nullable(), resources: count, prompts: count, logging: z.boolean().optional(),
55
+ canWatchResources: z.boolean().optional(),
56
+ resourceTemplates: z.array(z.strictObject({ uriTemplate: z.string().max(4096), name: z.string().max(200),
57
+ description: z.string().max(720), variables: z.array(z.string().min(1).max(128)).max(32) })).max(32).optional(),
58
+ resourceRows: z.array(z.strictObject({ uri: z.string().max(4096), name: z.string().max(200),
59
+ description: z.string().max(720), mimeType: z.string().max(120) })).max(200).optional(),
60
+ promptRows: z.array(z.strictObject({ name: z.string().max(256), description: z.string().max(720),
61
+ arguments: z.array(z.strictObject({ name: z.string().max(64), description: z.string().max(300), required: z.boolean() })).max(16) })).max(100).optional(),
62
+ }),
63
+ tools: z.strictObject({ rows: z.array(z.strictObject({ name: z.string().max(1024), description: z.string().max(720),
64
+ enabled: z.boolean(), requireApproval: z.boolean(), writable: z.boolean(), stamp: toolStamp.nullable(),
65
+ pending: z.boolean().optional(), hint: z.enum(['read-only', 'destructive']).optional() })).max(500), total: count }),
66
+ activity: z.strictObject({ stats: z.strictObject({ calls: count, failures: count, active: count }),
67
+ history: z.array(z.strictObject({ tool: z.string().max(1024), at: stamp, durationMs: stamp,
68
+ ok: z.boolean(), code: faultCode, message: faultMessage })).max(20) }),
69
+ config: z.strictObject({ ...configInput, headers: z.array(pairView).max(16), env: z.array(pairView).max(16) }),
70
+ }
71
+ const readRow = z.strictObject({ ...directoryRow, requireApproval: z.boolean() })
72
+ const serverDetail = z.discriminatedUnion('section', Object.entries(details).map(([key, detail]) =>
73
+ z.strictObject({ revision, server: readRow, section: z.literal(key), detail })))
74
+ const toolSchema = z.strictObject({ name: z.string().max(1024), schemaJson: z.string().max(16000), truncated: z.boolean(),
75
+ outputSchemaJson: z.string().max(16000).optional(), outputTruncated: z.boolean().optional() })
76
+ const aggregateRow = z.strictObject({ id, calls: count, failures: count, active: count, tools: count })
77
+ const aggregateData = z.strictObject({
78
+ runtimeReady: z.boolean(), generatedAt: stamp, configPath: z.string().max(512),
79
+ servers: z.array(aggregateRow).max(32),
80
+ byTool: z.array(z.strictObject({ tool: z.string().max(1024), calls: count, failures: count,
81
+ lastAt: stamp, lastDurationMs: stamp.nullable() })).max(24),
82
+ conflicts: z.array(z.strictObject({ tool: z.string().max(1024), servers: z.array(id).max(32) })).max(16),
83
+ })
84
+ const invokeResult = z.strictObject({ approvalRequired: z.literal(false), durationMs: stamp, isError: z.boolean(),
85
+ text: z.string().max(8000), truncated: z.boolean(), structured: z.boolean().optional(), code: faultCode })
86
+ const invokeData = z.discriminatedUnion('approvalRequired', [
87
+ z.strictObject({ approvalRequired: z.literal(true), confirmToken: z.string().min(8).max(80) }), invokeResult,
88
+ ])
89
+ const testResult = z.strictObject({ revision, id, status: z.enum(['connected', 'connecting', 'disconnected', 'reconnecting', 'disabled', 'error']),
90
+ error: z.strictObject({ code: faultCode, message: faultMessage }).nullable(), lastCheck: lastCheck.nullable(), durationMs: stamp })
91
+ const exportData = z.strictObject({ filename: z.string().max(80), contentJson: z.string().max(160000),
92
+ servers: count, redacted: z.boolean() })
93
+ const importData = z.strictObject({ revision, added: count, updated: count, replaced: z.boolean(), servers: count })
94
+ const healthData = z.strictObject({
95
+ enabled: z.boolean(), intervalMinutes: z.number().int().min(1).max(360),
96
+ autoDisableAfterFaults: z.number().int().min(0).max(10), lastTickAt: stamp.nullable(),
97
+ log: z.array(z.strictObject({at: stamp, serverId: id, kind: z.string().max(24), code: z.string().max(128).optional()})).max(20),
98
+ servers: z.array(z.strictObject({id, faults: count, lastFaultAt: stamp.nullable(), lastOkAt: stamp.nullable(),
99
+ lastKind: z.string().max(24)})).max(32),
100
+ })
101
+ const registryData = z.strictObject({servers: z.array(z.strictObject({name: z.string().max(160),
102
+ description: z.string().max(200), version: z.string().max(40), websiteUrl: z.string().max(300).nullable(),
103
+ status: z.string().max(16), transport, url: z.string().max(600).nullable(), command: z.string().max(80).nullable(),
104
+ args: z.array(z.string().max(300)).max(32), registryType: z.enum(['npm', 'pypi', 'oci']).optional(),
105
+ packageRef: z.string().min(1).max(300).optional(), headerNames: z.array(z.string().max(64)).max(8), envNames: z.array(z.string().max(64)).max(8)})).max(20),
106
+ source: z.string().max(80), unreachable: z.boolean(), reason: z.string().max(24).optional()})
107
+ const resourceUri = z.string().min(1).max(4096)
108
+ const watchData = z.strictObject({supported: z.boolean(), rows: z.array(z.strictObject({
109
+ uri: resourceUri, token: z.string().min(1).max(80), changedAt: stamp.nullable(),
110
+ })).max(16)})
111
+ const resourceData = z.strictObject({uri: z.string().max(4096), mimeType: z.string().max(120).nullable(),
112
+ text: z.string().max(16000).nullable(), blob: z.string().max(160000).nullable(), truncated: z.boolean(), size: count})
113
+ const promptData = z.strictObject({description: z.string().max(512).nullable(),
114
+ messages: z.array(z.strictObject({role: z.enum(['user', 'assistant']), text: z.string().max(16000)})).max(10)})
115
+ const statsData = z.strictObject({days: z.array(z.strictObject({date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/), calls: count, failures: count})).max(30),
116
+ totals: z.strictObject({calls: count, failures: count, durationMs: count}), failureRate: z.number().min(0).max(1),
117
+ top: z.array(z.strictObject({tool: z.string().max(1024), calls: count, failures: count, avgMs: count, maxMs: count})).max(12),
118
+ slow: z.array(z.strictObject({tool: z.string().max(1024), serverId: id, at: stamp, durationMs: stamp, ok: z.boolean()})).max(8),
119
+ servers: z.array(z.strictObject({id, recent: z.array(z.strictObject({at: stamp, ok: z.boolean()})).max(12)})).max(32)})
120
+ const logData = z.strictObject({level: z.string().max(16).nullable(),
121
+ lines: z.array(z.strictObject({at: stamp, level: z.string().max(16), logger: z.string().max(64).nullable(), data: z.string().max(4000)})).max(300)})
122
+ const definitions = {
123
+ overview: ['List connection summaries for the workbench.', null, directory],
124
+ getServer: ['Read one panel of a configured server.', z.strictObject({ id, section }), serverDetail],
125
+ getToolSchema: ['Read one redacted tool input definition preview.', z.strictObject({ id, name: z.string().min(1).max(1024), stamp: toolStamp }), toolSchema],
126
+ reviewTool: ['Accept one exact discovered tool definition at a known configuration revision.',
127
+ z.strictObject({ id, revision, name: z.string().min(1).max(1024), stamp: toolStamp }), mutation],
128
+ saveServer: ['Save one new or existing server at a known revision.', z.strictObject({ revision, mode: z.enum(['create', 'edit']), server: serverInput }), mutation],
129
+ removeServer: ['Remove one configured server at a known revision.', z.strictObject({ id, revision }), mutation],
130
+ setServerEnabled: ['Set the desired connection state of one configured server.', z.strictObject({ id, revision, enabled: z.boolean() }), mutation],
131
+ setToolPolicy: ['Update a policy for the reviewed tool definition.', z.strictObject({ id, revision, name: z.string().min(1).max(256), enabled: z.boolean(), requireApproval: z.boolean(), stamp: toolStamp }), mutation],
132
+ connect: ['Request reconnection of an enabled server.', endpoint, accepted],
133
+ refresh: ['Request a refresh of its tool catalog.', endpoint, accepted],
134
+ aggregate: ['Aggregate fleet-wide dashboard numbers from live runtime slots.', null, aggregateData],
135
+ invokeTool: ['Invoke one live discovered tool with explicit approval handling.',
136
+ z.strictObject({ id, name: z.string().min(1).max(1024), stamp: toolStamp,
137
+ argsJson: z.string().max(16000), confirmToken: z.string().min(8).max(80).optional() }), invokeData],
138
+ testServer: ['Save one server, connect and report the observed result.',
139
+ z.strictObject({ revision, mode: z.enum(['create', 'edit']), server: serverInput }), testResult],
140
+ exportConfig: ['Export all configured servers as JSON.', z.strictObject({ mode: z.enum(['redacted', 'full']) }), exportData],
141
+ importConfig: ['Import a plugin backup or supported third-party MCP JSON at a known revision.',
142
+ z.strictObject({ revision, contentJson: z.string().max(160000), mode: z.enum(['merge', 'replace']) }), importData],
143
+ setServerTags: ['Update the organizational tags of one server.', z.strictObject({ id, revision, tags: z.array(z.string().trim().min(1).max(24)).max(8) }), mutation],
144
+ healthStatus: ['Read the background health watcher state and recent transitions.', null, healthData],
145
+ healthConfig: ['Configure the background health watcher.', z.strictObject({
146
+ enabled: z.boolean(), intervalMinutes: z.number().int().min(1).max(360),
147
+ autoDisableAfterFaults: z.number().int().min(0).max(10),
148
+ }), healthData],
149
+ registrySearch: ['Search the public MCP registry for connectable servers.',
150
+ z.strictObject({query: z.string().trim().min(1).max(100)}), registryData],
151
+ readResource: ['Read a resource on a connected server, optionally by expanding an advertised template.',
152
+ z.union([z.strictObject({id, uri: resourceUri}), z.strictObject({id, uriTemplate: resourceUri,
153
+ args: z.array(z.strictObject({name: z.string().min(1).max(128), value: z.string().max(1024)})).max(32).optional()})]), resourceData],
154
+ resourceWatches: ['Read the current connection’s resource subscription metadata.', z.strictObject({id}), watchData],
155
+ setResourceWatch: ['Start or stop watching a previously read resource on this connection.',
156
+ z.strictObject({id, uri: resourceUri, enabled: z.boolean()}), watchData],
157
+ getPrompt: ['Render one server prompt template with arguments.',
158
+ z.strictObject({id, name: z.string().min(1).max(256),
159
+ args: z.array(z.strictObject({name: z.string().min(1).max(64), value: z.string().max(2000)})).max(16).optional()}), promptData],
160
+ statsOverview: ['Aggregate persisted call statistics for trend views.',
161
+ z.strictObject({days: z.number().int().min(1).max(30)}), statsData],
162
+ logTail: ['Read recent log notifications of one server.', z.strictObject({id}), logData],
163
+ logConfig: ['Set the minimum log level of one connected server.',
164
+ z.strictObject({id, level: z.enum(['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'])}), logData],
165
+ }
166
+ const makeCodec = (name, schema) => ({
167
+ mode: 'strict', typeSymbol: `${PACKAGE}#Workbench${name}`, create: () => schema,
168
+ get jsonSchema() { return z.toJSONSchema(schema) },
169
+ })
170
+ const schemas = []
171
+ const descriptors = METHODS.map(method => {
172
+ const [description, input, data] = definitions[method]
173
+ const reply = z.discriminatedUnion('ok', [failure, z.strictObject({ ok: z.literal(true), data })])
174
+ const parameters = []
175
+ if (input) {
176
+ const name = `${method}Input`, codec = makeCodec(name, input)
177
+ schemas.push({ name: `Workbench${name}`, create: codec.create })
178
+ parameters.push({ name: 'input', wire: 'input', source: 'json', codec, strictCodec: codec })
179
+ }
180
+ const name = `${method}Reply`, codec = makeCodec(name, reply)
181
+ schemas.push({ name: `Workbench${name}`, create: codec.create })
182
+ return {
183
+ id: `${PACKAGE}#${NAMESPACE}/${method}`, service: NAMESPACE, namespace: NAMESPACE, method, description,
184
+ invocation: { kind: 'direct' }, parameters,
185
+ result: { ...codec, encode: value => reply.parse(value), decode: value => reply.parse(value) },
186
+ }
187
+ })
188
+ return {
189
+ host: {
190
+ package: PACKAGE, face: 'host', schemas, invocations: descriptors,
191
+ model: { services: [{ key: NAMESPACE, exportName: NAMESPACE, tags: [], types: [],
192
+ members: descriptors.map(({ method, description, parameters }) => ({ name: method, kind: 'method',
193
+ signature: `${method}(${parameters.length ? 'input' : ''})`, description })),
194
+ }], events: [], objects: [] },
195
+ },
196
+ client: { package: PACKAGE, descriptors },
197
+ }
198
+ }