mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
added getMcpClient to app
This commit is contained in:
@@ -136,4 +136,21 @@ describe("App", () => {
|
|||||||
// expect async listeners to be executed sync after request
|
// expect async listeners to be executed sync after request
|
||||||
expect(called).toHaveBeenCalled();
|
expect(called).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("getMcpClient", async () => {
|
||||||
|
const app = createApp({
|
||||||
|
initialConfig: {
|
||||||
|
server: {
|
||||||
|
mcp: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await app.build();
|
||||||
|
const client = app.getMcpClient();
|
||||||
|
const res = await client.listTools();
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(res?.tools.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CreateUserPayload } from "auth/AppAuth";
|
import type { CreateUserPayload } from "auth/AppAuth";
|
||||||
import { $console } from "bknd/utils";
|
import { $console, McpClient } from "bknd/utils";
|
||||||
import { Event } from "core/events";
|
import { Event } from "core/events";
|
||||||
import type { em as prototypeEm } from "data/prototype";
|
import type { em as prototypeEm } from "data/prototype";
|
||||||
import { Connection } from "data/connection/Connection";
|
import { Connection } from "data/connection/Connection";
|
||||||
@@ -268,6 +268,17 @@ export class App<C extends Connection = Connection, Options extends AppOptions =
|
|||||||
return new Api({ host: "http://localhost", ...(options ?? {}), fetcher });
|
return new Api({ host: "http://localhost", ...(options ?? {}), fetcher });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMcpClient() {
|
||||||
|
if (!this.mcp) {
|
||||||
|
throw new Error("MCP is not enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new McpClient({
|
||||||
|
url: "http://localhost/mcp",
|
||||||
|
fetch: this.server.request,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async onUpdated<Module extends keyof Modules>(module: Module, config: ModuleConfigs[Module]) {
|
async onUpdated<Module extends keyof Modules>(module: Module, config: ModuleConfigs[Module]) {
|
||||||
// if the EventManager was disabled, we assume we shouldn't
|
// if the EventManager was disabled, we assume we shouldn't
|
||||||
// respond to events, such as "onUpdated".
|
// respond to events, such as "onUpdated".
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export {
|
|||||||
mcpResource,
|
mcpResource,
|
||||||
getMcpServer,
|
getMcpServer,
|
||||||
stdioTransport,
|
stdioTransport,
|
||||||
|
McpClient,
|
||||||
|
type McpClientConfig,
|
||||||
type ToolAnnotation,
|
type ToolAnnotation,
|
||||||
type ToolHandlerCtx,
|
type ToolHandlerCtx,
|
||||||
} from "jsonv-ts/mcp";
|
} from "jsonv-ts/mcp";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export const McpIcon = () => (
|
export const McpIcon = () => (
|
||||||
<svg
|
<svg
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
fill-rule="evenodd"
|
fillRule="evenodd"
|
||||||
height="1em"
|
height="1em"
|
||||||
style={{ flex: "none", lineHeight: "1" }}
|
style={{ flex: "none", lineHeight: "1" }}
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
|
|||||||
Reference in New Issue
Block a user