@enhance-eng/enhance 0.1.6 → 0.1.7
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/dist/{capability-inventory.mapper-DN3TEDbU.mjs → capability-inventory.mapper-DyYXyVBJ.mjs} +2 -1
- package/dist/{failure.mapper-CNRVSTrf.mjs → cli-output-identity.lib-BSUBcRJm.mjs} +960 -140
- package/dist/{file-credential.adapter-WNl4GM58.mjs → file-credential.adapter-rI5HpMEo.mjs} +3 -1
- package/dist/main.mjs +406 -334
- package/dist/mcp-invocation.adapter-Bn41hcLB.mjs +64 -0
- package/dist/mcp-main.mjs +159 -9
- package/dist/{mcp-server.adapter-T8UqHf6A.mjs → mcp-server.adapter-lxpsuDlU.mjs} +145 -144
- package/dist/mcp.mjs +5 -4
- package/dist/{mutation-key.adapter-B7Ss_464.mjs → mutation-key.adapter-EvvklGSw.mjs} +267 -26
- package/dist/remote-mcp-main.mjs +11 -8
- package/package.json +1 -1
- package/dist/mcp-invocation.adapter-D0o0vb_-.mjs +0 -17
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as createOauthLoopbackAdapter, f as createAuthUseCase, n as createHttpRemoteAdapter, o as createCapabilityInvocationAdapter, t as createMutationKeyAdapter } from "./mutation-key.adapter-EvvklGSw.mjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/infrastructure/mcp-invocation.adapter.ts
|
|
6
|
+
const TRANSPORT_CAPABILITIES = /* @__PURE__ */ new Set([
|
|
7
|
+
"auth.login",
|
|
8
|
+
"auth.logout",
|
|
9
|
+
"auth.status",
|
|
10
|
+
"doctor"
|
|
11
|
+
]);
|
|
12
|
+
const loginInputSchema = z.object({ openBrowser: z.boolean() });
|
|
13
|
+
const invokeTransport = async (input) => {
|
|
14
|
+
const auth = createAuthUseCase(input.credentials, input.remote, createOauthLoopbackAdapter(input.remote));
|
|
15
|
+
switch (input.capability) {
|
|
16
|
+
case "auth.login": {
|
|
17
|
+
const offered = loginInputSchema.parse(input.arguments);
|
|
18
|
+
return auth.loginWithBrowser({
|
|
19
|
+
label: "Agent plugin",
|
|
20
|
+
openBrowser: offered.openBrowser,
|
|
21
|
+
onReady: () => null
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
case "auth.logout": return auth.logout();
|
|
25
|
+
case "auth.status":
|
|
26
|
+
if (await input.credentials.read() === null) return { authenticated: false };
|
|
27
|
+
return auth.status();
|
|
28
|
+
case "doctor": {
|
|
29
|
+
const [api, credential] = await Promise.all([input.remote.health(), input.credentials.read()]);
|
|
30
|
+
return {
|
|
31
|
+
status: credential !== null && api.reachable ? "ok" : "degraded",
|
|
32
|
+
runtimeVersion: input.version,
|
|
33
|
+
api: {
|
|
34
|
+
reachable: api.reachable,
|
|
35
|
+
status: api.status,
|
|
36
|
+
...api.error !== void 0 && { error: api.error }
|
|
37
|
+
},
|
|
38
|
+
credential: { present: credential !== null }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
default: throw new TypeError(`${input.capability} has no MCP transport execution`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const createMcpInvocationAdapter = (apiUrl, credentials, configDirectory, version) => {
|
|
45
|
+
const transportRemote = createHttpRemoteAdapter(apiUrl, credentials, createMutationKeyAdapter());
|
|
46
|
+
return { invoke: async (request) => {
|
|
47
|
+
if (TRANSPORT_CAPABILITIES.has(request.capability.id)) return invokeTransport({
|
|
48
|
+
capability: request.capability.id,
|
|
49
|
+
arguments: request.arguments,
|
|
50
|
+
credentials,
|
|
51
|
+
remote: transportRemote,
|
|
52
|
+
version
|
|
53
|
+
});
|
|
54
|
+
const mutationKey = createMutationKeyAdapter();
|
|
55
|
+
return createCapabilityInvocationAdapter({
|
|
56
|
+
remote: createHttpRemoteAdapter(apiUrl, credentials, mutationKey),
|
|
57
|
+
mutationKey,
|
|
58
|
+
configDirectory
|
|
59
|
+
}).invoke(request);
|
|
60
|
+
} };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { createMcpInvocationAdapter as t };
|
package/dist/mcp-main.mjs
CHANGED
|
@@ -1,19 +1,169 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import { t as
|
|
2
|
+
import { f as toCapabilityDefinition, l as createCapabilityCatalogAdapter } from "./cli-output-identity.lib-BSUBcRJm.mjs";
|
|
3
|
+
import { r as CLI_CONFIG } from "./mutation-key.adapter-EvvklGSw.mjs";
|
|
4
|
+
import { t as createFileCredentialAdapter } from "./file-credential.adapter-rI5HpMEo.mjs";
|
|
5
|
+
import { t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-Bn41hcLB.mjs";
|
|
6
|
+
import { t as createMcpServerAdapter } from "./mcp-server.adapter-lxpsuDlU.mjs";
|
|
7
|
+
import { z } from "zod";
|
|
6
8
|
import process from "node:process";
|
|
7
9
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
10
|
+
|
|
11
|
+
//#region src/infrastructure/mcp-transport-capability.adapter.ts
|
|
12
|
+
const unauthenticatedSchema = z.object({ authenticated: z.literal(false) });
|
|
13
|
+
const authenticatedSchema = z.object({
|
|
14
|
+
authenticated: z.literal(true),
|
|
15
|
+
personId: z.uuid(),
|
|
16
|
+
displayName: z.string().min(1),
|
|
17
|
+
tokenId: z.uuid(),
|
|
18
|
+
tokenLabel: z.string().min(1),
|
|
19
|
+
expiresAt: z.iso.datetime().nullable()
|
|
20
|
+
});
|
|
21
|
+
const loginInputSchema = z.object({ openBrowser: z.boolean().default(true).describe("Open the system browser for the human sign-in and wait for completion.") });
|
|
22
|
+
const statusInputSchema = z.strictObject({});
|
|
23
|
+
const statusOutputSchema = z.union([unauthenticatedSchema, authenticatedSchema]);
|
|
24
|
+
const logoutOutputSchema = z.object({ loggedOut: z.boolean() });
|
|
25
|
+
const doctorOutputSchema = z.object({
|
|
26
|
+
status: z.enum(["ok", "degraded"]),
|
|
27
|
+
runtimeVersion: z.string().min(1),
|
|
28
|
+
api: z.object({
|
|
29
|
+
reachable: z.boolean(),
|
|
30
|
+
status: z.number().int().nullable(),
|
|
31
|
+
error: z.string().optional()
|
|
32
|
+
}),
|
|
33
|
+
credential: z.object({ present: z.boolean() })
|
|
34
|
+
});
|
|
35
|
+
const guideFor = (input) => ({
|
|
36
|
+
summary: input.summary,
|
|
37
|
+
useWhen: input.useWhen,
|
|
38
|
+
preconditions: ["Run through the local Enhance MCP runtime, which owns the user-scoped credential.", "Keep credential values outside model-visible input and output."],
|
|
39
|
+
input: [],
|
|
40
|
+
output: [],
|
|
41
|
+
result: input.result,
|
|
42
|
+
recovery: [
|
|
43
|
+
"BAD_REQUEST: correct the named option and call again.",
|
|
44
|
+
"UNAUTHORIZED: start browser sign-in and let the person complete consent.",
|
|
45
|
+
"FORBIDDEN: leave the credential unchanged and report the governing account policy.",
|
|
46
|
+
"INTERNAL: call doctor, report the failing boundary, and stop repeating the call."
|
|
47
|
+
],
|
|
48
|
+
next: input.next,
|
|
49
|
+
examples: [{
|
|
50
|
+
input: input.exampleInput,
|
|
51
|
+
output: input.exampleOutput
|
|
52
|
+
}]
|
|
53
|
+
});
|
|
54
|
+
const definition = (input) => toCapabilityDefinition({
|
|
55
|
+
...input,
|
|
56
|
+
source: "composite",
|
|
57
|
+
idempotency: input.operation === "query" ? "none" : "single",
|
|
58
|
+
execution: {
|
|
59
|
+
kind: "composite",
|
|
60
|
+
procedures: []
|
|
61
|
+
},
|
|
62
|
+
meta: { description: input.guide.summary },
|
|
63
|
+
policy: {
|
|
64
|
+
exposure: "mcp-transport",
|
|
65
|
+
reason: "The local MCP runtime owns its own authentication and installation diagnostics.",
|
|
66
|
+
owner: "mcp"
|
|
67
|
+
},
|
|
68
|
+
cliPath: null,
|
|
69
|
+
inputExample: input.guide.examples[0]?.input,
|
|
70
|
+
outputExample: input.guide.examples[0]?.output
|
|
71
|
+
});
|
|
72
|
+
const capabilities = [
|
|
73
|
+
definition({
|
|
74
|
+
id: "auth.login",
|
|
75
|
+
operation: "mutation",
|
|
76
|
+
effect: "external",
|
|
77
|
+
inputSchema: loginInputSchema,
|
|
78
|
+
outputSchema: authenticatedSchema,
|
|
79
|
+
guide: guideFor({
|
|
80
|
+
summary: "Open browser sign-in and store a revocable user-scoped Enhance credential.",
|
|
81
|
+
useWhen: "Use when Enhance is not authenticated or its credential was revoked.",
|
|
82
|
+
result: "Waits for browser consent, stores the credential locally, and returns safe identity metadata.",
|
|
83
|
+
next: ["Call auth.status, then read the target canvas."],
|
|
84
|
+
exampleInput: { openBrowser: true },
|
|
85
|
+
exampleOutput: {
|
|
86
|
+
authenticated: true,
|
|
87
|
+
personId: "00000000-0000-4000-8000-000000000001",
|
|
88
|
+
displayName: "Ada",
|
|
89
|
+
tokenId: "00000000-0000-4000-8000-000000000002",
|
|
90
|
+
tokenLabel: "Agent plugin",
|
|
91
|
+
expiresAt: null
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
}),
|
|
95
|
+
definition({
|
|
96
|
+
id: "auth.logout",
|
|
97
|
+
operation: "mutation",
|
|
98
|
+
effect: "delete",
|
|
99
|
+
inputSchema: statusInputSchema,
|
|
100
|
+
outputSchema: logoutOutputSchema,
|
|
101
|
+
guide: guideFor({
|
|
102
|
+
summary: "Remove the user-scoped local Enhance credential.",
|
|
103
|
+
useWhen: "Use only when the person asks to disconnect this local agent host.",
|
|
104
|
+
result: "Reports whether a local credential was removed without returning its value.",
|
|
105
|
+
next: ["Call auth.status to confirm the local runtime is disconnected."],
|
|
106
|
+
exampleInput: {},
|
|
107
|
+
exampleOutput: { loggedOut: true }
|
|
108
|
+
})
|
|
109
|
+
}),
|
|
110
|
+
definition({
|
|
111
|
+
id: "auth.status",
|
|
112
|
+
operation: "query",
|
|
113
|
+
effect: "read",
|
|
114
|
+
inputSchema: statusInputSchema,
|
|
115
|
+
outputSchema: statusOutputSchema,
|
|
116
|
+
guide: guideFor({
|
|
117
|
+
summary: "Check whether the local Enhance MCP runtime is authenticated.",
|
|
118
|
+
useWhen: "Use before a workflow or after login, logout, expiry, or an authorization failure.",
|
|
119
|
+
result: "Returns safe identity metadata or authenticated false, never a credential value.",
|
|
120
|
+
next: ["When unauthenticated, call auth.login; otherwise continue with the requested workflow."],
|
|
121
|
+
exampleInput: {},
|
|
122
|
+
exampleOutput: { authenticated: false }
|
|
123
|
+
})
|
|
124
|
+
}),
|
|
125
|
+
definition({
|
|
126
|
+
id: "doctor",
|
|
127
|
+
operation: "query",
|
|
128
|
+
effect: "read",
|
|
129
|
+
inputSchema: statusInputSchema,
|
|
130
|
+
outputSchema: doctorOutputSchema,
|
|
131
|
+
guide: guideFor({
|
|
132
|
+
summary: "Check MCP runtime identity, API reachability, and credential presence without changes.",
|
|
133
|
+
useWhen: "Use after repeated connection, authentication, or compatibility failure.",
|
|
134
|
+
result: "Returns bounded diagnostics without machine paths, credentials, or customer data.",
|
|
135
|
+
next: ["Follow the failing boundary; do not repeat a mutation while diagnostics are degraded."],
|
|
136
|
+
exampleInput: {},
|
|
137
|
+
exampleOutput: {
|
|
138
|
+
status: "ok",
|
|
139
|
+
runtimeVersion: "0.1.7",
|
|
140
|
+
api: {
|
|
141
|
+
reachable: true,
|
|
142
|
+
status: 200
|
|
143
|
+
},
|
|
144
|
+
credential: { present: true }
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
].toSorted((left, right) => left.id.localeCompare(right.id));
|
|
149
|
+
const createMcpTransportCapabilityAdapter = () => capabilities;
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
8
152
|
//#region src/mcp-main.ts
|
|
9
153
|
const credentials = createFileCredentialAdapter(CLI_CONFIG.configDirectory);
|
|
10
|
-
const invocation = createMcpInvocationAdapter(CLI_CONFIG.apiUrl, credentials, CLI_CONFIG.configDirectory);
|
|
154
|
+
const invocation = createMcpInvocationAdapter(CLI_CONFIG.apiUrl, credentials, CLI_CONFIG.configDirectory, "0.1.7");
|
|
155
|
+
const catalog = [...createCapabilityCatalogAdapter(), ...createMcpTransportCapabilityAdapter()];
|
|
11
156
|
serveStdio(() => createMcpServerAdapter({
|
|
12
|
-
version: "0.1.
|
|
13
|
-
|
|
157
|
+
version: "0.1.7",
|
|
158
|
+
name: CLI_CONFIG.mcpServiceName,
|
|
159
|
+
commandName: CLI_CONFIG.commandName,
|
|
160
|
+
invocation,
|
|
161
|
+
catalog,
|
|
162
|
+
exposures: ["shared", "mcp-transport"]
|
|
14
163
|
}), {
|
|
15
164
|
legacy: "serve",
|
|
16
|
-
onerror: () => process.stderr.write(
|
|
165
|
+
onerror: () => process.stderr.write(`${CLI_CONFIG.mcpServiceName} transport failure\n`)
|
|
17
166
|
});
|
|
167
|
+
|
|
18
168
|
//#endregion
|
|
19
|
-
export {};
|
|
169
|
+
export { };
|
|
@@ -1,89 +1,60 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { C as CliError, a as toPresentedCapabilities, i as toFailurePayload, l as createCapabilityCatalogAdapter, n as withCommandName, s as createMcpCapabilityDiscoveryAdapter, t as withCommandInFailure } from "./cli-output-identity.lib-BSUBcRJm.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { readFile, rm } from "node:fs/promises";
|
|
6
6
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const id = normalized(capability.id);
|
|
18
|
-
if (query === id) return EXACT_ID_SCORE;
|
|
19
|
-
const idSegments = new Set(id.split(" "));
|
|
20
|
-
const guide = normalized([
|
|
21
|
-
capability.guide.summary,
|
|
22
|
-
capability.guide.useWhen,
|
|
23
|
-
...capability.guide.preconditions,
|
|
24
|
-
...capability.guide.input.map((field) => `${field.name} ${field.meaning}`),
|
|
25
|
-
...capability.guide.output.map((field) => `${field.name} ${field.meaning}`),
|
|
26
|
-
...capability.guide.next
|
|
27
|
-
].join(" "));
|
|
28
|
-
const terms = query.split(" ").filter((term) => term !== "");
|
|
29
|
-
let score = id.startsWith(query) ? ID_PREFIX_SCORE : NO_MATCH_SCORE;
|
|
30
|
-
for (const term of terms) {
|
|
31
|
-
if (idSegments.has(term)) score += ID_SEGMENT_SCORE;
|
|
32
|
-
else if (id.includes(term)) score += ID_SUBSTRING_SCORE;
|
|
33
|
-
if (guide.includes(term)) score += GUIDE_MATCH_SCORE;
|
|
34
|
-
}
|
|
35
|
-
return score;
|
|
7
|
+
|
|
8
|
+
//#region src/infrastructure/capability-catalogue-text.mapper.ts
|
|
9
|
+
const MAX_LINE_CHARACTERS = 180;
|
|
10
|
+
const MAX_CATALOGUE_BYTES = 24 * 1024;
|
|
11
|
+
const oneLine = (value) => value.replaceAll(/\s+/gu, " ").trim();
|
|
12
|
+
const lineFor = (capability) => {
|
|
13
|
+
const prefix = `${capability.id} [${capability.effect}] — `;
|
|
14
|
+
const summary = oneLine(capability.guide.summary);
|
|
15
|
+
const available = MAX_LINE_CHARACTERS - prefix.length;
|
|
16
|
+
return `${prefix}${summary.slice(0, available)}`;
|
|
36
17
|
};
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
const toCapabilityCatalogueText = (catalog, serverVersion) => {
|
|
19
|
+
const lines = catalog.toSorted((left, right) => left.id.localeCompare(right.id)).map((capability) => lineFor(capability));
|
|
20
|
+
const digest = createHash("sha256").update(lines.join("\n")).digest("hex");
|
|
21
|
+
const text = [`Enhance MCP ${serverVersion} — ${String(lines.length)} capabilities — sha256:${digest}`, ...lines].join("\n");
|
|
22
|
+
if (Buffer.byteLength(text) > MAX_CATALOGUE_BYTES) throw new RangeError("the complete capability catalogue exceeds 24 KiB");
|
|
23
|
+
return {
|
|
24
|
+
digest,
|
|
25
|
+
text
|
|
26
|
+
};
|
|
41
27
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
})).filter((candidate) => candidate.score > NO_MATCH_SCORE).toSorted((left, right) => {
|
|
73
|
-
const scoreDifference = right.score - left.score;
|
|
74
|
-
return scoreDifference === NO_MATCH_SCORE ? left.capability.id.localeCompare(right.capability.id) : scoreDifference;
|
|
75
|
-
});
|
|
76
|
-
return {
|
|
77
|
-
matches: ranked.slice(0, input.limit).map(({ capability }) => toBrief(capability)),
|
|
78
|
-
totalMatches: ranked.length,
|
|
79
|
-
truncated: ranked.length > input.limit
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
describe: (id) => {
|
|
83
|
-
const capability = catalog.find((candidate) => candidate.id === id);
|
|
84
|
-
return capability === void 0 ? null : toContract(capability);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/infrastructure/mcp-catalogue-tool.adapter.ts
|
|
31
|
+
const createMcpCatalogueToolAdapter = (catalog, version, commandName = "enhance") => {
|
|
32
|
+
const catalogue = toCapabilityCatalogueText(catalog, version);
|
|
33
|
+
const presented = String(withCommandName(catalogue.text, commandName));
|
|
34
|
+
return { register: (server) => {
|
|
35
|
+
server.registerTool("capability_catalogue", {
|
|
36
|
+
title: "Scan every Enhance capability",
|
|
37
|
+
description: "Return the complete bounded capability inventory when the task is broad, uncertain, or capability_search does not find the right words. Call capability_describe with one exact id before invoking it.",
|
|
38
|
+
inputSchema: z.strictObject({}),
|
|
39
|
+
annotations: {
|
|
40
|
+
readOnlyHint: true,
|
|
41
|
+
destructiveHint: false,
|
|
42
|
+
idempotentHint: true,
|
|
43
|
+
openWorldHint: false
|
|
44
|
+
},
|
|
45
|
+
_meta: {
|
|
46
|
+
"ai.enhancelabs/disclosure": "progressive",
|
|
47
|
+
"ai.enhancelabs/catalogSize": catalog.length,
|
|
48
|
+
"enhance/disclosure": "progressive",
|
|
49
|
+
"enhance/catalogSize": catalog.length
|
|
50
|
+
}
|
|
51
|
+
}, () => ({ content: [{
|
|
52
|
+
type: "text",
|
|
53
|
+
text: presented
|
|
54
|
+
}] }));
|
|
55
|
+
} };
|
|
56
|
+
};
|
|
57
|
+
|
|
87
58
|
//#endregion
|
|
88
59
|
//#region src/infrastructure/mcp-progressive.schema.ts
|
|
89
60
|
const failureSchema = z.object({
|
|
@@ -164,6 +135,33 @@ const mcpDescribeResultSchema = z.union([z.object({
|
|
|
164
135
|
ok: z.literal(true),
|
|
165
136
|
result: capabilityContractSchema
|
|
166
137
|
}), failureSchema]);
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/infrastructure/mcp-describe-tool.adapter.ts
|
|
141
|
+
const describeInputSchema = z.object({ capability: z.string().min(1).describe("Exact capability id returned by capability_search or capability_catalogue.") });
|
|
142
|
+
const createMcpDescribeToolAdapter = (discovery, mcpResults) => ({ register: (server) => {
|
|
143
|
+
server.registerTool("capability_describe", {
|
|
144
|
+
title: "Load one Enhance capability contract",
|
|
145
|
+
description: "Load the exact input schema, example, preconditions, result guidance, recovery, and next steps for one id returned by capability_search or capability_catalogue.",
|
|
146
|
+
inputSchema: describeInputSchema,
|
|
147
|
+
outputSchema: mcpDescribeResultSchema,
|
|
148
|
+
annotations: {
|
|
149
|
+
readOnlyHint: true,
|
|
150
|
+
destructiveHint: false,
|
|
151
|
+
idempotentHint: true,
|
|
152
|
+
openWorldHint: false
|
|
153
|
+
},
|
|
154
|
+
_meta: {
|
|
155
|
+
"ai.enhancelabs/disclosure": "progressive",
|
|
156
|
+
"enhance/disclosure": "progressive"
|
|
157
|
+
}
|
|
158
|
+
}, ({ capability }) => {
|
|
159
|
+
const contract = discovery.describe(capability);
|
|
160
|
+
if (contract !== null) return mcpResults.inline(contract);
|
|
161
|
+
return mcpResults.failure(new CliError("BAD_REQUEST", `Unknown shared capability: ${capability}.`, "Call capability_search or capability_catalogue and use an exact id from its results.", { capability: "No shared capability has this id." }));
|
|
162
|
+
});
|
|
163
|
+
} });
|
|
164
|
+
|
|
167
165
|
//#endregion
|
|
168
166
|
//#region src/infrastructure/mcp-result.adapter.ts
|
|
169
167
|
const PROTECTED_RESULT_BYTES = 2e4;
|
|
@@ -295,16 +293,17 @@ const artifactResult = (server, serialized, delivery) => {
|
|
|
295
293
|
structuredContent
|
|
296
294
|
};
|
|
297
295
|
};
|
|
298
|
-
const validationError = (error) => new CliError("BAD_REQUEST", "Input validation error.", "Call
|
|
299
|
-
const createMcpResultAdapter = () => ({
|
|
296
|
+
const validationError = (error) => new CliError("BAD_REQUEST", "Input validation error.", "Call capability_search again and rewrite every rejected input field.", Object.fromEntries(error.issues.map((issue) => [issue.path.length === 0 ? "input" : issue.path.join("."), issue.message])));
|
|
297
|
+
const createMcpResultAdapter = (authenticationRemediation, commandName = "enhance") => ({
|
|
300
298
|
success: async (server, result, delivery) => {
|
|
301
|
-
const
|
|
299
|
+
const presented = withCommandName(result, commandName);
|
|
300
|
+
const localArtifact = await localArtifactResult(server, presented, delivery);
|
|
302
301
|
if (localArtifact !== null) return localArtifact;
|
|
303
|
-
const serialized = textFor(
|
|
304
|
-
if (Buffer.byteLength(serialized) > PROTECTED_RESULT_BYTES || hasProtectedMaterial(
|
|
302
|
+
const serialized = textFor(presented);
|
|
303
|
+
if (Buffer.byteLength(serialized) > PROTECTED_RESULT_BYTES || hasProtectedMaterial(presented)) return artifactResult(server, serialized, delivery);
|
|
305
304
|
const structuredContent = {
|
|
306
305
|
ok: true,
|
|
307
|
-
result
|
|
306
|
+
result: presented
|
|
308
307
|
};
|
|
309
308
|
return {
|
|
310
309
|
content: [{
|
|
@@ -317,7 +316,7 @@ const createMcpResultAdapter = () => ({
|
|
|
317
316
|
inline: (result) => {
|
|
318
317
|
const structuredContent = {
|
|
319
318
|
ok: true,
|
|
320
|
-
result
|
|
319
|
+
result: withCommandName(result, commandName)
|
|
321
320
|
};
|
|
322
321
|
return {
|
|
323
322
|
content: [{
|
|
@@ -328,9 +327,13 @@ const createMcpResultAdapter = () => ({
|
|
|
328
327
|
};
|
|
329
328
|
},
|
|
330
329
|
failure: (error) => {
|
|
330
|
+
const failure = withCommandInFailure(toFailurePayload(error instanceof z.ZodError ? validationError(error) : error, null), commandName);
|
|
331
331
|
const structuredContent = {
|
|
332
332
|
ok: false,
|
|
333
|
-
error:
|
|
333
|
+
error: failure.code === "UNAUTHORIZED" ? {
|
|
334
|
+
...failure,
|
|
335
|
+
remediation: authenticationRemediation
|
|
336
|
+
} : failure
|
|
334
337
|
};
|
|
335
338
|
return {
|
|
336
339
|
content: [{
|
|
@@ -342,15 +345,15 @@ const createMcpResultAdapter = () => ({
|
|
|
342
345
|
};
|
|
343
346
|
}
|
|
344
347
|
});
|
|
345
|
-
|
|
346
|
-
//#region src/infrastructure/shared-capabilities.mapper.ts
|
|
347
|
-
const toSharedCapabilities = (catalog) => catalog.filter((capability) => capability.policy.exposure === "shared");
|
|
348
|
+
|
|
348
349
|
//#endregion
|
|
349
350
|
//#region src/infrastructure/mcp-server.adapter.ts
|
|
350
351
|
const MAX_SEARCH_QUERY_CHARACTERS = 200;
|
|
351
352
|
const MAX_SEARCH_RESULTS = 10;
|
|
352
353
|
const DEFAULT_SEARCH_RESULTS = 5;
|
|
353
|
-
const
|
|
354
|
+
const AUTHENTICATION_INSTRUCTIONS = "Transport attachment is not Enhance sign-in, even when the host reports mcp_auth success. Use capability_query with capability auth.status to check the person. If authenticated is false or a read returns UNAUTHORIZED, use capability_mutate with capability auth.login and input {\"openBrowser\":true}, then let the person complete browser sign-in. Verify auth.status and a read such as canvas.list before reporting setup complete.";
|
|
355
|
+
const LOCAL_AUTHENTICATION_REMEDY = "Call capability_mutate with capability auth.login and input {\"openBrowser\":true}. Complete browser sign-in, then verify auth.status and a read such as canvas.list.";
|
|
356
|
+
const HOSTED_AUTHENTICATION_REMEDY = "Reconnect this hosted MCP server through your host’s browser OAuth sign-in. Then verify person.me and a read such as canvas.list.";
|
|
354
357
|
const searchInputSchema = z.object({
|
|
355
358
|
query: z.string().trim().min(1).max(MAX_SEARCH_QUERY_CHARACTERS).describe("Plain-language task, domain, or exact capability id to discover."),
|
|
356
359
|
operation: z.enum([
|
|
@@ -361,28 +364,27 @@ const searchInputSchema = z.object({
|
|
|
361
364
|
limit: z.number().int().min(1).max(MAX_SEARCH_RESULTS).default(DEFAULT_SEARCH_RESULTS).describe("Maximum contracts to return.")
|
|
362
365
|
});
|
|
363
366
|
const queryInputSchema = z.object({
|
|
364
|
-
capability: z.string().min(1).describe("Exact query id returned by
|
|
367
|
+
capability: z.string().min(1).describe("Exact query id returned by capability_describe."),
|
|
365
368
|
input: z.record(z.string(), z.unknown()).default({}).describe("Input matching the discovered capability inputSchema.")
|
|
366
369
|
});
|
|
367
370
|
const mutationInputSchema = z.object({
|
|
368
|
-
capability: z.string().min(1).describe("Exact mutation id returned by
|
|
371
|
+
capability: z.string().min(1).describe("Exact mutation id returned by capability_describe."),
|
|
369
372
|
input: z.record(z.string(), z.unknown()).default({}).describe("Input matching the discovered capability inputSchema."),
|
|
370
373
|
clientToken: z.uuid().optional().describe("Stable UUID reused only when retrying this exact mutation input.")
|
|
371
374
|
});
|
|
372
|
-
const describeInputSchema = z.object({ capability: z.string().min(1).describe("Exact capability id returned by capability.search.") });
|
|
373
375
|
const capabilityFor = (catalog, id, operation) => {
|
|
374
376
|
const capability = catalog.find((candidate) => candidate.id === id);
|
|
375
|
-
if (capability === void 0) throw new CliError("BAD_REQUEST", `Unknown shared capability: ${id}.`, "Call
|
|
377
|
+
if (capability === void 0) throw new CliError("BAD_REQUEST", `Unknown shared capability: ${id}.`, "Call capability_search or capability_catalogue and use an exact id from its results.", { capability: "No shared capability has this id." });
|
|
376
378
|
if (capability.operation !== operation) {
|
|
377
|
-
const dispatcher = capability.operation === "query" ? "
|
|
379
|
+
const dispatcher = capability.operation === "query" ? "capability_query" : "capability_mutate";
|
|
378
380
|
throw new CliError("BAD_REQUEST", `${id} is a ${capability.operation}, not a ${operation}.`, `Call ${dispatcher} with the same capability and input.`, { capability: `Use ${dispatcher} for this capability.` });
|
|
379
381
|
}
|
|
380
382
|
return capability;
|
|
381
383
|
};
|
|
382
|
-
const registerSearch = (server, catalog, discovery) => {
|
|
383
|
-
server.registerTool("
|
|
384
|
+
const registerSearch = (server, catalog, discovery, mcpResults) => {
|
|
385
|
+
server.registerTool("capability_search", {
|
|
384
386
|
title: "Discover Enhance capabilities",
|
|
385
|
-
description: "Search the
|
|
387
|
+
description: "Search the Enhance capability catalogue for a specific likely action. Returns only the most relevant summaries; use capability_catalogue when the request is broad or the matches look wrong, then call capability_describe before invoking.",
|
|
386
388
|
inputSchema: searchInputSchema,
|
|
387
389
|
outputSchema: mcpSearchResultSchema,
|
|
388
390
|
annotations: {
|
|
@@ -392,6 +394,8 @@ const registerSearch = (server, catalog, discovery) => {
|
|
|
392
394
|
openWorldHint: false
|
|
393
395
|
},
|
|
394
396
|
_meta: {
|
|
397
|
+
"ai.enhancelabs/disclosure": "progressive",
|
|
398
|
+
"ai.enhancelabs/catalogSize": catalog.length,
|
|
395
399
|
"enhance/disclosure": "progressive",
|
|
396
400
|
"enhance/catalogSize": catalog.length
|
|
397
401
|
}
|
|
@@ -401,29 +405,10 @@ const registerSearch = (server, catalog, discovery) => {
|
|
|
401
405
|
limit
|
|
402
406
|
})));
|
|
403
407
|
};
|
|
404
|
-
const
|
|
405
|
-
server.registerTool("
|
|
406
|
-
title: "Load one Enhance capability contract",
|
|
407
|
-
description: "Load the exact input schema, example, preconditions, result guidance, recovery, and next steps for one id returned by capability.search.",
|
|
408
|
-
inputSchema: describeInputSchema,
|
|
409
|
-
outputSchema: mcpDescribeResultSchema,
|
|
410
|
-
annotations: {
|
|
411
|
-
readOnlyHint: true,
|
|
412
|
-
destructiveHint: false,
|
|
413
|
-
idempotentHint: true,
|
|
414
|
-
openWorldHint: false
|
|
415
|
-
},
|
|
416
|
-
_meta: { "enhance/disclosure": "progressive" }
|
|
417
|
-
}, async ({ capability }) => {
|
|
418
|
-
const contract = discovery.describe(capability);
|
|
419
|
-
if (contract !== null) return mcpResults.inline(contract);
|
|
420
|
-
return mcpResults.failure(new CliError("BAD_REQUEST", `Unknown shared capability: ${capability}.`, "Call capability.search and use an exact id from its matches.", { capability: "No shared capability has this id." }));
|
|
421
|
-
});
|
|
422
|
-
};
|
|
423
|
-
const registerQuery = (server, catalog, invocation, delivery) => {
|
|
424
|
-
server.registerTool("capability.query", {
|
|
408
|
+
const registerQuery = (server, catalog, invocation, execution) => {
|
|
409
|
+
server.registerTool("capability_query", {
|
|
425
410
|
title: "Run a discovered Enhance query",
|
|
426
|
-
description: "Run one read-only capability using the exact id and input loaded by
|
|
411
|
+
description: "Run one read-only capability using the exact id and input loaded by capability_describe. Search and describe first whenever the contract is not already present in the conversation.",
|
|
427
412
|
inputSchema: queryInputSchema,
|
|
428
413
|
outputSchema: mcpDispatchedResultSchema,
|
|
429
414
|
annotations: {
|
|
@@ -432,23 +417,26 @@ const registerQuery = (server, catalog, invocation, delivery) => {
|
|
|
432
417
|
idempotentHint: true,
|
|
433
418
|
openWorldHint: false
|
|
434
419
|
},
|
|
435
|
-
_meta: {
|
|
420
|
+
_meta: {
|
|
421
|
+
"ai.enhancelabs/disclosure": "progressive",
|
|
422
|
+
"enhance/disclosure": "progressive"
|
|
423
|
+
}
|
|
436
424
|
}, async ({ capability: id, input }) => {
|
|
437
425
|
try {
|
|
438
|
-
return await
|
|
426
|
+
return await execution.results.success(server, await invocation.invoke({
|
|
439
427
|
capability: capabilityFor(catalog, id, "query"),
|
|
440
428
|
arguments: input,
|
|
441
429
|
clientToken: null
|
|
442
|
-
}), delivery);
|
|
430
|
+
}), execution.delivery);
|
|
443
431
|
} catch (error) {
|
|
444
|
-
return
|
|
432
|
+
return execution.results.failure(error);
|
|
445
433
|
}
|
|
446
434
|
});
|
|
447
435
|
};
|
|
448
|
-
const registerMutation = (server, catalog, invocation,
|
|
449
|
-
server.registerTool("
|
|
436
|
+
const registerMutation = (server, catalog, invocation, execution) => {
|
|
437
|
+
server.registerTool("capability_mutate", {
|
|
450
438
|
title: "Run a discovered Enhance mutation",
|
|
451
|
-
description: "Run one state-changing capability using the exact id and input loaded by
|
|
439
|
+
description: "Run one state-changing capability using the exact id and input loaded by capability_describe. Search and describe first, respect its preconditions, and reuse clientToken only when retrying the identical mutation.",
|
|
452
440
|
inputSchema: mutationInputSchema,
|
|
453
441
|
outputSchema: mcpDispatchedResultSchema,
|
|
454
442
|
annotations: {
|
|
@@ -457,35 +445,48 @@ const registerMutation = (server, catalog, invocation, delivery) => {
|
|
|
457
445
|
idempotentHint: false,
|
|
458
446
|
openWorldHint: false
|
|
459
447
|
},
|
|
460
|
-
_meta: {
|
|
448
|
+
_meta: {
|
|
449
|
+
"ai.enhancelabs/disclosure": "progressive",
|
|
450
|
+
"enhance/disclosure": "progressive"
|
|
451
|
+
}
|
|
461
452
|
}, async ({ capability: id, input, clientToken }) => {
|
|
462
453
|
try {
|
|
463
|
-
return await
|
|
454
|
+
return await execution.results.success(server, await invocation.invoke({
|
|
464
455
|
capability: capabilityFor(catalog, id, "mutation"),
|
|
465
456
|
arguments: input,
|
|
466
457
|
clientToken: clientToken ?? null
|
|
467
|
-
}), delivery);
|
|
458
|
+
}), execution.delivery);
|
|
468
459
|
} catch (error) {
|
|
469
|
-
return
|
|
460
|
+
return execution.results.failure(error);
|
|
470
461
|
}
|
|
471
462
|
});
|
|
472
463
|
};
|
|
473
464
|
const createMcpServerAdapter = (input) => {
|
|
474
465
|
const server = new McpServer({
|
|
475
|
-
name: "enhance-mcp",
|
|
466
|
+
name: input.name ?? "enhance-mcp",
|
|
476
467
|
version: input.version
|
|
477
|
-
}, {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
468
|
+
}, {
|
|
469
|
+
capabilities: {
|
|
470
|
+
tools: { listChanged: false },
|
|
471
|
+
resources: { listChanged: true }
|
|
472
|
+
},
|
|
473
|
+
...input.exposures?.includes("mcp-transport") === true && { instructions: AUTHENTICATION_INSTRUCTIONS }
|
|
474
|
+
});
|
|
475
|
+
const catalog = toPresentedCapabilities(input.catalog ?? createCapabilityCatalogAdapter(), input.exposures ?? ["shared"]);
|
|
482
476
|
const discovery = createMcpCapabilityDiscoveryAdapter(catalog);
|
|
483
477
|
const delivery = input.delivery ?? "linked";
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
478
|
+
const mcpResults = createMcpResultAdapter(input.exposures?.includes("mcp-transport") === true ? LOCAL_AUTHENTICATION_REMEDY : HOSTED_AUTHENTICATION_REMEDY, input.commandName);
|
|
479
|
+
createMcpCatalogueToolAdapter(catalog, input.version, input.commandName).register(server);
|
|
480
|
+
registerSearch(server, catalog, discovery, mcpResults);
|
|
481
|
+
createMcpDescribeToolAdapter(discovery, mcpResults).register(server);
|
|
482
|
+
const execution = {
|
|
483
|
+
delivery,
|
|
484
|
+
results: mcpResults
|
|
485
|
+
};
|
|
486
|
+
registerQuery(server, catalog, input.invocation, execution);
|
|
487
|
+
registerMutation(server, catalog, input.invocation, execution);
|
|
488
488
|
return server;
|
|
489
489
|
};
|
|
490
|
+
|
|
490
491
|
//#endregion
|
|
491
|
-
export {
|
|
492
|
+
export { createMcpServerAdapter as t };
|