feat: add local auth support if api storage provided

This commit is contained in:
dswbx
2025-12-02 18:18:45 +01:00
parent 506c7d84cc
commit acc10377ca
20 changed files with 193 additions and 174 deletions

View File

@@ -1,4 +1,5 @@
import { McpClient, type McpClientConfig } from "jsonv-ts/mcp";
import { useApi } from "bknd/client";
import { useBknd } from "ui/client/bknd";
const clients = new Map<string, McpClient>();
@@ -12,5 +13,14 @@ export function getClient(opts: McpClientConfig) {
export function useMcpClient() {
const { config } = useBknd();
return getClient({ url: window.location.origin + config.server.mcp.path });
const api = useApi();
const token = api.getAuthState().token;
const headers =
api.token_transport === "header" && token ? { Authorization: `Bearer ${token}` } : undefined;
return getClient({
url: window.location.origin + config.server.mcp.path,
fetch: api.fetcher,
headers,
});
}

View File

@@ -12,7 +12,7 @@ import { useBrowserTitle } from "ui/hooks/use-browser-title";
export default function ToolsMcp() {
useBrowserTitle(["MCP UI"]);
const { config, options } = useBknd();
const { config } = useBknd();
const feature = useMcpStore((state) => state.feature);
const setFeature = useMcpStore((state) => state.setFeature);
const content = useMcpStore((state) => state.content);