mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
optimized performance
This commit is contained in:
@@ -6,9 +6,8 @@ import type { Hono } from "hono";
|
||||
import type { ServerEnv } from "modules/Controller";
|
||||
import type { ModuleHelper } from "./ModuleHelper";
|
||||
import { SchemaObject } from "core/object/SchemaObject";
|
||||
import type { DebugLogger } from "core/utils/DebugLogger";
|
||||
import type { Guard } from "auth/authorize/Guard";
|
||||
import type { McpServer } from "bknd/utils";
|
||||
import type { McpServer, DebugLogger } from "bknd/utils";
|
||||
|
||||
type PartialRec<T> = { [P in keyof T]?: PartialRec<T[P]> };
|
||||
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { mark, stripMark, $console, s, objectEach, transformObject, McpServer } from "bknd/utils";
|
||||
import {
|
||||
mark,
|
||||
stripMark,
|
||||
$console,
|
||||
s,
|
||||
objectEach,
|
||||
transformObject,
|
||||
McpServer,
|
||||
DebugLogger,
|
||||
} from "bknd/utils";
|
||||
import { Guard } from "auth/authorize/Guard";
|
||||
import { env } from "core/env";
|
||||
import { BkndError } from "core/errors";
|
||||
import { DebugLogger } from "core/utils/DebugLogger";
|
||||
import { EventManager, Event } from "core/events";
|
||||
import * as $diff from "core/object/diff";
|
||||
import type { Connection } from "data/connection";
|
||||
|
||||
@@ -8,12 +8,9 @@ export function getSystemMcp(app: App) {
|
||||
|
||||
const appConfig = app.modules.configs();
|
||||
const { version, ...appSchema } = app.getSchema();
|
||||
|
||||
const schema = s.strictObject(appSchema);
|
||||
|
||||
const nodes = [...schema.walk({ data: appConfig })].filter(
|
||||
(n) => isObject(n.schema) && mcpSchemaSymbol in n.schema,
|
||||
) as s.Node<McpSchema>[];
|
||||
const result = [...schema.walk({ maxDepth: 3 })];
|
||||
const nodes = result.filter((n) => mcpSchemaSymbol in n.schema) as s.Node<McpSchema>[];
|
||||
const tools = [
|
||||
// tools from hono routes
|
||||
...middlewareServer.tools,
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
mcpTool,
|
||||
mcp as mcpMiddleware,
|
||||
isNode,
|
||||
type McpServer,
|
||||
} from "bknd/utils";
|
||||
import type { Context, Hono } from "hono";
|
||||
import { Controller } from "modules/Controller";
|
||||
@@ -47,6 +48,8 @@ export type SchemaResponse = {
|
||||
};
|
||||
|
||||
export class SystemController extends Controller {
|
||||
_mcpServer: McpServer | null = null;
|
||||
|
||||
constructor(private readonly app: App) {
|
||||
super();
|
||||
}
|
||||
@@ -64,8 +67,8 @@ export class SystemController extends Controller {
|
||||
|
||||
this.registerMcp();
|
||||
|
||||
const mcpServer = getSystemMcp(app);
|
||||
mcpServer.onNotification((message) => {
|
||||
this._mcpServer = getSystemMcp(app);
|
||||
this._mcpServer.onNotification((message) => {
|
||||
if (message.method === "notification/message") {
|
||||
const consoleMap = {
|
||||
emergency: "error",
|
||||
@@ -87,7 +90,7 @@ export class SystemController extends Controller {
|
||||
|
||||
app.server.use(
|
||||
mcpMiddleware({
|
||||
server: mcpServer,
|
||||
server: this._mcpServer,
|
||||
sessionsEnabled: true,
|
||||
debug: {
|
||||
logLevel: "debug",
|
||||
|
||||
Reference in New Issue
Block a user