Merge pull request #616 from erichoracek/dev/eh/tool-meta-support
feat: Add _meta field support to tool UI
This commit is contained in:
commit
aba186c955
3 changed files with 128 additions and 0 deletions
|
|
@ -154,6 +154,14 @@ const ToolResults = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{structuredResult._meta && (
|
||||||
|
<div className="mb-4">
|
||||||
|
<h5 className="font-semibold mb-2 text-sm">Meta:</h5>
|
||||||
|
<div className="bg-gray-50 dark:bg-gray-900 p-3 rounded-lg">
|
||||||
|
<JsonView data={structuredResult._meta} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{!structuredResult.structuredContent &&
|
{!structuredResult.structuredContent &&
|
||||||
validationResult &&
|
validationResult &&
|
||||||
!validationResult.isValid && (
|
!validationResult.isValid && (
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ import ListPane from "./ListPane";
|
||||||
import JsonView from "./JsonView";
|
import JsonView from "./JsonView";
|
||||||
import ToolResults from "./ToolResults";
|
import ToolResults from "./ToolResults";
|
||||||
|
|
||||||
|
// Type guard to safely detect the optional _meta field without using `any`
|
||||||
|
const hasMeta = (tool: Tool): tool is Tool & { _meta: unknown } =>
|
||||||
|
typeof (tool as { _meta?: unknown })._meta !== "undefined";
|
||||||
|
|
||||||
const ToolsTab = ({
|
const ToolsTab = ({
|
||||||
tools,
|
tools,
|
||||||
listTools,
|
listTools,
|
||||||
|
|
@ -46,6 +50,7 @@ const ToolsTab = ({
|
||||||
const [params, setParams] = useState<Record<string, unknown>>({});
|
const [params, setParams] = useState<Record<string, unknown>>({});
|
||||||
const [isToolRunning, setIsToolRunning] = useState(false);
|
const [isToolRunning, setIsToolRunning] = useState(false);
|
||||||
const [isOutputSchemaExpanded, setIsOutputSchemaExpanded] = useState(false);
|
const [isOutputSchemaExpanded, setIsOutputSchemaExpanded] = useState(false);
|
||||||
|
const [isMetaExpanded, setIsMetaExpanded] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = Object.entries(
|
const params = Object.entries(
|
||||||
|
|
@ -245,6 +250,40 @@ const ToolsTab = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{selectedTool &&
|
||||||
|
hasMeta(selectedTool) &&
|
||||||
|
selectedTool._meta && (
|
||||||
|
<div className="bg-gray-50 dark:bg-gray-900 p-3 rounded-lg">
|
||||||
|
<div className="flex items-center justify-between mb-2">
|
||||||
|
<h4 className="text-sm font-semibold">Meta:</h4>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => setIsMetaExpanded(!isMetaExpanded)}
|
||||||
|
className="h-6 px-2"
|
||||||
|
>
|
||||||
|
{isMetaExpanded ? (
|
||||||
|
<>
|
||||||
|
<ChevronUp className="h-3 w-3 mr-1" />
|
||||||
|
Collapse
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ChevronDown className="h-3 w-3 mr-1" />
|
||||||
|
Expand
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={`transition-all ${
|
||||||
|
isMetaExpanded ? "" : "max-h-[8rem] overflow-y-auto"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<JsonView data={selectedTool._meta} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import ToolsTab from "../ToolsTab";
|
||||||
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
||||||
import { Tabs } from "@/components/ui/tabs";
|
import { Tabs } from "@/components/ui/tabs";
|
||||||
import { cacheToolOutputSchemas } from "@/utils/schemaUtils";
|
import { cacheToolOutputSchemas } from "@/utils/schemaUtils";
|
||||||
|
import { within } from "@testing-library/react";
|
||||||
|
|
||||||
describe("ToolsTab", () => {
|
describe("ToolsTab", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
@ -556,4 +557,84 @@ describe("ToolsTab", () => {
|
||||||
expect(mockOnReadResource).toHaveBeenCalledTimes(1);
|
expect(mockOnReadResource).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Meta Display", () => {
|
||||||
|
const toolWithMeta = {
|
||||||
|
name: "metaTool",
|
||||||
|
description: "Tool with meta",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object" as const,
|
||||||
|
properties: {
|
||||||
|
foo: { type: "string" as const },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
_meta: {
|
||||||
|
author: "tester",
|
||||||
|
version: 1,
|
||||||
|
},
|
||||||
|
} as unknown as Tool;
|
||||||
|
|
||||||
|
it("should display meta section when tool has _meta", () => {
|
||||||
|
renderToolsTab({
|
||||||
|
tools: [toolWithMeta],
|
||||||
|
selectedTool: toolWithMeta,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(screen.getByText("Meta:")).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.getByRole("button", { name: /expand/i }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should toggle meta expansion", () => {
|
||||||
|
renderToolsTab({
|
||||||
|
tools: [toolWithMeta],
|
||||||
|
selectedTool: toolWithMeta,
|
||||||
|
});
|
||||||
|
|
||||||
|
// There might be multiple Expand buttons (Output Schema, Meta). We need the one within Meta section
|
||||||
|
const metaHeading = screen.getByText("Meta:");
|
||||||
|
const metaContainer = metaHeading.closest("div");
|
||||||
|
expect(metaContainer).toBeTruthy();
|
||||||
|
const toggleButton = within(metaContainer as HTMLElement).getByRole(
|
||||||
|
"button",
|
||||||
|
{ name: /expand/i },
|
||||||
|
);
|
||||||
|
|
||||||
|
// Expand Meta
|
||||||
|
fireEvent.click(toggleButton);
|
||||||
|
expect(
|
||||||
|
within(metaContainer as HTMLElement).getByRole("button", {
|
||||||
|
name: /collapse/i,
|
||||||
|
}),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
|
||||||
|
// Collapse Meta
|
||||||
|
fireEvent.click(toggleButton);
|
||||||
|
expect(
|
||||||
|
within(metaContainer as HTMLElement).getByRole("button", {
|
||||||
|
name: /expand/i,
|
||||||
|
}),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ToolResults Meta", () => {
|
||||||
|
it("should display meta information when present in toolResult", () => {
|
||||||
|
const resultWithMeta = {
|
||||||
|
content: [],
|
||||||
|
_meta: { info: "details", version: 2 },
|
||||||
|
};
|
||||||
|
|
||||||
|
renderToolsTab({
|
||||||
|
selectedTool: mockTools[0],
|
||||||
|
toolResult: resultWithMeta,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Only ToolResults meta should be present since selectedTool has no _meta
|
||||||
|
expect(screen.getAllByText("Meta:")).toHaveLength(1);
|
||||||
|
expect(screen.getByText(/info/i)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/version/i)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue