mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
added initial $record
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import type { CliCommand } from "cli/types";
|
||||
import { makeAppFromEnv } from "../run";
|
||||
import { s, mcp as mcpMiddleware, McpServer } from "bknd/utils";
|
||||
import { ObjectToolSchema } from "modules/mcp";
|
||||
import { s, mcp as mcpMiddleware, McpServer, isObject } from "bknd/utils";
|
||||
import type { McpSchema } from "modules/mcp";
|
||||
import { serve } from "@hono/node-server";
|
||||
import { Hono } from "hono";
|
||||
import type { Module } from "modules/Module";
|
||||
import { mcpSchemaSymbol } from "modules/mcp/McpSchemaHelper";
|
||||
|
||||
export const mcp: CliCommand = (program) =>
|
||||
program
|
||||
@@ -25,8 +25,8 @@ async function action(options: { port: string; path: string }) {
|
||||
const schema = s.strictObject(appSchema);
|
||||
|
||||
const nodes = [...schema.walk({ data: appConfig })].filter(
|
||||
(n) => n.schema instanceof ObjectToolSchema,
|
||||
) as s.Node<ObjectToolSchema>[];
|
||||
(n) => isObject(n.schema) && mcpSchemaSymbol in n.schema,
|
||||
) as s.Node<McpSchema>[];
|
||||
const tools = [...nodes.flatMap((n) => n.schema.getTools(n)), ...app.modules.ctx().mcp.tools];
|
||||
const resources = [...app.modules.ctx().mcp.resources];
|
||||
|
||||
@@ -39,43 +39,6 @@ async function action(options: { port: string; path: string }) {
|
||||
tools,
|
||||
resources,
|
||||
);
|
||||
server
|
||||
.resource("system_config", "bknd://system/config", (c) =>
|
||||
c.json(c.context.app.toJSON(), {
|
||||
title: "System Config",
|
||||
}),
|
||||
)
|
||||
.resource(
|
||||
"system_config_module",
|
||||
"bknd://system/config/{module}",
|
||||
(c, { module }) => {
|
||||
const m = c.context.app.modules.get(module as any) as Module;
|
||||
return c.json(m.toJSON(), {
|
||||
title: `Config for ${module}`,
|
||||
});
|
||||
},
|
||||
{
|
||||
list: Object.keys(appConfig),
|
||||
},
|
||||
)
|
||||
.resource("system_schema", "bknd://system/schema", (c) =>
|
||||
c.json(c.context.app.getSchema(), {
|
||||
title: "System Schema",
|
||||
}),
|
||||
)
|
||||
.resource(
|
||||
"system_schema_module",
|
||||
"bknd://system/schema/{module}",
|
||||
(c, { module }) => {
|
||||
const m = c.context.app.modules.get(module as any);
|
||||
return c.json(m.getSchema().toJSON(), {
|
||||
title: `Schema for ${module}`,
|
||||
});
|
||||
},
|
||||
{
|
||||
list: Object.keys(appSchema),
|
||||
},
|
||||
);
|
||||
|
||||
const hono = new Hono().use(
|
||||
mcpMiddleware({
|
||||
@@ -91,6 +54,10 @@ async function action(options: { port: string; path: string }) {
|
||||
port: Number(options.port) || 3000,
|
||||
});
|
||||
console.info(`Server is running on http://localhost:${options.port}${options.path}`);
|
||||
console.info(`⚙️ Tools:\n${server.tools.map((t) => `- ${t.name}`).join("\n")}\n`);
|
||||
console.info(`📚 Resources:\n${server.resources.map((r) => `- ${r.name}`).join("\n")}`);
|
||||
console.info(
|
||||
`⚙️ Tools (${server.tools.length}):\n${server.tools.map((t) => `- ${t.name}`).join("\n")}\n`,
|
||||
);
|
||||
console.info(
|
||||
`📚 Resources (${server.resources.length}):\n${server.resources.map((r) => `- ${r.name}`).join("\n")}`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user