@openfairygui/mcp 0.6.3 → 0.7.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 +12 -4
- package/bin/ofgui-mcp.cjs +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +18 -9
- package/dist/index.d.mts +19 -10
- package/dist/index.mjs +1 -1
- package/dist/{stdio-BWd0nXcw.mjs → stdio-CGEOPi_6.mjs} +389 -239
- package/dist/{stdio-D0L4ie5Z.cjs → stdio-uhD6y1BG.cjs} +389 -239
- package/dist/stdio.cjs +1 -1
- package/dist/stdio.mjs +1 -1
- package/package.json +7 -7
- package/src/contract-schema.ts +0 -39
- package/src/index.ts +0 -35
- package/src/prompt-definitions.ts +0 -122
- package/src/resource-definitions.ts +0 -141
- package/src/server.ts +0 -94
- package/src/stdio.ts +0 -20
- package/src/tool-definitions.ts +0 -64
- package/src/tool-handler.ts +0 -107
- package/src/tool-metadata.ts +0 -160
package/dist/stdio.cjs
CHANGED
package/dist/stdio.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as connectOpenFairyGuiMcpStdio } from "./stdio-
|
|
1
|
+
import { t as connectOpenFairyGuiMcpStdio } from "./stdio-CGEOPi_6.mjs";
|
|
2
2
|
export { connectOpenFairyGuiMcpStdio };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfairygui/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "FairyGUI Headless Authoring SDK - MCP server adapter for the backend runtime.",
|
|
5
5
|
"author": "OpenFairyGUI Contributors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,8 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
50
50
|
"dist/",
|
|
51
|
-
"bin/"
|
|
52
|
-
"src/"
|
|
51
|
+
"bin/"
|
|
53
52
|
],
|
|
54
53
|
"keywords": [
|
|
55
54
|
"fairygui",
|
|
@@ -61,12 +60,12 @@
|
|
|
61
60
|
"dependencies": {
|
|
62
61
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
63
62
|
"zod": "^4.3.6",
|
|
64
|
-
"@openfairygui/backend": "0.
|
|
63
|
+
"@openfairygui/backend": "0.7.1"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
67
66
|
"ava": "^7.0.0",
|
|
68
67
|
"tsx": "^4.0.0",
|
|
69
|
-
"@openfairygui/core": "0.
|
|
68
|
+
"@openfairygui/core": "0.7.1",
|
|
70
69
|
"@openfairygui/test-utils": "0.3.0"
|
|
71
70
|
},
|
|
72
71
|
"ava": {
|
|
@@ -79,11 +78,12 @@
|
|
|
79
78
|
],
|
|
80
79
|
"files": [
|
|
81
80
|
"test/**/*.test.ts"
|
|
82
|
-
]
|
|
81
|
+
],
|
|
82
|
+
"workerThreads": false
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
85
|
"build": "tsdown src/index.ts src/stdio.ts --format esm,cjs --platform node --external node:fs --external node:path --external node:fs/promises",
|
|
86
86
|
"build:watch": "tsdown src/index.ts src/stdio.ts --watch --format esm,cjs --platform node",
|
|
87
|
-
"test": "ava test/**/*.test.ts
|
|
87
|
+
"test": "ava test/**/*.test.ts"
|
|
88
88
|
}
|
|
89
89
|
}
|
package/src/contract-schema.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { getInstalledContractSnapshot, type ContractSchema } from '@openfairygui/backend/docs';
|
|
3
|
-
export { getOpenFairyGuiOperationCatalog, getOpenFairyGuiOperationSchema, OPENFAIRYGUI_OPERATION_CATALOG_URI, OPENFAIRYGUI_OPERATION_SCHEMA_TEMPLATE } from '@openfairygui/backend/docs';
|
|
4
|
-
|
|
5
|
-
export const CONTRACT_SNAPSHOT = getInstalledContractSnapshot();
|
|
6
|
-
|
|
7
|
-
export function contractObjectSchema(schema: ContractSchema): z.ZodObject {
|
|
8
|
-
const result = z.fromJSONSchema({ ...schema, $defs: CONTRACT_SNAPSHOT.$defs });
|
|
9
|
-
if (!(result instanceof z.ZodObject)) throw new TypeError('Tool contract must be an object');
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Keep SDK discovery dynamic without expanding shared contract definitions. */
|
|
14
|
-
export function compactToolSchema(schema: z.ZodObject, io: 'input' | 'output'): z.ZodObject {
|
|
15
|
-
// Zod metadata supplies the wire schema; validation still delegates to the original schema.
|
|
16
|
-
// A separate object avoids Zod's cycle extraction overwriting the metadata's definitions.
|
|
17
|
-
return z.looseObject({}).superRefine((value, context) => {
|
|
18
|
-
const parsed = schema.safeParse(value);
|
|
19
|
-
if (!parsed.success) for (const issue of parsed.error.issues) context.addIssue({ ...issue });
|
|
20
|
-
}).meta(z.toJSONSchema(schema, { target: 'draft-07', io, reused: 'ref' }));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Decode only generated Uint8Array locations; arbitrary JSON metadata is not rewritten. */
|
|
24
|
-
export function decodeToolBytes(input: Record<string, unknown>, paths: string[][]): Record<string, unknown> {
|
|
25
|
-
if (!paths.length) return input;
|
|
26
|
-
const result = structuredClone(input);
|
|
27
|
-
function visit(value: unknown, parts: string[]): unknown {
|
|
28
|
-
if (!parts.length) return value === null ? value : Uint8Array.from(value as number[]);
|
|
29
|
-
if (!value || typeof value !== 'object') return value;
|
|
30
|
-
const [key, ...rest] = parts;
|
|
31
|
-
const record = value as Record<string, unknown>;
|
|
32
|
-
for (const name of key === '*' ? Object.keys(record) : [key]) {
|
|
33
|
-
if (Object.hasOwn(record, name)) record[name] = visit(record[name], rest);
|
|
34
|
-
}
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
for (const parts of paths) visit(result, parts);
|
|
38
|
-
return result;
|
|
39
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
createOpenFairyGuiMcpServer,
|
|
3
|
-
type CreateOpenFairyGuiMcpServerOptions,
|
|
4
|
-
} from './server.js';
|
|
5
|
-
export {
|
|
6
|
-
connectOpenFairyGuiMcpStdio,
|
|
7
|
-
} from './stdio.js';
|
|
8
|
-
export {
|
|
9
|
-
callOpenFairyGuiBackendTool,
|
|
10
|
-
type OpenFairyGuiBackendRuntime,
|
|
11
|
-
type OpenFairyGuiMcpToolPolicy,
|
|
12
|
-
} from './tool-handler.js';
|
|
13
|
-
export {
|
|
14
|
-
OPENFAIRYGUI_BACKEND_PROMPT_DEFINITIONS,
|
|
15
|
-
OPENFAIRYGUI_BACKEND_PROMPT_NAMES,
|
|
16
|
-
type OpenFairyGuiBackendPromptName,
|
|
17
|
-
} from './prompt-definitions.js';
|
|
18
|
-
export {
|
|
19
|
-
OPENFAIRYGUI_BACKEND_CAPABILITIES_RESOURCE_URI,
|
|
20
|
-
OPENFAIRYGUI_BACKEND_RESOURCE_TEMPLATES,
|
|
21
|
-
} from './resource-definitions.js';
|
|
22
|
-
export {
|
|
23
|
-
OPENFAIRYGUI_BACKEND_TOOL_DEFINITIONS,
|
|
24
|
-
OPENFAIRYGUI_BACKEND_TOOL_NAMES,
|
|
25
|
-
OPENFAIRYGUI_BACKEND_TOOL_PREFIX,
|
|
26
|
-
type BackendMethodName,
|
|
27
|
-
type OpenFairyGuiBackendToolDefinition,
|
|
28
|
-
type OpenFairyGuiBackendToolName,
|
|
29
|
-
} from './tool-definitions.js';
|
|
30
|
-
export {
|
|
31
|
-
getOpenFairyGuiOperationCatalog,
|
|
32
|
-
getOpenFairyGuiOperationSchema,
|
|
33
|
-
OPENFAIRYGUI_OPERATION_CATALOG_URI,
|
|
34
|
-
OPENFAIRYGUI_OPERATION_SCHEMA_TEMPLATE,
|
|
35
|
-
} from './contract-schema.js';
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { GetPromptResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
|
|
3
|
-
export const OPENFAIRYGUI_BACKEND_PROMPT_NAMES = [
|
|
4
|
-
'openfairygui_inspect_capabilities',
|
|
5
|
-
'openfairygui_open_and_inspect_session',
|
|
6
|
-
'openfairygui_inspect_project_outline',
|
|
7
|
-
'openfairygui_plan_revision_checked_transaction',
|
|
8
|
-
'openfairygui_save_session',
|
|
9
|
-
'openfairygui_poll_runtime_state',
|
|
10
|
-
] as const;
|
|
11
|
-
|
|
12
|
-
export type OpenFairyGuiBackendPromptName = typeof OPENFAIRYGUI_BACKEND_PROMPT_NAMES[number];
|
|
13
|
-
|
|
14
|
-
interface OpenFairyGuiBackendPromptDefinition {
|
|
15
|
-
name: OpenFairyGuiBackendPromptName;
|
|
16
|
-
title: string;
|
|
17
|
-
description: string;
|
|
18
|
-
text: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const OPENFAIRYGUI_BACKEND_PROMPT_DEFINITIONS = [
|
|
22
|
-
{
|
|
23
|
-
name: 'openfairygui_inspect_capabilities',
|
|
24
|
-
title: 'Inspect OpenFairyGUI Backend Capabilities',
|
|
25
|
-
description: 'Guide a client through the capability and version discovery tool.',
|
|
26
|
-
text: [
|
|
27
|
-
'Use openfairygui_backend_get_capabilities first.',
|
|
28
|
-
'Read contractVersion, capabilitySchemaVersion, capability planes, methods, and runtime non-goals from the backend envelope.',
|
|
29
|
-
'Do not infer artifact publish/restore, subscriptions, or cache source-of-truth support when the backend marks them unsupported.',
|
|
30
|
-
].join('\n'),
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: 'openfairygui_open_and_inspect_session',
|
|
34
|
-
title: 'Open and Inspect an OpenFairyGUI Session',
|
|
35
|
-
description: 'Guide a client through opening and reading a backend session.',
|
|
36
|
-
text: [
|
|
37
|
-
'Use openfairygui_backend_open_session with a projectPath, then use openfairygui_backend_get_session with the returned sessionId.',
|
|
38
|
-
'Backend path policy remains authoritative for project paths and save targets; MCP roots are only client context in this package.',
|
|
39
|
-
'Close the session with openfairygui_backend_close_session when finished.',
|
|
40
|
-
].join('\n'),
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'openfairygui_inspect_project_outline',
|
|
44
|
-
title: 'Inspect an OpenFairyGUI Project Outline',
|
|
45
|
-
description: 'Guide a client through selector discovery before a revision-checked transaction.',
|
|
46
|
-
text: [
|
|
47
|
-
'Use openfairygui_backend_get_project_outline with the active sessionId before planning mutations.',
|
|
48
|
-
'Use package, resource, folder, display node, controller page, and transition identities from the returned outline.',
|
|
49
|
-
'Pass the returned revision as expectedRevision when calling openfairygui_backend_apply_transaction.',
|
|
50
|
-
'Read a new outline if the backend reports a stale revision; the outline intentionally excludes source bytes and full property payloads.',
|
|
51
|
-
].join('\n'),
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'openfairygui_plan_revision_checked_transaction',
|
|
55
|
-
title: 'Plan a Revision-Checked OpenFairyGUI Transaction',
|
|
56
|
-
description: 'Guide a client through backend-owned revision checks without inventing operation grammar.',
|
|
57
|
-
text: [
|
|
58
|
-
'Use openfairygui_backend_get_session to read the current revision before mutation.',
|
|
59
|
-
'Use openfairygui_backend_get_project_outline for identities, then openfairygui_backend_query_entity for current properties at the returned revision.',
|
|
60
|
-
'For settings edits, query target {kind:"project"} or {kind:"package",selector:{packageId}}; copy entity.properties.settings, change the requested fields, and submit the complete settings to updateProjectSettings or updatePackageSettings.',
|
|
61
|
-
'Read openfairygui://contracts/operations and openfairygui://contracts/operations/{kind} for the current operation names and exact JSON parameters.',
|
|
62
|
-
'Call openfairygui_backend_preflight_transaction with the queried revision and planned operations to execute and discard an isolated preview; inspect the backend diagnostics.',
|
|
63
|
-
'A successful preview does not reserve a revision or guarantee save. Apply the same batch with expectedRevision set to the preview baseRevision; refresh properties and re-plan on stale revision.',
|
|
64
|
-
'Call openfairygui_backend_apply_transaction with sessionId, expectedRevision, and backend/UAM-owned operations.',
|
|
65
|
-
'If the backend returns a stale revision error, refresh the session snapshot and re-plan against the new revision.',
|
|
66
|
-
'Do not invent selector grammar, transaction grammar, or operation payload semantics at the MCP layer.',
|
|
67
|
-
].join('\n'),
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
name: 'openfairygui_save_session',
|
|
71
|
-
title: 'Save an OpenFairyGUI Backend Session',
|
|
72
|
-
description: 'Guide a client through coordinated backend save semantics.',
|
|
73
|
-
text: [
|
|
74
|
-
'Use openfairygui_backend_save_session with sessionId and expectedRevision when available.',
|
|
75
|
-
'Backend path policy remains authoritative for targetPath; MCP does not canonicalize or authorize paths.',
|
|
76
|
-
'Handle stale revision and partial save failure envelopes from the backend without rewriting their error semantics.',
|
|
77
|
-
].join('\n'),
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
name: 'openfairygui_poll_runtime_state',
|
|
81
|
-
title: 'Poll OpenFairyGUI Runtime State',
|
|
82
|
-
description: 'Guide a client through event polling and synchronous cache snapshots.',
|
|
83
|
-
text: [
|
|
84
|
-
'Use openfairygui_backend_get_events for polling events with the backend cursor contract.',
|
|
85
|
-
'Use openfairygui_backend_get_cache_snapshot for derived read-only cache state; openfairygui_backend_refresh_cache returns the refreshed snapshot synchronously.',
|
|
86
|
-
'Subscriptions and cache-as-source-of-truth behavior are not supported by the backend.',
|
|
87
|
-
].join('\n'),
|
|
88
|
-
},
|
|
89
|
-
] as const satisfies readonly OpenFairyGuiBackendPromptDefinition[];
|
|
90
|
-
|
|
91
|
-
function promptResult(text: string): GetPromptResult {
|
|
92
|
-
return {
|
|
93
|
-
messages: [
|
|
94
|
-
{
|
|
95
|
-
role: 'user',
|
|
96
|
-
content: {
|
|
97
|
-
type: 'text',
|
|
98
|
-
text,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function registerOpenFairyGuiBackendPrompts(server: {
|
|
106
|
-
registerPrompt: (
|
|
107
|
-
name: string,
|
|
108
|
-
config: { title?: string; description?: string },
|
|
109
|
-
callback: () => GetPromptResult,
|
|
110
|
-
) => unknown;
|
|
111
|
-
}): void {
|
|
112
|
-
for (const definition of OPENFAIRYGUI_BACKEND_PROMPT_DEFINITIONS) {
|
|
113
|
-
server.registerPrompt(
|
|
114
|
-
definition.name,
|
|
115
|
-
{
|
|
116
|
-
title: definition.title,
|
|
117
|
-
description: definition.description,
|
|
118
|
-
},
|
|
119
|
-
() => promptResult(definition.text),
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { ResourceTemplate, type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import { BACKEND_DIAGNOSTICS_URI, BACKEND_DIAGNOSTIC_TEMPLATE, getBackendDiagnosticCatalog, getBackendDiagnosticGuide } from '@openfairygui/backend';
|
|
4
|
-
import { getInstalledDocumentationIndex, readInstalledDocumentation, OPENFAIRYGUI_DOCS_INDEX_URI } from '@openfairygui/backend/docs';
|
|
5
|
-
import type { OpenFairyGuiBackendRuntime } from './tool-handler.js';
|
|
6
|
-
import {
|
|
7
|
-
getOpenFairyGuiOperationCatalog,
|
|
8
|
-
getOpenFairyGuiOperationSchema,
|
|
9
|
-
OPENFAIRYGUI_OPERATION_CATALOG_URI,
|
|
10
|
-
OPENFAIRYGUI_OPERATION_SCHEMA_TEMPLATE,
|
|
11
|
-
} from './contract-schema.js';
|
|
12
|
-
|
|
13
|
-
const JSON_MIME_TYPE = 'application/json';
|
|
14
|
-
|
|
15
|
-
function firstVariable(value: string | string[] | undefined): string {
|
|
16
|
-
return Array.isArray(value) ? value[0] ?? '' : value ?? '';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function jsonResource(uri: URL, backendResult: unknown): ReadResourceResult {
|
|
20
|
-
return {
|
|
21
|
-
contents: [
|
|
22
|
-
{
|
|
23
|
-
uri: uri.toString(),
|
|
24
|
-
mimeType: JSON_MIME_TYPE,
|
|
25
|
-
text: JSON.stringify(backendResult, null, 2),
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const OPENFAIRYGUI_BACKEND_CAPABILITIES_RESOURCE_URI = 'openfairygui://backend/capabilities';
|
|
32
|
-
|
|
33
|
-
export const OPENFAIRYGUI_BACKEND_RESOURCE_TEMPLATES = [
|
|
34
|
-
'openfairygui://docs/methods/{method}',
|
|
35
|
-
'openfairygui://docs/cli/{command}',
|
|
36
|
-
BACKEND_DIAGNOSTIC_TEMPLATE,
|
|
37
|
-
OPENFAIRYGUI_OPERATION_SCHEMA_TEMPLATE,
|
|
38
|
-
'openfairygui://backend/session/{sessionId}',
|
|
39
|
-
'openfairygui://backend/session/{sessionId}/outline',
|
|
40
|
-
'openfairygui://backend/cache/{sessionId}',
|
|
41
|
-
] as const;
|
|
42
|
-
|
|
43
|
-
export function registerOpenFairyGuiBackendResources(server: McpServer, runtime: OpenFairyGuiBackendRuntime): void {
|
|
44
|
-
server.registerResource(
|
|
45
|
-
'openfairygui_docs_index', OPENFAIRYGUI_DOCS_INDEX_URI,
|
|
46
|
-
{ title: 'Installed Documentation', description: 'Offline documentation IDs, URIs, installed package version and contract digest shared with the CLI.', mimeType: JSON_MIME_TYPE },
|
|
47
|
-
(uri) => jsonResource(uri, getInstalledDocumentationIndex()),
|
|
48
|
-
);
|
|
49
|
-
function installedDocument(uri: URL, id: string): ReadResourceResult {
|
|
50
|
-
const document = readInstalledDocumentation(id);
|
|
51
|
-
return { contents: [{ uri: uri.toString(), mimeType: document.mimeType, text: document.text }] };
|
|
52
|
-
}
|
|
53
|
-
for (const id of ['workflow', 'restore-limits', 'skill', 'contracts']) {
|
|
54
|
-
server.registerResource(
|
|
55
|
-
`openfairygui_docs_${id}`, `openfairygui://docs/${id}`,
|
|
56
|
-
{ title: `Installed ${id}`, description: 'Read the installed-version corpus without repository or network access.', mimeType: id === 'contracts' ? JSON_MIME_TYPE : 'text/markdown' },
|
|
57
|
-
(uri) => installedDocument(uri, id),
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
server.registerResource(
|
|
61
|
-
'openfairygui_docs_method', new ResourceTemplate('openfairygui://docs/methods/{method}', { list: undefined }),
|
|
62
|
-
{ title: 'Installed Method Contract', description: 'Read self-contained Backend/MCP wire input/output schemas and metadata.', mimeType: JSON_MIME_TYPE },
|
|
63
|
-
(uri, variables) => installedDocument(uri, `methods/${firstVariable(variables.method)}`),
|
|
64
|
-
);
|
|
65
|
-
server.registerResource(
|
|
66
|
-
'openfairygui_diagnostic_catalog', BACKEND_DIAGNOSTICS_URI,
|
|
67
|
-
{ title: 'Diagnostic Recovery Catalog', description: 'Complete formal diagnostic ownership and recovery guidance; never automatic repair.', mimeType: JSON_MIME_TYPE },
|
|
68
|
-
(uri) => jsonResource(uri, getBackendDiagnosticCatalog()),
|
|
69
|
-
);
|
|
70
|
-
server.registerResource(
|
|
71
|
-
'openfairygui_docs_cli', new ResourceTemplate('openfairygui://docs/cli/{command}', { list: undefined }),
|
|
72
|
-
{ title: 'Installed CLI Output Contract', description: 'Read a generated, self-contained CLI JSON envelope schema.', mimeType: JSON_MIME_TYPE },
|
|
73
|
-
(uri, variables) => installedDocument(uri, `cli/${decodeURIComponent(firstVariable(variables.command))}`),
|
|
74
|
-
);
|
|
75
|
-
server.registerResource(
|
|
76
|
-
'openfairygui_diagnostic_guide', new ResourceTemplate(BACKEND_DIAGNOSTIC_TEMPLATE, { list: undefined }),
|
|
77
|
-
{ title: 'Diagnostic Recovery Guide', description: 'Read the recovery boundary for one stable diagnostic code.', mimeType: JSON_MIME_TYPE },
|
|
78
|
-
(uri, variables) => jsonResource(uri, getBackendDiagnosticGuide(firstVariable(variables.code))),
|
|
79
|
-
);
|
|
80
|
-
server.registerResource(
|
|
81
|
-
'openfairygui_operation_catalog', OPENFAIRYGUI_OPERATION_CATALOG_URI,
|
|
82
|
-
{ title: 'UAM Operation Catalog', description: 'Discover current operations and their generated JSON schemas.', mimeType: JSON_MIME_TYPE },
|
|
83
|
-
(uri) => jsonResource(uri, getOpenFairyGuiOperationCatalog()),
|
|
84
|
-
);
|
|
85
|
-
server.registerResource(
|
|
86
|
-
'openfairygui_operation_schema',
|
|
87
|
-
new ResourceTemplate(OPENFAIRYGUI_OPERATION_SCHEMA_TEMPLATE, { list: undefined }),
|
|
88
|
-
{ title: 'UAM Operation Schema', description: 'Read the precise Core-derived JSON wire schema for one operation. Structure is not semantic preflight.', mimeType: JSON_MIME_TYPE },
|
|
89
|
-
(uri, variables) => jsonResource(uri, getOpenFairyGuiOperationSchema(firstVariable(variables.kind))),
|
|
90
|
-
);
|
|
91
|
-
server.registerResource(
|
|
92
|
-
'openfairygui_backend_capabilities',
|
|
93
|
-
OPENFAIRYGUI_BACKEND_CAPABILITIES_RESOURCE_URI,
|
|
94
|
-
{
|
|
95
|
-
title: 'OpenFairyGUI Backend Capabilities',
|
|
96
|
-
description: 'Read the backend capability and version envelope as JSON.',
|
|
97
|
-
mimeType: JSON_MIME_TYPE,
|
|
98
|
-
},
|
|
99
|
-
(uri: URL) => jsonResource(uri, runtime.getCapabilities()),
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
server.registerResource(
|
|
103
|
-
'openfairygui_backend_session',
|
|
104
|
-
new ResourceTemplate('openfairygui://backend/session/{sessionId}', { list: undefined }),
|
|
105
|
-
{
|
|
106
|
-
title: 'OpenFairyGUI Backend Session Snapshot',
|
|
107
|
-
description: 'Read a backend session envelope by backend-local session id.',
|
|
108
|
-
mimeType: JSON_MIME_TYPE,
|
|
109
|
-
},
|
|
110
|
-
(uri: URL, variables) => jsonResource(uri, runtime.getSession({
|
|
111
|
-
sessionId: firstVariable(variables.sessionId),
|
|
112
|
-
})),
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
server.registerResource(
|
|
116
|
-
'openfairygui_backend_project_outline',
|
|
117
|
-
new ResourceTemplate('openfairygui://backend/session/{sessionId}/outline', { list: undefined }),
|
|
118
|
-
{
|
|
119
|
-
title: 'OpenFairyGUI Project Outline',
|
|
120
|
-
description: 'Read a revision-bound project identity outline without source bytes or full property payloads.',
|
|
121
|
-
mimeType: JSON_MIME_TYPE,
|
|
122
|
-
},
|
|
123
|
-
(uri: URL, variables) => jsonResource(uri, runtime.getProjectOutline({
|
|
124
|
-
sessionId: firstVariable(variables.sessionId),
|
|
125
|
-
})),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
server.registerResource(
|
|
129
|
-
'openfairygui_backend_cache',
|
|
130
|
-
new ResourceTemplate('openfairygui://backend/cache/{sessionId}', { list: undefined }),
|
|
131
|
-
{
|
|
132
|
-
title: 'OpenFairyGUI Backend Cache Snapshot',
|
|
133
|
-
description: 'Read a derived backend cache envelope by backend-local session id.',
|
|
134
|
-
mimeType: JSON_MIME_TYPE,
|
|
135
|
-
},
|
|
136
|
-
(uri: URL, variables) => jsonResource(uri, runtime.getCacheSnapshot({
|
|
137
|
-
sessionId: firstVariable(variables.sessionId),
|
|
138
|
-
})),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
}
|
package/src/server.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import { createNodeBackendRuntime } from '@openfairygui/backend/node';
|
|
3
|
-
import { createRequire } from 'node:module';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import { registerOpenFairyGuiBackendPrompts } from './prompt-definitions.js';
|
|
6
|
-
import { registerOpenFairyGuiBackendResources } from './resource-definitions.js';
|
|
7
|
-
import { compactToolSchema, CONTRACT_SNAPSHOT } from './contract-schema.js';
|
|
8
|
-
import { callOpenFairyGuiBackendTool, type OpenFairyGuiBackendRuntime, type OpenFairyGuiMcpToolPolicy } from './tool-handler.js';
|
|
9
|
-
import {
|
|
10
|
-
OPENFAIRYGUI_BACKEND_TOOL_DEFINITIONS,
|
|
11
|
-
type OpenFairyGuiBackendToolName,
|
|
12
|
-
} from './tool-definitions.js';
|
|
13
|
-
|
|
14
|
-
const require = createRequire(import.meta.url);
|
|
15
|
-
declare const __OPENFAIRYGUI_PACKAGE_VERSION__: string | undefined;
|
|
16
|
-
|
|
17
|
-
function getInjectedPackageVersion(): string | null {
|
|
18
|
-
const version = typeof __OPENFAIRYGUI_PACKAGE_VERSION__ === 'string' ? __OPENFAIRYGUI_PACKAGE_VERSION__ : null;
|
|
19
|
-
return typeof version === 'string' && version.length > 0 ? version : null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function readPackageVersion(): string {
|
|
23
|
-
const injectedVersion = getInjectedPackageVersion();
|
|
24
|
-
if (injectedVersion) return injectedVersion;
|
|
25
|
-
try {
|
|
26
|
-
const pkg = require('../package.json') as { version?: unknown };
|
|
27
|
-
if (typeof pkg.version === 'string' && pkg.version.length > 0) {
|
|
28
|
-
return pkg.version;
|
|
29
|
-
}
|
|
30
|
-
} catch {
|
|
31
|
-
// Keep the MCP server usable when executed from a bundled artifact missing package.json.
|
|
32
|
-
}
|
|
33
|
-
return '0.0.0-dev';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const PACKAGE_VERSION = readPackageVersion();
|
|
37
|
-
|
|
38
|
-
export interface CreateOpenFairyGuiMcpServerOptions {
|
|
39
|
-
runtime?: OpenFairyGuiBackendRuntime;
|
|
40
|
-
/** Filesystem roots exposed by the default Node backend runtime. Defaults to process.cwd(). */
|
|
41
|
-
allowedProjectRoots?: readonly string[];
|
|
42
|
-
name?: string;
|
|
43
|
-
version?: string;
|
|
44
|
-
/** Host guidance returned by the SDK initialize handshake. */
|
|
45
|
-
instructions?: string;
|
|
46
|
-
/** Per-tool Host failures do not change the canonical Backend contracts. */
|
|
47
|
-
toolPolicies?: Partial<Record<OpenFairyGuiBackendToolName, OpenFairyGuiMcpToolPolicy>>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function createOpenFairyGuiMcpServer(options: CreateOpenFairyGuiMcpServerOptions = {}): McpServer {
|
|
51
|
-
for (const name of Object.keys(options.toolPolicies ?? {})) {
|
|
52
|
-
if (!OPENFAIRYGUI_BACKEND_TOOL_DEFINITIONS.some((definition) => definition.name === name)) {
|
|
53
|
-
throw new RangeError(`Unknown OpenFairyGUI backend MCP tool policy: ${name}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const runtime = options.runtime ?? createNodeBackendRuntime({
|
|
57
|
-
allowedProjectRoots: options.allowedProjectRoots ?? [process.cwd()],
|
|
58
|
-
});
|
|
59
|
-
const server = new McpServer({
|
|
60
|
-
name: options.name ?? 'openfairygui-mcp',
|
|
61
|
-
version: options.version ?? PACKAGE_VERSION,
|
|
62
|
-
}, { instructions: options.instructions });
|
|
63
|
-
|
|
64
|
-
for (const definition of OPENFAIRYGUI_BACKEND_TOOL_DEFINITIONS) {
|
|
65
|
-
const policy = options.toolPolicies?.[definition.name];
|
|
66
|
-
const outputSchema = policy ? definition.outputSchema.extend({
|
|
67
|
-
backendResult: z.union([definition.outputSchema.shape.backendResult, policy.failureSchema]),
|
|
68
|
-
}) : definition.outputSchema;
|
|
69
|
-
const metadata = {
|
|
70
|
-
name: definition.name, title: definition.title, description: definition.description,
|
|
71
|
-
annotations: definition.annotations,
|
|
72
|
-
_meta: {
|
|
73
|
-
'openfairygui/backendMethod': definition.backendMethod,
|
|
74
|
-
'openfairygui/adapter': 'thin-backend-p2',
|
|
75
|
-
'openfairygui/contractDigest': CONTRACT_SNAPSHOT.digest,
|
|
76
|
-
...(policy ? { 'openfairygui/hostPolicy': true } : {}),
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
server.registerTool(
|
|
80
|
-
definition.name,
|
|
81
|
-
{
|
|
82
|
-
...metadata,
|
|
83
|
-
inputSchema: compactToolSchema(definition.inputSchema, 'input'),
|
|
84
|
-
outputSchema: compactToolSchema(outputSchema, 'output'),
|
|
85
|
-
},
|
|
86
|
-
async (args: Record<string, unknown>) => callOpenFairyGuiBackendTool(runtime, definition.name, args, policy),
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
registerOpenFairyGuiBackendResources(server, runtime);
|
|
91
|
-
registerOpenFairyGuiBackendPrompts(server);
|
|
92
|
-
|
|
93
|
-
return server;
|
|
94
|
-
}
|
package/src/stdio.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { createOpenFairyGuiMcpServer } from './server.js';
|
|
5
|
-
|
|
6
|
-
export async function connectOpenFairyGuiMcpStdio(): Promise<void> {
|
|
7
|
-
const configuredRoots = process.env.OPENFAIRYGUI_ALLOWED_PROJECT_ROOTS
|
|
8
|
-
?.split(path.delimiter)
|
|
9
|
-
.map((value) => value.trim())
|
|
10
|
-
.filter(Boolean);
|
|
11
|
-
const server = createOpenFairyGuiMcpServer({ allowedProjectRoots: configuredRoots });
|
|
12
|
-
await server.connect(new StdioServerTransport());
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
16
|
-
connectOpenFairyGuiMcpStdio().catch((error: unknown) => {
|
|
17
|
-
console.error(error instanceof Error ? error.stack ?? error.message : String(error));
|
|
18
|
-
process.exitCode = 1;
|
|
19
|
-
});
|
|
20
|
-
}
|
package/src/tool-definitions.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
import type { BackendMethodName } from '@openfairygui/backend';
|
|
3
|
-
import { contractObjectSchema, CONTRACT_SNAPSHOT } from './contract-schema.js';
|
|
4
|
-
import { OPENFAIRYGUI_BACKEND_TOOL_METADATA, type BackendToolMetadata } from './tool-metadata.js';
|
|
5
|
-
|
|
6
|
-
export const OPENFAIRYGUI_BACKEND_TOOL_PREFIX = 'openfairygui_backend_';
|
|
7
|
-
export type { BackendMethodName };
|
|
8
|
-
export type OpenFairyGuiBackendToolName = typeof OPENFAIRYGUI_BACKEND_TOOL_METADATA[number]['name'];
|
|
9
|
-
export const OPENFAIRYGUI_BACKEND_TOOL_NAMES = OPENFAIRYGUI_BACKEND_TOOL_METADATA.map((entry) => entry.name);
|
|
10
|
-
|
|
11
|
-
export interface OpenFairyGuiBackendToolDefinition extends BackendToolMetadata {
|
|
12
|
-
name: OpenFairyGuiBackendToolName;
|
|
13
|
-
inputSchema: z.ZodObject;
|
|
14
|
-
outputSchema: z.ZodObject;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function isOpenFairyGuiMcpPayloadWithinBudget(root: unknown, bytePaths: readonly string[][] = []): boolean {
|
|
18
|
-
const pending: Array<{ value: unknown; path: string[] }> = [{ value: root, path: [] }];
|
|
19
|
-
let nodes = 0, binaryBytes = 0;
|
|
20
|
-
while (pending.length > 0) {
|
|
21
|
-
const { value, path } = pending.pop()!;
|
|
22
|
-
nodes += 1;
|
|
23
|
-
if (nodes > 100_000 || path.length > 32) return false;
|
|
24
|
-
if (value === null || typeof value === 'boolean') continue;
|
|
25
|
-
if (typeof value === 'number') {
|
|
26
|
-
if (!Number.isFinite(value)) return false;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (typeof value === 'string') {
|
|
30
|
-
if (value.length > 1_000_000) return false;
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (value instanceof Uint8Array) {
|
|
34
|
-
binaryBytes += value.byteLength;
|
|
35
|
-
if (binaryBytes > 8 * 1024 * 1024) return false;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (Array.isArray(value)) {
|
|
39
|
-
if (bytePaths.some((parts) => parts.length === path.length && parts.every((part, index) => part === '*' || part === path[index]))) {
|
|
40
|
-
binaryBytes += value.length;
|
|
41
|
-
if (binaryBytes > 8 * 1024 * 1024 || !value.every((byte) => Number.isInteger(byte) && byte >= 0 && byte <= 255)) return false;
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (value.length > 10_000) return false;
|
|
45
|
-
for (const [index, child] of value.entries()) pending.push({ value: child, path: [...path, String(index)] });
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (typeof value !== 'object') return false;
|
|
49
|
-
const entries = Object.entries(value);
|
|
50
|
-
if (entries.length > 10_000 || entries.some(([key]) => key.length > 256)) return false;
|
|
51
|
-
for (const [key, child] of entries) pending.push({ value: child, path: [...path, key] });
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const OPENFAIRYGUI_BACKEND_TOOL_DEFINITIONS: readonly OpenFairyGuiBackendToolDefinition[] =
|
|
57
|
-
OPENFAIRYGUI_BACKEND_TOOL_METADATA.map((metadata) => {
|
|
58
|
-
const contract = CONTRACT_SNAPSHOT.tools[metadata.backendMethod];
|
|
59
|
-
return {
|
|
60
|
-
...metadata,
|
|
61
|
-
inputSchema: contractObjectSchema(contract.input),
|
|
62
|
-
outputSchema: contractObjectSchema(contract.output),
|
|
63
|
-
};
|
|
64
|
-
});
|