@brickkit/core 0.16.0-beta.2 → 0.16.0-beta.4
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/chunks/client.d.ts +4 -1
- package/dist/chunks/client.js +3 -0
- package/dist/chunks/client.js.map +1 -1
- package/dist/chunks/server.d.ts +28 -2
- package/dist/chunks/server.js +281 -11
- package/dist/chunks/server.js.map +1 -1
- package/dist/chunks/types.d.ts +11 -1
- package/dist/client.d.ts +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -137
- package/dist/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/workflow.d.ts +1 -1
- package/package.json +1 -1
package/dist/chunks/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fn as ServicePort, Mt as DashboardUser, O as Logger, Qr as SecretSource, Ut as Sensitivity, V as Service, Z as ValidationErrorItem, _t as EventsDefinition, ai as HttpMethod, gn as InstalledPlugin, lt as SocketBroker, ot as BrickSocketSchema, qt as DatabaseHandle, rr as PluginInstance, t as Action, vt as EventsHub, wt as ClientIp, xr as EventsOptions } from "./types.js";
|
|
2
2
|
import { Elysia } from "elysia";
|
|
3
3
|
type RouteMethod = HttpMethod;
|
|
4
4
|
/** How a string from a query or form field becomes the schema's type; objects travel as JSON. */
|
|
@@ -164,7 +164,33 @@ interface DashboardOptions {
|
|
|
164
164
|
* in (by token, or by `authorize` returning `true`) can only look.
|
|
165
165
|
*/
|
|
166
166
|
inspector?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Let a coding agent (Claude Code, Cursor, Codex) read the dashboard's data
|
|
169
|
+
* over MCP at `/mcp`, while it debugs: requests, traces, logs, errors and the
|
|
170
|
+
* app's architecture. Default false; `brick dev` always has it, since it only
|
|
171
|
+
* listens on this machine. Its own tools only read, even for a signed-in
|
|
172
|
+
* user, and it passes the same checks as the rest of the dashboard: the agent sends
|
|
173
|
+
* `Authorization: Bearer <token>` with one of `auth.token`.
|
|
174
|
+
*
|
|
175
|
+
* What the agent reads goes to its model provider: request paths and
|
|
176
|
+
* messages, log lines (which can hold what your users typed), error stacks,
|
|
177
|
+
* and span attributes such as SQL text. Turn it on only for a dashboard
|
|
178
|
+
* whose data you are willing to send there.
|
|
179
|
+
*
|
|
180
|
+
* It also serves the app's own tools marked `dashboard: true` (see
|
|
181
|
+
* `service.tool`), next to the dashboard's. A tool that is not marked
|
|
182
|
+
* `readOnlyHint: true` can change data, and is offered only to a signed-in
|
|
183
|
+
* user (one `auth.authorize` returned as `{ user }`).
|
|
184
|
+
*/
|
|
185
|
+
mcp?: boolean;
|
|
167
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Where the app answers MCP for the dashboard's `/mcp`: its tools marked
|
|
189
|
+
* `dashboard: true`. Only a request signed by the dashboard gets in.
|
|
190
|
+
*/
|
|
191
|
+
declare const DASHBOARD_MCP_ROUTE = "/_brick/dashboard/mcp";
|
|
192
|
+
/** The dashboard's own MCP tools. A `dashboard: true` tool may not take one of these names. */
|
|
193
|
+
declare const DASHBOARD_MCP_TOOLS: readonly ["summary", "list_requests", "get_trace", "list_errors", "app_overview", "search_logs", "list_reloads", "list_schedules", "list_runs", "get_run", "get_openapi", "list_docs", "read_doc"];
|
|
168
194
|
type EndpointMethod = HttpMethod;
|
|
169
195
|
/** The logger handed to endpoint handlers (the same one actions get). */
|
|
170
196
|
type EndpointLogger = Logger;
|
|
@@ -473,4 +499,4 @@ interface CreateServerOptions {
|
|
|
473
499
|
* });
|
|
474
500
|
*/
|
|
475
501
|
declare function brick(options?: CreateServerOptions): BrickApp;
|
|
476
|
-
export {
|
|
502
|
+
export { referencePlugin as A, DashboardAuth as C, OpenApiDocument as D, DocumentationOptions as E, RouteMethod as F, scalarDocsHTML as M, BrickIR as N, ReferenceDocument as O, RouteIR as P, DASHBOARD_MCP_TOOLS as S, ApiDocument as T, EndpointContext as _, RequestLoggingOptions as a, EndpointMethod as b, CompiledRoute as c, loadCompiledBrickApp as d, CompiledHandler as f, BrickApp as g, deny as h, CorsOrigin as i, registerReferenceRoute as j, ReferenceOptions as k, bindCompiledApplication as l, HandlerFactory as m, brick as n, requestLoggingPlugin as o, CompiledRoutePlan as p, CorsOptions as r, CompiledApplication as s, CreateServerOptions as t, compileBrickApplication as u, EndpointDefinition as v, DashboardOptions as w, DASHBOARD_MCP_ROUTE as x, EndpointLogger as y };
|
package/dist/chunks/server.js
CHANGED
|
@@ -449,6 +449,7 @@ const INSTRUMENTATION_SCOPE = "@brickkit/core";
|
|
|
449
449
|
const MAX_TEXT_LENGTH = 500;
|
|
450
450
|
const MAX_STATEMENT_LENGTH = 2e3;
|
|
451
451
|
const DATABASE_INSTRUMENTED = Symbol.for("brickkit.telemetry.database");
|
|
452
|
+
const FETCH_INSTRUMENTED = Symbol.for("brickkit.telemetry.fetch");
|
|
452
453
|
const SQLITE_STATEMENT_METHODS = [
|
|
453
454
|
"all",
|
|
454
455
|
"get",
|
|
@@ -569,6 +570,53 @@ function instrumentDatabase(db) {
|
|
|
569
570
|
else return;
|
|
570
571
|
driver[DATABASE_INSTRUMENTED] = true;
|
|
571
572
|
}
|
|
573
|
+
function instrumentFetch() {
|
|
574
|
+
const original = globalThis.fetch;
|
|
575
|
+
if (original[FETCH_INSTRUMENTED]) return;
|
|
576
|
+
const wrapped = new Proxy(original, {
|
|
577
|
+
get: (target, key) => key === FETCH_INSTRUMENTED ? true : Reflect.get(target, key),
|
|
578
|
+
apply(target, self, args) {
|
|
579
|
+
const [input, init] = args;
|
|
580
|
+
if (!trace.getActiveSpan()) return Reflect.apply(target, self, args);
|
|
581
|
+
let url;
|
|
582
|
+
try {
|
|
583
|
+
url = new URL(input instanceof Request ? input.url : String(input));
|
|
584
|
+
} catch {
|
|
585
|
+
return Reflect.apply(target, self, args);
|
|
586
|
+
}
|
|
587
|
+
const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
588
|
+
const span = trace.getTracer(INSTRUMENTATION_SCOPE).startSpan(truncate(redactText(`${method} ${url.host}${url.pathname}`)), {
|
|
589
|
+
kind: SpanKind.CLIENT,
|
|
590
|
+
attributes: {
|
|
591
|
+
[ATTR.httpMethod]: method,
|
|
592
|
+
[ATTR.urlFull]: truncate(redactText(`${url.origin}${url.pathname}`)),
|
|
593
|
+
[ATTR.serverAddress]: url.hostname
|
|
594
|
+
}
|
|
595
|
+
}, context.active());
|
|
596
|
+
const fail = (error) => {
|
|
597
|
+
recordThrown(span, error);
|
|
598
|
+
span.end();
|
|
599
|
+
throw error;
|
|
600
|
+
};
|
|
601
|
+
let pending;
|
|
602
|
+
try {
|
|
603
|
+
pending = Reflect.apply(target, self, args);
|
|
604
|
+
} catch (error) {
|
|
605
|
+
return fail(error);
|
|
606
|
+
}
|
|
607
|
+
return pending.then((response) => {
|
|
608
|
+
span.setAttribute(ATTR.httpStatus, response.status);
|
|
609
|
+
if (response.status >= 400) span.setStatus({
|
|
610
|
+
code: SpanStatusCode.ERROR,
|
|
611
|
+
message: `HTTP ${response.status}`
|
|
612
|
+
});
|
|
613
|
+
span.end();
|
|
614
|
+
return response;
|
|
615
|
+
}, fail);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
globalThis.fetch = wrapped;
|
|
619
|
+
}
|
|
572
620
|
function instrumentBunSqlite(client) {
|
|
573
621
|
const prepare = client.prepare.bind(client);
|
|
574
622
|
client.prepare = (sql) => {
|
|
@@ -983,15 +1031,18 @@ function markDashboardArrival(request) {
|
|
|
983
1031
|
arrivedAt.set(request, Date.now());
|
|
984
1032
|
}
|
|
985
1033
|
const mac$1 = (payload) => createHmac("sha256", dashboardKey()).update(payload).digest();
|
|
986
|
-
|
|
987
|
-
function signDashboardIdentity(identity, now = Date.now()) {
|
|
1034
|
+
const sign = (claims, now) => {
|
|
988
1035
|
const payload = Buffer.from(JSON.stringify({
|
|
989
|
-
|
|
1036
|
+
...claims,
|
|
990
1037
|
exp: now + SIGNATURE_TTL_MS
|
|
991
1038
|
})).toString("base64url");
|
|
992
1039
|
return `${payload}.${mac$1(payload).toString("base64url")}`;
|
|
1040
|
+
};
|
|
1041
|
+
/** The header value for an identity: `<base64url(json)>.<hmac>`. */
|
|
1042
|
+
function signDashboardIdentity(identity, now = Date.now()) {
|
|
1043
|
+
return sign({ user: identity.user }, now);
|
|
993
1044
|
}
|
|
994
|
-
function
|
|
1045
|
+
function verifiedClaims(request) {
|
|
995
1046
|
const header = request?.headers.get(DASHBOARD_IDENTITY_HEADER);
|
|
996
1047
|
if (!header) return void 0;
|
|
997
1048
|
const dot = header.indexOf(".");
|
|
@@ -1001,14 +1052,40 @@ function dashboardIdentity(request) {
|
|
|
1001
1052
|
const expected = mac$1(payload);
|
|
1002
1053
|
if (given.length !== expected.length || !timingSafeEqual(given, expected)) return void 0;
|
|
1003
1054
|
try {
|
|
1004
|
-
const
|
|
1055
|
+
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
1005
1056
|
const now = (request && arrivedAt.get(request)) ?? Date.now();
|
|
1006
|
-
if (typeof exp !== "number" || exp < now) return void 0;
|
|
1007
|
-
return
|
|
1057
|
+
if (typeof claims?.exp !== "number" || claims.exp < now) return void 0;
|
|
1058
|
+
return claims;
|
|
1008
1059
|
} catch {
|
|
1009
1060
|
return;
|
|
1010
1061
|
}
|
|
1011
1062
|
}
|
|
1063
|
+
/** A signature made for the MCP route carries a `scope`, and is not an identity here. */
|
|
1064
|
+
function dashboardIdentity(request) {
|
|
1065
|
+
const claims = verifiedClaims(request);
|
|
1066
|
+
if (!claims || claims.scope !== void 0) return void 0;
|
|
1067
|
+
return claims.user === void 0 ? {} : { user: claims.user };
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* The header value for a call the dashboard's `/mcp` forwards to the app. It is
|
|
1071
|
+
* scoped to the MCP route: the `/app` proxy never signs one, and a signature
|
|
1072
|
+
* made for `/app` is not accepted there.
|
|
1073
|
+
*/
|
|
1074
|
+
function signDashboardMcp(caller, now = Date.now()) {
|
|
1075
|
+
return sign({
|
|
1076
|
+
user: caller.user,
|
|
1077
|
+
scope: "mcp",
|
|
1078
|
+
write: caller.write
|
|
1079
|
+
}, now);
|
|
1080
|
+
}
|
|
1081
|
+
function dashboardMcpCaller(request) {
|
|
1082
|
+
const claims = verifiedClaims(request);
|
|
1083
|
+
if (claims?.scope !== "mcp") return void 0;
|
|
1084
|
+
return {
|
|
1085
|
+
...claims.user === void 0 ? {} : { user: claims.user },
|
|
1086
|
+
write: claims.write === true
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1012
1089
|
/**
|
|
1013
1090
|
* The dashboard user a request came from, for an endpoint: the person
|
|
1014
1091
|
* `dashboard.auth.authorize` let in, when the request arrived through the
|
|
@@ -4753,6 +4830,27 @@ function swaggerDocsHTML(specUrl, title) {
|
|
|
4753
4830
|
</html>`;
|
|
4754
4831
|
}
|
|
4755
4832
|
// src/dashboard.ts
|
|
4833
|
+
/**
|
|
4834
|
+
* Where the app answers MCP for the dashboard's `/mcp`: its tools marked
|
|
4835
|
+
* `dashboard: true`. Only a request signed by the dashboard gets in.
|
|
4836
|
+
*/
|
|
4837
|
+
const DASHBOARD_MCP_ROUTE = "/_brick/dashboard/mcp";
|
|
4838
|
+
/** The dashboard's own MCP tools. A `dashboard: true` tool may not take one of these names. */
|
|
4839
|
+
const DASHBOARD_MCP_TOOLS = [
|
|
4840
|
+
"summary",
|
|
4841
|
+
"list_requests",
|
|
4842
|
+
"get_trace",
|
|
4843
|
+
"list_errors",
|
|
4844
|
+
"app_overview",
|
|
4845
|
+
"search_logs",
|
|
4846
|
+
"list_reloads",
|
|
4847
|
+
"list_schedules",
|
|
4848
|
+
"list_runs",
|
|
4849
|
+
"get_run",
|
|
4850
|
+
"get_openapi",
|
|
4851
|
+
"list_docs",
|
|
4852
|
+
"read_doc"
|
|
4853
|
+
];
|
|
4756
4854
|
const MIN_TOKEN_LENGTH = 16;
|
|
4757
4855
|
/**
|
|
4758
4856
|
* Check what `brick()` was given, and freeze it. The secrets sit behind a getter
|
|
@@ -4761,16 +4859,18 @@ const MIN_TOKEN_LENGTH = 16;
|
|
|
4761
4859
|
*/
|
|
4762
4860
|
function normalizeDashboard(options) {
|
|
4763
4861
|
if (options === void 0) return void 0;
|
|
4764
|
-
const { port, host, auth, historyDays, inspector } = options;
|
|
4862
|
+
const { port, host, auth, historyDays, inspector, mcp } = options;
|
|
4765
4863
|
if (port !== void 0 && (!Number.isInteger(port) || port < 1 || port > 65535)) throw new Error(`Brick: dashboard port must be an integer from 1 to 65535, not ${String(port)}.`);
|
|
4766
4864
|
if (host !== void 0 && (typeof host !== "string" || host.trim() === "")) throw new Error("Brick: dashboard host must be an address, such as '0.0.0.0'.");
|
|
4767
4865
|
if (historyDays !== void 0 && (!Number.isInteger(historyDays) || historyDays < 0)) throw new Error(`Brick: dashboard historyDays must be a whole number of days, not ${String(historyDays)}.`);
|
|
4768
4866
|
if (inspector !== void 0 && typeof inspector !== "boolean") throw new Error("Brick: dashboard inspector must be true or false.");
|
|
4867
|
+
if (mcp !== void 0 && typeof mcp !== "boolean") throw new Error("Brick: dashboard mcp must be true or false.");
|
|
4769
4868
|
const normalized = {
|
|
4770
4869
|
...port !== void 0 ? { port } : {},
|
|
4771
4870
|
...host !== void 0 ? { host: host.trim() } : {},
|
|
4772
4871
|
...historyDays !== void 0 ? { historyDays } : {},
|
|
4773
|
-
...inspector !== void 0 ? { inspector } : {}
|
|
4872
|
+
...inspector !== void 0 ? { inspector } : {},
|
|
4873
|
+
...mcp !== void 0 ? { mcp } : {}
|
|
4774
4874
|
};
|
|
4775
4875
|
if (auth !== void 0) {
|
|
4776
4876
|
const tokens = auth.token === void 0 ? void 0 : typeof auth.token === "string" ? [auth.token] : [...auth.token];
|
|
@@ -4788,6 +4888,141 @@ function normalizeDashboard(options) {
|
|
|
4788
4888
|
}
|
|
4789
4889
|
return Object.freeze(normalized);
|
|
4790
4890
|
}
|
|
4891
|
+
// src/mcp.ts
|
|
4892
|
+
var UnknownToolError = class extends Error {
|
|
4893
|
+
constructor(name) {
|
|
4894
|
+
super(`unknown tool: ${name}`);
|
|
4895
|
+
this.name = "UnknownToolError";
|
|
4896
|
+
}
|
|
4897
|
+
};
|
|
4898
|
+
/** Collect only explicitly defined tools, without exposing ordinary actions. */
|
|
4899
|
+
function createMcpRegistry(options) {
|
|
4900
|
+
function toolsByName() {
|
|
4901
|
+
const tools = /* @__PURE__ */ new Map();
|
|
4902
|
+
for (const tool of [...options.tools ?? [], ...(options.services ?? []).flatMap((service) => service.listTools())]) {
|
|
4903
|
+
const existing = tools.get(tool.name);
|
|
4904
|
+
if (existing && existing !== tool) throw new DuplicateNameError(`Duplicate MCP tool: ${tool.name}`);
|
|
4905
|
+
tools.set(tool.name, tool);
|
|
4906
|
+
}
|
|
4907
|
+
return tools;
|
|
4908
|
+
}
|
|
4909
|
+
toolsByName();
|
|
4910
|
+
return {
|
|
4911
|
+
listTools: () => Array.from(toolsByName().values(), (tool) => ({
|
|
4912
|
+
name: tool.name,
|
|
4913
|
+
...tool.config.title ?? tool.config.annotations?.title ? { title: tool.config.title ?? tool.config.annotations?.title } : {},
|
|
4914
|
+
description: tool.config.description ?? "",
|
|
4915
|
+
inputSchema: tool.config.input ?? {
|
|
4916
|
+
type: "object",
|
|
4917
|
+
properties: {},
|
|
4918
|
+
additionalProperties: false
|
|
4919
|
+
},
|
|
4920
|
+
...tool.config.output ? { outputSchema: outputSchema(tool.config.output) } : {},
|
|
4921
|
+
annotations: tool.config.annotations ?? {}
|
|
4922
|
+
})),
|
|
4923
|
+
async callTool(name, args = {}, ctx) {
|
|
4924
|
+
const tool = toolsByName().get(name);
|
|
4925
|
+
if (!tool) throw new UnknownToolError(name);
|
|
4926
|
+
return tool({
|
|
4927
|
+
input: args,
|
|
4928
|
+
ctx
|
|
4929
|
+
});
|
|
4930
|
+
}
|
|
4931
|
+
};
|
|
4932
|
+
}
|
|
4933
|
+
const WRAP_RESULT = "x-brick-wrap-result";
|
|
4934
|
+
function outputSchema(schema) {
|
|
4935
|
+
return schema.type === "object" ? schema : {
|
|
4936
|
+
type: "object",
|
|
4937
|
+
properties: { result: schema },
|
|
4938
|
+
required: ["result"],
|
|
4939
|
+
[WRAP_RESULT]: true
|
|
4940
|
+
};
|
|
4941
|
+
}
|
|
4942
|
+
function result(id, value) {
|
|
4943
|
+
return Response.json({
|
|
4944
|
+
jsonrpc: "2.0",
|
|
4945
|
+
id,
|
|
4946
|
+
result: value
|
|
4947
|
+
});
|
|
4948
|
+
}
|
|
4949
|
+
function rpcError(id, code, message) {
|
|
4950
|
+
return Response.json({
|
|
4951
|
+
jsonrpc: "2.0",
|
|
4952
|
+
id,
|
|
4953
|
+
error: {
|
|
4954
|
+
code,
|
|
4955
|
+
message
|
|
4956
|
+
}
|
|
4957
|
+
});
|
|
4958
|
+
}
|
|
4959
|
+
function isRecord(value) {
|
|
4960
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
4961
|
+
}
|
|
4962
|
+
/** Stateless MCP JSON-RPC POST handler. Wrap with the app's authentication. */
|
|
4963
|
+
function createMcpHandler(options) {
|
|
4964
|
+
const versions = options.protocolVersions ?? ["2025-06-18"];
|
|
4965
|
+
if (!versions.length) throw new Error("At least one MCP protocol version is required");
|
|
4966
|
+
return async (request, ctx) => {
|
|
4967
|
+
if (request.method !== "POST") return new Response(null, {
|
|
4968
|
+
status: 405,
|
|
4969
|
+
headers: { Allow: "POST" }
|
|
4970
|
+
});
|
|
4971
|
+
if (options.clientIp) withClientIp(request, options.clientIp);
|
|
4972
|
+
let body;
|
|
4973
|
+
try {
|
|
4974
|
+
body = await request.json();
|
|
4975
|
+
} catch {
|
|
4976
|
+
return rpcError(null, -32700, "parse error");
|
|
4977
|
+
}
|
|
4978
|
+
if (!isRecord(body) || body.jsonrpc !== "2.0" || typeof body.method !== "string" || body.id !== void 0 && body.id !== null && typeof body.id !== "string" && typeof body.id !== "number" || body.params !== void 0 && !isRecord(body.params)) return rpcError(null, -32600, "invalid request");
|
|
4979
|
+
if (body.id === void 0) return new Response(null, { status: 202 });
|
|
4980
|
+
const { id, method } = body;
|
|
4981
|
+
const params = body.params;
|
|
4982
|
+
switch (method) {
|
|
4983
|
+
case "initialize": {
|
|
4984
|
+
const requested = params?.protocolVersion;
|
|
4985
|
+
return result(id, {
|
|
4986
|
+
capabilities: { tools: {} },
|
|
4987
|
+
protocolVersion: typeof requested === "string" && versions.includes(requested) ? requested : versions[0],
|
|
4988
|
+
serverInfo: options.serverInfo
|
|
4989
|
+
});
|
|
4990
|
+
}
|
|
4991
|
+
case "ping": return result(id, {});
|
|
4992
|
+
case "tools/list": try {
|
|
4993
|
+
return result(id, { tools: options.registry.listTools() });
|
|
4994
|
+
} catch {
|
|
4995
|
+
return rpcError(id, -32603, "internal error");
|
|
4996
|
+
}
|
|
4997
|
+
case "tools/call":
|
|
4998
|
+
if (typeof params?.name !== "string" || params.arguments !== void 0 && !isRecord(params.arguments)) return rpcError(id, -32602, "invalid tool parameters");
|
|
4999
|
+
try {
|
|
5000
|
+
const value = await options.registry.callTool(params.name, params.arguments, {
|
|
5001
|
+
...ctx,
|
|
5002
|
+
request
|
|
5003
|
+
});
|
|
5004
|
+
const schema = options.registry.listTools().find((tool) => tool.name === params.name)?.outputSchema;
|
|
5005
|
+
return result(id, {
|
|
5006
|
+
content: [{
|
|
5007
|
+
type: "text",
|
|
5008
|
+
text: typeof value === "string" ? value : JSON.stringify(value, null, 2) ?? "null"
|
|
5009
|
+
}],
|
|
5010
|
+
...schema ? { structuredContent: schema["x-brick-wrap-result"] ? { result: value } : value } : {}
|
|
5011
|
+
});
|
|
5012
|
+
} catch (error) {
|
|
5013
|
+
if (error instanceof UnknownToolError) return rpcError(id, -32602, error.message);
|
|
5014
|
+
return result(id, {
|
|
5015
|
+
content: [{
|
|
5016
|
+
type: "text",
|
|
5017
|
+
text: error instanceof Error ? error.message : String(error)
|
|
5018
|
+
}],
|
|
5019
|
+
isError: true
|
|
5020
|
+
});
|
|
5021
|
+
}
|
|
5022
|
+
default: return rpcError(id, -32601, `method not found: ${method}`);
|
|
5023
|
+
}
|
|
5024
|
+
};
|
|
5025
|
+
}
|
|
4791
5026
|
// src/endpoints.ts
|
|
4792
5027
|
/** Resolve the db for an endpoint: explicit service first, else first service holding one. */
|
|
4793
5028
|
function resolveEndpointDb(service, services) {
|
|
@@ -6691,7 +6926,10 @@ function brick(options = {}) {
|
|
|
6691
6926
|
} : options.events;
|
|
6692
6927
|
const events = eventsOptions ? new EventsHub(eventsOptions, appDeps(services)).attach(services) : void 0;
|
|
6693
6928
|
if (events?.workflows) app.all(WEBHOOK_ROUTE, ({ request }) => events.webhook(request));
|
|
6694
|
-
if (telemetry)
|
|
6929
|
+
if (telemetry) {
|
|
6930
|
+
for (const service of services) instrumentDatabase(service.getDb());
|
|
6931
|
+
instrumentFetch();
|
|
6932
|
+
}
|
|
6695
6933
|
for (const service of services) service.build();
|
|
6696
6934
|
for (const service of services) checkFileStorages(service, [portOf(service).deps, ...installedPlugins(service).map(pluginDepsOf)]);
|
|
6697
6935
|
const localDirs = localFileDirs([...services.map((service) => portOf(service).deps), ...plugins.deps]);
|
|
@@ -6722,6 +6960,38 @@ function brick(options = {}) {
|
|
|
6722
6960
|
builtIn(swaggerPath, htmlResponse(swaggerDocsHTML(openApiPath, title)));
|
|
6723
6961
|
}
|
|
6724
6962
|
builtIn("/_brick/services", (context) => architecture(context));
|
|
6963
|
+
const dashboardTools = [];
|
|
6964
|
+
const dashboardToolService = /* @__PURE__ */ new Map();
|
|
6965
|
+
for (const service of services) for (const tool of service.listTools()) {
|
|
6966
|
+
if (tool.config.dashboard !== true) continue;
|
|
6967
|
+
if (DASHBOARD_MCP_TOOLS.includes(tool.name)) throw new DuplicateNameError(`Brick: the tool '${tool.name}' is marked dashboard: true, but the dashboard's MCP endpoint has a tool of that name. Rename yours.`);
|
|
6968
|
+
const other = dashboardToolService.get(tool.name);
|
|
6969
|
+
if (other !== void 0) throw new DuplicateNameError(`Brick: the services '${other}' and '${service.name}' both have a tool '${tool.name}' marked dashboard: true. The dashboard's MCP endpoint needs one name per tool, so rename one of them.`);
|
|
6970
|
+
dashboardToolService.set(tool.name, service.name);
|
|
6971
|
+
dashboardTools.push(tool);
|
|
6972
|
+
}
|
|
6973
|
+
const toolRegistry = createMcpRegistry({ tools: dashboardTools });
|
|
6974
|
+
const readsOnly = (tool) => tool.annotations.readOnlyHint === true;
|
|
6975
|
+
const forCaller = (write) => ({
|
|
6976
|
+
listTools: () => toolRegistry.listTools().filter((tool) => write || readsOnly(tool)),
|
|
6977
|
+
callTool(name, args, ctx) {
|
|
6978
|
+
const tool = toolRegistry.listTools().find((item) => item.name === name);
|
|
6979
|
+
if (tool && !write && !readsOnly(tool)) throw new Error(`${name} can change data, so only a signed-in user may call it: dashboard.auth.authorize must return { user }. A token, or authorize returning true, can only read.`);
|
|
6980
|
+
return toolRegistry.callTool(name, args, ctx);
|
|
6981
|
+
}
|
|
6982
|
+
});
|
|
6983
|
+
const mcpHandlers = [false, true].map((write) => createMcpHandler({
|
|
6984
|
+
registry: forCaller(write),
|
|
6985
|
+
serverInfo: {
|
|
6986
|
+
name: title,
|
|
6987
|
+
version
|
|
6988
|
+
}
|
|
6989
|
+
}));
|
|
6990
|
+
app.post(DASHBOARD_MCP_ROUTE, ({ request }) => {
|
|
6991
|
+
const caller = dashboardMcpCaller(request);
|
|
6992
|
+
return caller ? mcpHandlers[caller.write ? 1 : 0](request, { dashboard: caller.user ? { user: caller.user } : {} }) : new Response("Unauthorized", { status: 401 });
|
|
6993
|
+
});
|
|
6994
|
+
registeredRoutes.set(routeKey("POST", DASHBOARD_MCP_ROUTE), false);
|
|
6725
6995
|
const sockets = services.flatMap((service) => service.listSockets().map((definition) => ({
|
|
6726
6996
|
service: service.name,
|
|
6727
6997
|
path: socketPath(prefix, service.name, definition),
|
|
@@ -6883,6 +7153,6 @@ function cachedJsonRoute(build, revision) {
|
|
|
6883
7153
|
return json;
|
|
6884
7154
|
};
|
|
6885
7155
|
}
|
|
6886
|
-
export {
|
|
7156
|
+
export { auditStage as $, hasSensitive as $t, defineListener as A, listSecrets as At, INTERNALS as B, hasIdentity as Bt, getGlobalRegistry as C, redisBroker as Ct, loadCompiledBrickApp as D, SecretRef as Dt, compileBrickApplication as E, scopeFiles as Et, eventRefs as F, definitionSite as Ft, installPlugin as G, signDashboardIdentity as Gt, defineServicePlugin as H, DASHBOARD_KEY_ENV as Ht, isCrudEvent as I, depsOverride as It, validateName as J, fileFields as Jt, isInstallingPlugin as K, signDashboardMcp as Kt, isBrickApp as L, freezeAsBuiltDeps as Lt, checkPayload as M, resetSecrets as Mt, crudEventName as N, resolveSecrets as Nt, WORKFLOW_BUNDLE as O, defineSecret as Ot, crudEventSource as P, claimName as Pt, deny as Q, Sensitive as Qt, requireBrickApp as R, useDeps as Rt, setActionAudit as S, redis as St, bindCompiledApplication as T, s3 as Tt, getPluginEndpoints as U, dashboardKey as Ut, defineResourcePlugin as V, DASHBOARD_IDENTITY_HEADER as Vt, hasPlugin as W, dashboardUser as Wt, defineAction as X, traceRoute as Xt, buildErrorHelpers as Y, validateWithSchema as Yt, errorsOf as Z, withCallSpan as Zt, scalarDocsHTML as _, clientAddress as _t, defineSchedule as a, recordInline as at, getActionAccess as b, defineStorage as bt, outboxTable as c, checkWebhook as ct, createMcpHandler as d, webhookOf as dt, isSensitive as en, auditTable as et, createMcpRegistry as f, baseContext as ft, registerReferenceRoute as g, checkRateLimits as gt, referencePlugin as h, resolvedDeps as ht, stopAllEvents as i, PLUGIN_KIND as in, recordAudit as it, checkEvent as j, overrideSecret as jt, resolveWorkflowPaths as k, envSource as kt, UnknownToolError as l, defineWebhookMeta as lt, DASHBOARD_MCP_TOOLS as m, pickContextEnvelope as mt, defineServiceSocket as n, sensitivity as nn, inlineAudit as nt, Dispatcher as o, onTransactionCommit as ot, DASHBOARD_MCP_ROUTE as p, markResolved as pt, segmentClaimant as q, Type as qt, recordingServices as r, PLUGIN_COMMIT as rn, isAuditTable as rt, isOutboxTable as s, runInTransaction as st, brick as t, redact as tn, entryOf as tt, WRAP_RESULT as u, isWebhook as ut, requestLoggingPlugin as v, rateLimitsOf as vt, resetGlobalRegistry as w, hasFilesView as wt, setActionAccess as x, memory as xt, generateOpenApiSpec as y, StorageUnavailableError as yt, createActionHandler as z, portOf as zt };
|
|
6887
7157
|
|
|
6888
7158
|
//# sourceMappingURL=server.js.map
|