mcp: improve auth id type + styling fixes

This commit is contained in:
dswbx
2025-08-21 10:58:31 +02:00
parent f9184a71db
commit dcf88cf587
8 changed files with 110 additions and 99 deletions

View File

@@ -204,6 +204,7 @@ export class AuthController extends Controller {
override registerMcp(): void { override registerMcp(): void {
const { mcp } = this.auth.ctx; const { mcp } = this.auth.ctx;
const idType = s.anyOf([s.number({ title: "Integer" }), s.string({ title: "UUID" })]);
const getUser = async (params: { id?: string | number; email?: string }) => { const getUser = async (params: { id?: string | number; email?: string }) => {
let user: DB["users"] | undefined = undefined; let user: DB["users"] | undefined = undefined;
@@ -248,7 +249,7 @@ export class AuthController extends Controller {
{ {
description: "Get a user token", description: "Get a user token",
inputSchema: s.object({ inputSchema: s.object({
id: s.anyOf([s.string(), s.number()]).optional(), id: idType.optional(),
email: s.string({ format: "email" }).optional(), email: s.string({ format: "email" }).optional(),
}), }),
}, },
@@ -266,7 +267,7 @@ export class AuthController extends Controller {
{ {
description: "Change a user's password", description: "Change a user's password",
inputSchema: s.object({ inputSchema: s.object({
id: s.anyOf([s.string(), s.number()]).optional(), id: idType.optional(),
email: s.string({ format: "email" }).optional(), email: s.string({ format: "email" }).optional(),
password: s.string({ minLength: 8 }), password: s.string({ minLength: 8 }),
}), }),

View File

@@ -316,6 +316,7 @@ export class DataController extends Controller {
param: s.object({ entity: entitiesEnum, id: idType }), param: s.object({ entity: entitiesEnum, id: idType }),
query: saveRepoQuerySchema(["offset", "sort", "select"]), query: saveRepoQuerySchema(["offset", "sort", "select"]),
}, },
noErrorCodes: [404],
}), }),
jsc( jsc(
"param", "param",

View File

@@ -101,25 +101,25 @@ export const JsonViewerTabs = forwardRef<JsonViewerTabsRef, JsonViewerTabsProps>
})); }));
return ( return (
<div className="flex flex-col bg-primary/5 rounded-md"> <div className="flex flex-col bg-primary/5 rounded-md flex-shrink-0">
<div className="flex flex-row gap-4 border-b px-3 border-primary/10"> <div className="flex flex-row gap-4 border-b px-3 border-primary/10 min-w-0">
{Object.keys(tabs).map((key) => ( {Object.keys(tabs).map((key) => (
<button <button
key={key} key={key}
type="button" type="button"
className={twMerge( className={twMerge(
"flex flex-row text-sm cursor-pointer py-3 pt-3.5 px-1 border-b border-transparent -mb-px transition-opacity", "flex flex-row text-sm cursor-pointer py-3 pt-3.5 px-1 border-b border-transparent -mb-px transition-opacity flex-shrink-0",
selected === key ? "border-primary" : "opacity-50 hover:opacity-70", selected === key ? "border-primary" : "opacity-50 hover:opacity-70",
)} )}
onClick={() => setSelected(key)} onClick={() => setSelected(key)}
> >
<span className="font-mono leading-none">{key}</span> <span className="font-mono leading-none truncate">{key}</span>
</button> </button>
))} ))}
</div> </div>
{/* @ts-ignore */} {/* @ts-ignore */}
<JsonViewer <JsonViewer
className="bg-transparent" className="bg-transparent overflow-x-auto"
{...defaultProps} {...defaultProps}
{...tabs[selected as any]} {...tabs[selected as any]}
title={undefined} title={undefined}

View File

@@ -13,7 +13,6 @@ import {
useFormValue, useFormValue,
} from "./Form"; } from "./Form";
import { getLabel, getMultiSchemaMatched } from "./utils"; import { getLabel, getMultiSchemaMatched } from "./utils";
import { FieldWrapper } from "ui/components/form/json-schema-form/FieldWrapper";
export type AnyOfFieldRootProps = { export type AnyOfFieldRootProps = {
path?: string; path?: string;

View File

@@ -109,7 +109,7 @@ export function Form<
const formRef = useRef<HTMLFormElement | null>(null); const formRef = useRef<HTMLFormElement | null>(null);
useEffect(() => { useEffect(() => {
if (initialValues) { if (initialValues && validateOn === "change") {
validate(); validate();
} }
}, [initialValues]); }, [initialValues]);

View File

@@ -67,7 +67,7 @@ export function Content({ children, center }: { children: React.ReactNode; cente
<main <main
data-shell="content" data-shell="content"
className={twMerge( className={twMerge(
"flex flex-1 flex-row w-dvw h-full", "flex flex-1 flex-row max-w-screen h-full",
center && "justify-center items-center", center && "justify-center items-center",
)} )}
> >
@@ -158,7 +158,9 @@ export function Sidebar({
data-shell="sidebar" data-shell="sidebar"
className="flex-col w-[var(--sidebar-width)] flex-shrink-0 flex-grow-0 h-full border-muted border-r bg-background" className="flex-col w-[var(--sidebar-width)] flex-shrink-0 flex-grow-0 h-full border-muted border-r bg-background"
> >
<MaxHeightContainer className="overflow-y-scroll md:overflow-y-hidden">
{children} {children}
</MaxHeightContainer>
</aside> </aside>
</div> </div>
</> </>

View File

@@ -25,7 +25,7 @@ export default function ToolsMcp() {
} }
return ( return (
<div className="flex flex-col flex-grow"> <div className="flex flex-col flex-grow max-w-screen">
<AppShell.SectionHeader> <AppShell.SectionHeader>
<div className="flex flex-row gap-4 items-center"> <div className="flex flex-row gap-4 items-center">
<McpIcon /> <McpIcon />
@@ -45,7 +45,6 @@ export default function ToolsMcp() {
<div className="flex h-full"> <div className="flex h-full">
<AppShell.Sidebar> <AppShell.Sidebar>
<AppShell.MaxHeightContainer className="overflow-y-scroll md:overflow-auto">
<Tools.Sidebar open={feature === "tools"} toggle={() => setFeature("tools")} /> <Tools.Sidebar open={feature === "tools"} toggle={() => setFeature("tools")} />
<AppShell.SectionHeaderAccordionItem <AppShell.SectionHeaderAccordionItem
title="Resources" title="Resources"
@@ -56,7 +55,6 @@ export default function ToolsMcp() {
<i>Resources</i> <i>Resources</i>
</div> </div>
</AppShell.SectionHeaderAccordionItem> </AppShell.SectionHeaderAccordionItem>
</AppShell.MaxHeightContainer>
</AppShell.Sidebar> </AppShell.Sidebar>
{feature === "tools" && <Tools.Content />} {feature === "tools" && <Tools.Content />}

View File

@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState } from "react"; import { useCallback, useEffect, useRef, useState, useTransition } from "react";
import { getClient, getTemplate } from "./utils"; import { getClient, getTemplate } from "./utils";
import { useMcpStore } from "./state"; import { useMcpStore } from "./state";
import { AppShell } from "ui/layouts/AppShell"; import { AppShell } from "ui/layouts/AppShell";
@@ -6,7 +6,7 @@ import { TbHistory, TbHistoryOff, TbRefresh } from "react-icons/tb";
import { IconButton } from "ui/components/buttons/IconButton"; import { IconButton } from "ui/components/buttons/IconButton";
import { JsonViewer, JsonViewerTabs, type JsonViewerTabsRef } from "ui/components/code/JsonViewer"; import { JsonViewer, JsonViewerTabs, type JsonViewerTabsRef } from "ui/components/code/JsonViewer";
import { twMerge } from "ui/elements/mocks/tailwind-merge"; import { twMerge } from "ui/elements/mocks/tailwind-merge";
import { Form } from "ui/components/form/json-schema-form"; import { Field, Form } from "ui/components/form/json-schema-form";
import { Button } from "ui/components/buttons/Button"; import { Button } from "ui/components/buttons/Button";
import * as Formy from "ui/components/form/Formy"; import * as Formy from "ui/components/form/Formy";
import { appShellStore } from "ui/store"; import { appShellStore } from "ui/store";
@@ -52,6 +52,7 @@ export function Sidebar({ open, toggle }) {
placeholder="Search tools" placeholder="Search tools"
value={query} value={query}
onChange={(e) => setQuery(e.target.value)} onChange={(e) => setQuery(e.target.value)}
autoCapitalize="none"
/> />
<nav className="flex flex-col flex-1 gap-1"> <nav className="flex flex-col flex-1 gap-1">
{tools {tools
@@ -91,6 +92,7 @@ export function Content() {
const jsonViewerTabsRef = useRef<JsonViewerTabsRef>(null); const jsonViewerTabsRef = useRef<JsonViewerTabsRef>(null);
const hasInputSchema = const hasInputSchema =
content?.inputSchema && Object.keys(content.inputSchema.properties ?? {}).length > 0; content?.inputSchema && Object.keys(content.inputSchema.properties ?? {}).length > 0;
const [isPending, startTransition] = useTransition();
useEffect(() => { useEffect(() => {
setPayload(getTemplate(content?.inputSchema)); setPayload(getTemplate(content?.inputSchema));
@@ -103,6 +105,7 @@ export function Content() {
name: content.name, name: content.name,
arguments: payload, arguments: payload,
}; };
startTransition(async () => {
addHistory("request", request); addHistory("request", request);
const res = await client.callTool(request); const res = await client.callTool(request);
if (res) { if (res) {
@@ -110,6 +113,7 @@ export function Content() {
addHistory("response", res); addHistory("response", res);
jsonViewerTabsRef.current?.setSelected("Result"); jsonViewerTabsRef.current?.setSelected("Result");
} }
});
}, [payload]); }, [payload]);
if (!content) return null; if (!content) return null;
@@ -124,20 +128,33 @@ export function Content() {
} catch (e) {} } catch (e) {}
return ( return (
<div className="flex flex-grow flex-col"> <div className="flex flex-grow flex-col max-w-screen">
<Form
key={content.name}
schema={{
title: "InputSchema",
...content?.inputSchema,
}}
validateOn="submit"
initialValues={payload}
hiddenSubmit={false}
onChange={(value) => {
setPayload(value);
}}
onSubmit={handleSubmit}
>
<AppShell.SectionHeader <AppShell.SectionHeader
className="max-w-full min-w-0 debug" className="max-w-full min-w-0"
right={ right={
<div className="flex flex-row gap-2"> <div className="flex flex-row gap-2">
<IconButton <IconButton
Icon={historyVisible ? TbHistoryOff : TbHistory} Icon={historyVisible ? TbHistory : TbHistoryOff}
onClick={() => setHistoryVisible(!historyVisible)} onClick={() => setHistoryVisible(!historyVisible)}
/> />
<Button <Button
type="button" type="submit"
disabled={!content?.name} disabled={!content?.name || isPending}
variant="primary" variant="primary"
onClick={handleSubmit}
className="whitespace-nowrap" className="whitespace-nowrap"
> >
Call Tool Call Tool
@@ -152,36 +169,28 @@ export function Content() {
<span className="truncate">{content?.name}</span> <span className="truncate">{content?.name}</span>
</AppShell.SectionHeaderTitle> </AppShell.SectionHeaderTitle>
</AppShell.SectionHeader> </AppShell.SectionHeader>
<div className="flex flex-grow flex-row w-full"> <div className="flex flex-grow flex-row w-vw">
<div className="flex flex-grow flex-col w-full"> <div className="flex flex-grow flex-col w-full">
<AppShell.Scrollable> <AppShell.Scrollable>
<div key={JSON.stringify(content)} className="flex flex-col py-4 px-5 gap-4"> <div key={JSON.stringify(content)} className="flex flex-col py-4 px-5 gap-4">
<p className="text-primary/80">{content?.description}</p> <p className="text-primary/80">{content?.description}</p>
{hasInputSchema && ( {hasInputSchema && <Field name="" />}
<Form
schema={{
title: "InputSchema",
...content?.inputSchema,
}}
initialValues={payload}
hiddenSubmit={false}
onChange={(value) => {
setPayload(value);
}}
/>
)}
<JsonViewerTabs <JsonViewerTabs
ref={jsonViewerTabsRef} ref={jsonViewerTabsRef}
expand={9} expand={9}
showCopy showCopy
showSize showSize
tabs={{ tabs={{
Arguments: { json: payload, title: "Payload", enabled: hasInputSchema }, Arguments: {
json: payload,
title: "Payload",
enabled: hasInputSchema,
},
Result: { json: readableResult, title: "Result" }, Result: { json: readableResult, title: "Result" },
"Tool Configuration": { Configuration: {
json: content ?? null, json: content ?? null,
title: "Tool Configuration", title: "Configuration",
}, },
}} }}
/> />
@@ -189,11 +198,12 @@ export function Content() {
</AppShell.Scrollable> </AppShell.Scrollable>
</div> </div>
{historyVisible && ( {historyVisible && (
<AppShell.Sidebar name="right" handle="left" maxWidth={window.innerWidth * 0.25}> <AppShell.Sidebar name="right" handle="left" maxWidth={window.innerWidth * 0.4}>
<History /> <History />
</AppShell.Sidebar> </AppShell.Sidebar>
)} )}
</div> </div>
</Form>
</div> </div>
); );
} }
@@ -211,7 +221,7 @@ const History = () => {
key={`${item.type}-${i}`} key={`${item.type}-${i}`}
json={item.data} json={item.data}
title={item.type} title={item.type}
expand={1} expand={2}
/> />
))} ))}
</div> </div>