@frontmcp/sdk 1.11.0 → 1.11.1-rc.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/browser/common/entries/scope.entry.mjs +16 -0
- package/browser/common/metadata/plugin.metadata.mjs +2 -1
- package/browser/common/schemas/http-output.schema.mjs +12 -1
- package/browser/common/tokens/plugin.tokens.mjs +2 -1
- package/browser/common/types/options/skills-http/schema.mjs +13 -0
- package/browser/direct/direct-client.mjs +8 -0
- package/browser/direct/token-auth-info.mjs +31 -0
- package/browser/errors/http-route.errors.mjs +9 -0
- package/browser/errors/index.mjs +3 -1
- package/browser/errors/misconfiguration.mjs +2 -1
- package/browser/errors/plugin.errors.mjs +10 -0
- package/browser/front-mcp/front-mcp.mjs +6 -2
- package/browser/health/health.service.mjs +4 -0
- package/browser/http-route/flows/http.route.flow.mjs +47 -19
- package/browser/index.cjs +1404 -835
- package/browser/index.mjs +12 -2
- package/browser/job/enclave/browser-enclave-core.mjs +9 -0
- package/browser/job/enclave/job-enclave.bridge.mjs +3 -20
- package/browser/plugin/plugin.registry.mjs +17 -1
- package/browser/resource/flows/resources-list.flow.mjs +31 -1
- package/browser/scope/scope.instance.mjs +6 -4
- package/browser/server/server.validation.mjs +3 -6
- package/browser/skill/decision/decisions-api.decider.mjs +62 -0
- package/browser/skill/decision/skill-decision.ranker.mjs +96 -0
- package/browser/skill/flows/load-skill.flow.mjs +15 -10
- package/browser/skill/index.mjs +4 -0
- package/browser/skill/providers/memory-skill.provider.mjs +41 -135
- package/browser/skill/sep-2640/resources/skill-md.resource.mjs +3 -3
- package/browser/skill/sep-2640/sep-2640.builders.mjs +24 -2
- package/browser/skill/sep-2640/sep-2640.per-skill.mjs +3 -4
- package/browser/skill/sep-2640/sep-2640.resource-helpers.mjs +10 -1
- package/browser/skill/skill-catalog-source.mjs +23 -0
- package/browser/skill/skill-instructions.helper.mjs +23 -5
- package/browser/skill/skill-search-text.mjs +166 -0
- package/browser/skill/skill.registry.mjs +58 -3
- package/browser/subsystems.mjs +14 -1
- package/browser/transport/mcp-handlers/skills-mcp.types.mjs +5 -3
- package/browser/transport/relay/relay-http.mjs +2 -1
- package/browser/transport/web-response.renderer.mjs +6 -2
- package/browser/utils/http-location.utils.mjs +8 -0
- package/common/decorators/tool.decorator.d.ts +2 -1
- package/common/decorators/tool.decorator.d.ts.map +1 -1
- package/common/entries/scope.entry.d.ts +8 -0
- package/common/entries/scope.entry.d.ts.map +1 -1
- package/common/interfaces/skill.interface.d.ts +5 -0
- package/common/interfaces/skill.interface.d.ts.map +1 -1
- package/common/metadata/front-mcp.metadata.d.ts +90 -0
- package/common/metadata/front-mcp.metadata.d.ts.map +1 -1
- package/common/metadata/plugin.metadata.d.ts +8 -0
- package/common/metadata/plugin.metadata.d.ts.map +1 -1
- package/common/schemas/http-output.schema.d.ts.map +1 -1
- package/common/tokens/plugin.tokens.d.ts +1 -0
- package/common/tokens/plugin.tokens.d.ts.map +1 -1
- package/common/types/options/skills-http/interfaces.d.ts +16 -0
- package/common/types/options/skills-http/interfaces.d.ts.map +1 -1
- package/common/types/options/skills-http/schema.d.ts +11 -0
- package/common/types/options/skills-http/schema.d.ts.map +1 -1
- package/direct/client.types.d.ts +27 -8
- package/direct/client.types.d.ts.map +1 -1
- package/direct/create.types.d.ts +6 -1
- package/direct/create.types.d.ts.map +1 -1
- package/direct/token-auth-info.d.ts +5 -0
- package/direct/token-auth-info.d.ts.map +1 -0
- package/errors/http-route.errors.d.ts +4 -0
- package/errors/http-route.errors.d.ts.map +1 -1
- package/errors/index.d.ts +1 -1
- package/errors/index.d.ts.map +1 -1
- package/errors/misconfiguration.d.ts.map +1 -1
- package/errors/plugin.errors.d.ts +4 -0
- package/errors/plugin.errors.d.ts.map +1 -1
- package/esm/index.mjs +30 -22
- package/front-mcp/front-mcp.d.ts +3 -0
- package/front-mcp/front-mcp.d.ts.map +1 -1
- package/health/health.service.d.ts +4 -1
- package/health/health.service.d.ts.map +1 -1
- package/http-route/flows/http.route.flow.d.ts +6 -0
- package/http-route/flows/http.route.flow.d.ts.map +1 -1
- package/index.d.ts +9 -9
- package/index.d.ts.map +1 -1
- package/index.js +43 -35
- package/job/enclave/browser-enclave-core.d.ts +3 -0
- package/job/enclave/browser-enclave-core.d.ts.map +1 -0
- package/job/enclave/enclave-core.d.ts +3 -0
- package/job/enclave/enclave-core.d.ts.map +1 -0
- package/job/enclave/job-enclave.bridge.d.ts +1 -9
- package/job/enclave/job-enclave.bridge.d.ts.map +1 -1
- package/package.json +16 -11
- package/plugin/plugin.registry.d.ts +2 -0
- package/plugin/plugin.registry.d.ts.map +1 -1
- package/resource/flows/resources-list.flow.d.ts +3 -1
- package/resource/flows/resources-list.flow.d.ts.map +1 -1
- package/scope/scope.instance.d.ts.map +1 -1
- package/server/server.validation.d.ts.map +1 -1
- package/skill/decision/decisions-api.decider.d.ts +26 -0
- package/skill/decision/decisions-api.decider.d.ts.map +1 -0
- package/skill/decision/index.d.ts +4 -0
- package/skill/decision/index.d.ts.map +1 -0
- package/skill/decision/skill-decision.ranker.d.ts +28 -0
- package/skill/decision/skill-decision.ranker.d.ts.map +1 -0
- package/skill/decision/skill-decision.types.d.ts +63 -0
- package/skill/decision/skill-decision.types.d.ts.map +1 -0
- package/skill/flows/load-skill.flow.d.ts +6 -4
- package/skill/flows/load-skill.flow.d.ts.map +1 -1
- package/skill/index.d.ts +5 -0
- package/skill/index.d.ts.map +1 -1
- package/skill/providers/memory-skill.provider.d.ts +10 -12
- package/skill/providers/memory-skill.provider.d.ts.map +1 -1
- package/skill/sep-2640/sep-2640.builders.d.ts +7 -2
- package/skill/sep-2640/sep-2640.builders.d.ts.map +1 -1
- package/skill/sep-2640/sep-2640.per-skill.d.ts.map +1 -1
- package/skill/sep-2640/sep-2640.resource-helpers.d.ts +5 -0
- package/skill/sep-2640/sep-2640.resource-helpers.d.ts.map +1 -1
- package/skill/skill-catalog-source.d.ts +47 -0
- package/skill/skill-catalog-source.d.ts.map +1 -0
- package/skill/skill-instructions.helper.d.ts +10 -0
- package/skill/skill-instructions.helper.d.ts.map +1 -1
- package/skill/skill-search-text.d.ts +60 -0
- package/skill/skill-search-text.d.ts.map +1 -0
- package/skill/skill-storage.interface.d.ts +5 -0
- package/skill/skill-storage.interface.d.ts.map +1 -1
- package/skill/skill.registry.d.ts +20 -0
- package/skill/skill.registry.d.ts.map +1 -1
- package/subsystems.d.ts +1 -1
- package/subsystems.d.ts.map +1 -1
- package/transport/mcp-handlers/index.d.ts +1 -1
- package/transport/mcp-handlers/skills-mcp.types.d.ts +3 -2
- package/transport/mcp-handlers/skills-mcp.types.d.ts.map +1 -1
- package/transport/relay/relay-http.d.ts.map +1 -1
- package/transport/web-response.renderer.d.ts.map +1 -1
- package/utils/http-location.utils.d.ts +8 -0
- package/utils/http-location.utils.d.ts.map +1 -0
|
@@ -30,6 +30,22 @@ var ScopeEntry = class extends BaseEntry {
|
|
|
30
30
|
await cb();
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
addedHealthProbes = [];
|
|
34
|
+
/**
|
|
35
|
+
* Add a check to the server's `/readyz` readiness probe, run with the built-in ones and the
|
|
36
|
+
* `health.probes` the server configures. Plugins call it while the server starts, from a provider
|
|
37
|
+
* factory: the health service takes the checks registered by the time the scope is ready.
|
|
38
|
+
*/
|
|
39
|
+
registerHealthProbe(probe) {
|
|
40
|
+
this.addedHealthProbes.push(probe);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The checks added with registerHealthProbe().
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
get healthProbes() {
|
|
47
|
+
return this.addedHealthProbes;
|
|
48
|
+
}
|
|
33
49
|
/** Teardown callbacks registered via onDispose(), run once when the scope is disposed. */
|
|
34
50
|
disposeCallbacks = [];
|
|
35
51
|
disposeEmitted = false;
|
|
@@ -30,7 +30,8 @@ var frontMcpPluginMetadataSchema = z.object({
|
|
|
30
30
|
scope: z.enum(["app", "server"]).optional().default("app"),
|
|
31
31
|
contextExtensions: z.array(contextExtensionSchema).optional(),
|
|
32
32
|
enforcesMetadata: z.array(z.string().min(1)).optional(),
|
|
33
|
-
dynamicSkills: z.boolean().optional()
|
|
33
|
+
dynamicSkills: z.boolean().optional(),
|
|
34
|
+
oncePerServer: z.string().min(1).optional()
|
|
34
35
|
}).passthrough();
|
|
35
36
|
export {
|
|
36
37
|
frontMcpPluginMetadataSchema
|
|
@@ -47,10 +47,21 @@ var HttpMeta = z.object({
|
|
|
47
47
|
cookies: HttpCookies.optional()
|
|
48
48
|
});
|
|
49
49
|
var statusAllowsBody = (s) => !NO_BODY_STATUSES.includes(s);
|
|
50
|
+
function isLocation(location) {
|
|
51
|
+
if (/[\s\p{Cc}]/u.test(location)) return false;
|
|
52
|
+
try {
|
|
53
|
+
new URL(location, "http://localhost");
|
|
54
|
+
return true;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
50
59
|
var HttpRedirectSchema = z.object({
|
|
51
60
|
kind: z.literal("redirect"),
|
|
52
61
|
status: HttpRedirectStatus.default(302),
|
|
53
|
-
location: z.string().
|
|
62
|
+
location: z.string().min(1).refine(isLocation, {
|
|
63
|
+
message: "A redirect location is an absolute URL or a path, with no whitespace or control characters"
|
|
64
|
+
})
|
|
54
65
|
}).merge(HttpMeta);
|
|
55
66
|
var HttpJsonSchema = z.object({
|
|
56
67
|
kind: z.literal("json"),
|
|
@@ -16,7 +16,8 @@ var FrontMcpPluginTokens = {
|
|
|
16
16
|
scope: tokenFactory.meta("scope"),
|
|
17
17
|
contextExtensions: tokenFactory.meta("contextExtensions"),
|
|
18
18
|
enforcesMetadata: tokenFactory.meta("enforcesMetadata"),
|
|
19
|
-
dynamicSkills: tokenFactory.meta("dynamicSkills")
|
|
19
|
+
dynamicSkills: tokenFactory.meta("dynamicSkills"),
|
|
20
|
+
oncePerServer: tokenFactory.meta("oncePerServer")
|
|
20
21
|
};
|
|
21
22
|
export {
|
|
22
23
|
FrontMcpPluginTokens
|
|
@@ -54,6 +54,18 @@ function isExternalSkillProvider(value) {
|
|
|
54
54
|
const provider = value;
|
|
55
55
|
return EXTERNAL_SKILL_PROVIDER_METHODS.every((method) => typeof provider[method] === "function");
|
|
56
56
|
}
|
|
57
|
+
var skillsConfigDecisionOptionsSchema = z.object({
|
|
58
|
+
decider: z.custom((value) => typeof value === "function", {
|
|
59
|
+
message: "decision.decider must be a function, such as decisionsApiDecider({ apiKey })"
|
|
60
|
+
}),
|
|
61
|
+
maxCandidates: z.number().int().min(1).max(254).optional(),
|
|
62
|
+
minProbability: z.number().min(0).max(1).optional(),
|
|
63
|
+
timeoutMs: z.number().int().positive().optional(),
|
|
64
|
+
cache: z.union([
|
|
65
|
+
z.literal(false),
|
|
66
|
+
z.object({ ttlMs: z.number().int().positive().optional(), maxEntries: z.number().int().positive().optional() })
|
|
67
|
+
]).optional()
|
|
68
|
+
});
|
|
57
69
|
var skillsConfigOptionsSchema = z.object({
|
|
58
70
|
enabled: z.boolean().optional().default(false),
|
|
59
71
|
prefix: z.string().optional(),
|
|
@@ -70,6 +82,7 @@ var skillsConfigOptionsSchema = z.object({
|
|
|
70
82
|
audit: skillsConfigAuditOptionsSchema.optional(),
|
|
71
83
|
injectInstructions: z.enum(["off", "compact", "append", "prepend", "replace"]).optional().default("compact"),
|
|
72
84
|
scoring: z.enum(["cosine", "bm25"]).optional(),
|
|
85
|
+
decision: skillsConfigDecisionOptionsSchema.optional(),
|
|
73
86
|
failOnInvalidSkills: z.boolean().optional(),
|
|
74
87
|
externalProvider: z.custom(isExternalSkillProvider, {
|
|
75
88
|
message: `externalProvider must be an ExternalSkillProviderBase (${EXTERNAL_SKILL_PROVIDER_METHODS.join(", ")} functions)`
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
formatResultForPlatform,
|
|
29
29
|
formatToolsForPlatform
|
|
30
30
|
} from "./llm-platform.mjs";
|
|
31
|
+
import { authInfoForToken } from "./token-auth-info.mjs";
|
|
31
32
|
var DirectClientImpl = class _DirectClientImpl {
|
|
32
33
|
// Use a flexible type to handle dynamic import type differences between ESM/CJS
|
|
33
34
|
mcpClient;
|
|
@@ -83,6 +84,9 @@ var DirectClientImpl = class _DirectClientImpl {
|
|
|
83
84
|
if (options?.session?.scopes) {
|
|
84
85
|
authInfo["scopes"] = options.session.scopes;
|
|
85
86
|
}
|
|
87
|
+
if (options?.authToken) {
|
|
88
|
+
Object.assign(authInfo, await authInfoForToken(scope, options.authToken));
|
|
89
|
+
}
|
|
86
90
|
const { clientTransport, close } = await createInMemoryServer(scope, {
|
|
87
91
|
sessionId,
|
|
88
92
|
authInfo: Object.keys(authInfo).length > 0 ? authInfo : void 0,
|
|
@@ -531,6 +535,10 @@ var DirectClientImpl = class _DirectClientImpl {
|
|
|
531
535
|
} catch {
|
|
532
536
|
}
|
|
533
537
|
}
|
|
538
|
+
if (typeof meta.instructions === "string") {
|
|
539
|
+
const loaded = await scope.skills.loadSkill(meta.id ?? meta.name).catch(() => void 0);
|
|
540
|
+
if (loaded?.skill.bundleVersion !== void 0) entry.bundleVersion = loaded.skill.bundleVersion;
|
|
541
|
+
}
|
|
534
542
|
const resources = skill.getResources?.();
|
|
535
543
|
if (resources) {
|
|
536
544
|
entry.resources = {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// libs/sdk/src/direct/token-auth-info.ts
|
|
2
|
+
import { isAnonymousSubject } from "@frontmcp/auth";
|
|
3
|
+
import {
|
|
4
|
+
authInfoFromAuthorization,
|
|
5
|
+
normalizeEntryPrefix,
|
|
6
|
+
normalizeScopeBase
|
|
7
|
+
} from "../common/index.mjs";
|
|
8
|
+
import { PublicMcpError, SessionVerificationFailedError, UnauthorizedError } from "../errors/index.mjs";
|
|
9
|
+
async function authInfoForToken(scope, token) {
|
|
10
|
+
const mcpPath = `${normalizeEntryPrefix(scope.entryPath)}${normalizeScopeBase(scope.routeBase)}` || "/";
|
|
11
|
+
const request = {
|
|
12
|
+
method: "POST",
|
|
13
|
+
path: mcpPath,
|
|
14
|
+
url: mcpPath,
|
|
15
|
+
headers: { host: "localhost", authorization: `Bearer ${token}` },
|
|
16
|
+
query: {}
|
|
17
|
+
};
|
|
18
|
+
const verified = await scope.runFlow("session:verify", { request, sessionless: true });
|
|
19
|
+
if (!verified) throw new SessionVerificationFailedError();
|
|
20
|
+
if (verified.kind === "unauthorized") {
|
|
21
|
+
throw new UnauthorizedError("The server's auth did not accept the auth token", verified.prmMetadataHeader);
|
|
22
|
+
}
|
|
23
|
+
if (verified.kind === "forbidden") {
|
|
24
|
+
throw new PublicMcpError("The auth token lacks the scopes the server requires", "INSUFFICIENT_SCOPE", 403);
|
|
25
|
+
}
|
|
26
|
+
if (isAnonymousSubject(verified.authorization.user.sub)) return {};
|
|
27
|
+
return authInfoFromAuthorization(verified.authorization);
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
authInfoForToken
|
|
31
|
+
};
|
|
@@ -5,6 +5,14 @@ var InvalidHttpRouteError = class extends InternalMcpError {
|
|
|
5
5
|
super(`HTTP route ${method} ${path}: ${reason}`, "INVALID_HTTP_ROUTE");
|
|
6
6
|
}
|
|
7
7
|
};
|
|
8
|
+
var InvalidHttpRouteResponseError = class extends InternalMcpError {
|
|
9
|
+
constructor(method, path, kind, problems) {
|
|
10
|
+
super(
|
|
11
|
+
`HTTP route ${method} ${path} returned an invalid "${kind}" response: ${problems}`,
|
|
12
|
+
"INVALID_HTTP_ROUTE_RESPONSE"
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
8
16
|
var InvalidPeopleAuthOptionsError = class extends InternalMcpError {
|
|
9
17
|
constructor(problems) {
|
|
10
18
|
super(`http.auth.people: ${problems.join("; ")}`, "INVALID_PEOPLE_AUTH_OPTIONS");
|
|
@@ -41,6 +49,7 @@ var SignInLockedError = class extends PublicMcpError {
|
|
|
41
49
|
export {
|
|
42
50
|
CrossOriginRequestError,
|
|
43
51
|
InvalidHttpRouteError,
|
|
52
|
+
InvalidHttpRouteResponseError,
|
|
44
53
|
InvalidPeopleAuthOptionsError,
|
|
45
54
|
PersonNotSignedInError,
|
|
46
55
|
SignInLockedError,
|
package/browser/errors/index.mjs
CHANGED
|
@@ -160,6 +160,7 @@ import { BrowserEntryPointUnavailableError } from "./browser-entry-point.errors.
|
|
|
160
160
|
import {
|
|
161
161
|
CrossOriginRequestError,
|
|
162
162
|
InvalidHttpRouteError,
|
|
163
|
+
InvalidHttpRouteResponseError,
|
|
163
164
|
InvalidPeopleAuthOptionsError,
|
|
164
165
|
PersonNotSignedInError,
|
|
165
166
|
SignInLockedError,
|
|
@@ -259,7 +260,7 @@ import {
|
|
|
259
260
|
CallRecorderConfigurationError
|
|
260
261
|
} from "./sdk.errors.mjs";
|
|
261
262
|
export { DynamicJobRegistrationDisabledError, JobAdmissionTimeoutError, JobCancelledError, JobInterruptedError, JobNotAuthorizedError, JobRunFinishedError, JobRunNotCancellableError, JobRunNotFoundError, JobRunnerBootError, JobRunnerUnavailableError, JobStoreNotSupportedError, JobTimeoutError } from "./job.errors.mjs";
|
|
262
|
-
export { UnenforcedMetadataError } from "./plugin.errors.mjs";
|
|
263
|
+
export { DuplicatePluginError, UnenforcedMetadataError } from "./plugin.errors.mjs";
|
|
263
264
|
export {
|
|
264
265
|
AgentCallDepthExceededError,
|
|
265
266
|
AgentConfigKeyNotFoundError,
|
|
@@ -334,6 +335,7 @@ export {
|
|
|
334
335
|
InvalidFileSignalError,
|
|
335
336
|
InvalidHookFlowError,
|
|
336
337
|
InvalidHttpRouteError,
|
|
338
|
+
InvalidHttpRouteResponseError,
|
|
337
339
|
InvalidInputError,
|
|
338
340
|
InvalidInstructionSourceError,
|
|
339
341
|
InvalidMethodError,
|
|
@@ -6,7 +6,8 @@ var MISCONFIGURATION_REMEDIES = {
|
|
|
6
6
|
// The startup checks: a server whose entries ask for protection nothing gives them does not start.
|
|
7
7
|
UNENFORCED_METADATA: "An entry declares a field only a plugin enforces (approval, featureFlag, ...) and no installed plugin that enforces it reaches the entry, so the server refuses to start. Install the plugin or remove the field; the server log names the entries.",
|
|
8
8
|
AUTH_CONFIGURATION_ERROR: "The auth or authorities configuration is invalid (for example, entries declare authorities and the server has no authorities option, or a rule checks nothing), so the server refuses to start. The server log names the entries.",
|
|
9
|
-
TOOL_ALIAS_CONFLICT: "A tool alias (`@Tool({ aliases })`) is also the name of a tool or the alias of another tool, so the server refuses to start. Give each alias to one tool; the server log names the conflicts."
|
|
9
|
+
TOOL_ALIAS_CONFLICT: "A tool alias (`@Tool({ aliases })`) is also the name of a tool or the alias of another tool, so the server refuses to start. Give each alias to one tool; the server log names the conflicts.",
|
|
10
|
+
DUPLICATE_PLUGIN: "A plugin that can be installed once per server is installed twice (in one plugins list, or by the server and an app, or by two apps), so the server refuses to start. Install it once; the server log names the plugin."
|
|
10
11
|
};
|
|
11
12
|
function findMisconfiguration(error) {
|
|
12
13
|
let current = error;
|
|
@@ -22,6 +22,16 @@ To fix this issue:
|
|
|
22
22
|
${this.suggestion}`;
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
var DuplicatePluginError = class extends PublicMcpError {
|
|
26
|
+
constructor(pluginName, reason) {
|
|
27
|
+
super(
|
|
28
|
+
`Plugin "${pluginName}" can be installed once per server, and this server installs it twice. ${reason}`,
|
|
29
|
+
"DUPLICATE_PLUGIN",
|
|
30
|
+
500
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
25
34
|
export {
|
|
35
|
+
DuplicatePluginError,
|
|
26
36
|
UnenforcedMetadataError
|
|
27
37
|
};
|
|
@@ -473,6 +473,9 @@ var FrontMcpInstance = class _FrontMcpInstance {
|
|
|
473
473
|
* `options.workerEnv` sets the platform bindings every call reads as `this.workerEnv` unless the call
|
|
474
474
|
* (`DirectCallOptions.workerEnv`) or client (`ConnectOptions.workerEnv`) passes its own (#706).
|
|
475
475
|
*
|
|
476
|
+
* The server never listens, so of `http` it takes only `forwardHeaders`: a call's `metadata.customHeaders` keeps
|
|
477
|
+
* the headers it names, besides `x-frontmcp-*`, as an HTTP request does (#1052).
|
|
478
|
+
*
|
|
476
479
|
* @example
|
|
477
480
|
* ```typescript
|
|
478
481
|
* import { FrontMcpInstance } from '@frontmcp/sdk';
|
|
@@ -496,8 +499,9 @@ var FrontMcpInstance = class _FrontMcpInstance {
|
|
|
496
499
|
const { workerEnv, ...config } = options;
|
|
497
500
|
const parsedConfig = frontMcpMetadataSchema.parse({
|
|
498
501
|
...config,
|
|
499
|
-
// Direct access never listens: no HTTP
|
|
500
|
-
|
|
502
|
+
// Direct access never listens: no HTTP host (a browser build has no Express), so of `http` only the
|
|
503
|
+
// headers in-process calls keep apply (#1052)
|
|
504
|
+
http: config.http?.forwardHeaders ? { forwardHeaders: config.http.forwardHeaders } : void 0,
|
|
501
505
|
serve: false
|
|
502
506
|
});
|
|
503
507
|
markDirectOnly(parsedConfig);
|
|
@@ -26,6 +26,7 @@ var HealthService = class {
|
|
|
26
26
|
* Walks the scope's stores and registries to create built-in probes:
|
|
27
27
|
* - Session store (if transport persistence is configured)
|
|
28
28
|
* - Remote MCP apps (via existing HealthCheckManager)
|
|
29
|
+
* - Probes plugins registered on the scope
|
|
29
30
|
* - User-defined probes from config
|
|
30
31
|
*/
|
|
31
32
|
autoDiscoverProbes(scope) {
|
|
@@ -54,6 +55,9 @@ var HealthService = class {
|
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
57
|
}
|
|
58
|
+
for (const probe of scope.healthProbes ?? []) {
|
|
59
|
+
this.registerProbe(probe);
|
|
60
|
+
}
|
|
57
61
|
const userProbes = this.config.probes ?? [];
|
|
58
62
|
for (const probe of userProbes) {
|
|
59
63
|
if (probe && typeof probe.check === "function" && typeof probe.name === "string") {
|
|
@@ -18,13 +18,14 @@ import {
|
|
|
18
18
|
enforceIpFilter,
|
|
19
19
|
Flow,
|
|
20
20
|
FlowBase,
|
|
21
|
+
FlowControl,
|
|
21
22
|
FlowHooksOf,
|
|
22
23
|
httpInputSchema,
|
|
23
24
|
httpOutputSchema,
|
|
24
25
|
httpRespond,
|
|
25
26
|
isProxyTrusted
|
|
26
27
|
} from "../../common/index.mjs";
|
|
27
|
-
import { CrossOriginRequestError, PersonNotSignedInError } from "../../errors/index.mjs";
|
|
28
|
+
import { CrossOriginRequestError, InvalidHttpRouteResponseError, PersonNotSignedInError } from "../../errors/index.mjs";
|
|
28
29
|
import { FlowContextProviders } from "../../provider/flow-context-providers.mjs";
|
|
29
30
|
import { corsAllowedOrigins } from "../../server/security/resolve-allowed-hosts.mjs";
|
|
30
31
|
import { isSameOriginRequest } from "../../server/security/same-origin.mjs";
|
|
@@ -40,23 +41,22 @@ var httpRouteStateSchema = z.object({
|
|
|
40
41
|
var name = "http:route";
|
|
41
42
|
var { Stage } = FlowHooksOf(name);
|
|
42
43
|
var MUTATIONS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
44
|
+
var RESPONSE_KINDS = new Set(
|
|
45
|
+
Object.keys({
|
|
46
|
+
redirect: true,
|
|
47
|
+
json: true,
|
|
48
|
+
text: true,
|
|
49
|
+
html: true,
|
|
50
|
+
binary: true,
|
|
51
|
+
image: true,
|
|
52
|
+
stream: true,
|
|
53
|
+
sse: true,
|
|
54
|
+
jsonrpc: true,
|
|
55
|
+
problem: true,
|
|
56
|
+
empty: true,
|
|
57
|
+
"web-response": true
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
60
|
var HttpRouteFlow = class extends FlowBase {
|
|
61
61
|
static canActivate(request, scope) {
|
|
62
62
|
return scope.httpRouteTable?.match(request) !== void 0;
|
|
@@ -104,7 +104,35 @@ var HttpRouteFlow = class extends FlowBase {
|
|
|
104
104
|
request: this.httpRequest,
|
|
105
105
|
person
|
|
106
106
|
});
|
|
107
|
-
this.respond(
|
|
107
|
+
this.respond(
|
|
108
|
+
route.sse ? this.openStream(route, route.sse, context) : this.toHttpOutput(route, await context.handle())
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* What `handle()` returned, as the response. A value with a response `kind` that is valid for that kind is a
|
|
113
|
+
* response, with the kind's defaults (a redirect without a `status` is a 302). One that is not valid and has a
|
|
114
|
+
* `status`, as every `httpRespond` output has, fails (#1053); other objects are data.
|
|
115
|
+
*/
|
|
116
|
+
toHttpOutput(route, result) {
|
|
117
|
+
if (result === void 0) return httpRespond.noContent();
|
|
118
|
+
if (typeof result === "string") {
|
|
119
|
+
return { kind: "text", status: 200, body: result, contentType: "text/plain; charset=utf-8" };
|
|
120
|
+
}
|
|
121
|
+
const kind = result.kind;
|
|
122
|
+
const parsed = typeof kind === "string" && RESPONSE_KINDS.has(kind) ? httpOutputSchema.safeParse(result) : void 0;
|
|
123
|
+
if (parsed?.success) return parsed.data;
|
|
124
|
+
if (parsed && "status" in result) {
|
|
125
|
+
const problems = parsed.error.issues.map((issue) => `${issue.path.join(".") || "kind"}: ${issue.message}`);
|
|
126
|
+
const error = new InvalidHttpRouteResponseError(route.method, route.path, String(kind), problems.join("; "));
|
|
127
|
+
this.scope.logger.error(error.message);
|
|
128
|
+
throw FlowControl.fail(error);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
kind: "json",
|
|
132
|
+
status: 200,
|
|
133
|
+
body: result,
|
|
134
|
+
contentType: "application/json; charset=utf-8"
|
|
135
|
+
};
|
|
108
136
|
}
|
|
109
137
|
/** The person signed in for routes of `auth`: a session for a subject opens `'subject'` routes only. */
|
|
110
138
|
verifyPerson(auth) {
|