Aligned naming
This commit is contained in:
parent
159a049f94
commit
8f28ea791b
4 changed files with 54 additions and 51 deletions
|
|
@ -808,7 +808,7 @@ const App = () => {
|
|||
const callTool = async (
|
||||
name: string,
|
||||
params: Record<string, unknown>,
|
||||
meta?: Record<string, unknown>,
|
||||
metadata?: Record<string, unknown>,
|
||||
) => {
|
||||
lastToolCallOriginTabRef.current = currentTabRef.current;
|
||||
|
||||
|
|
@ -824,7 +824,7 @@ const App = () => {
|
|||
const mergedMeta = {
|
||||
...metadata, // General metadata first
|
||||
progressToken: progressTokenRef.current++,
|
||||
...(meta ?? {}), // Tool-specific metadata overrides
|
||||
...(metadata ?? {}), // Tool-specific metadata overrides
|
||||
};
|
||||
|
||||
const response = await sendMCPRequest(
|
||||
|
|
@ -1148,11 +1148,11 @@ const App = () => {
|
|||
callTool={async (
|
||||
name: string,
|
||||
params: Record<string, unknown>,
|
||||
meta?: Record<string, unknown>,
|
||||
metadata?: Record<string, unknown>,
|
||||
) => {
|
||||
clearError("tools");
|
||||
setToolResult(null);
|
||||
await callTool(name, params, meta);
|
||||
await callTool(name, params, metadata);
|
||||
}}
|
||||
selectedTool={selectedTool}
|
||||
setSelectedTool={(tool) => {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ const ToolsTab = ({
|
|||
callTool: (
|
||||
name: string,
|
||||
params: Record<string, unknown>,
|
||||
meta?: Record<string, unknown>,
|
||||
metadata?: Record<string, unknown>,
|
||||
) => Promise<void>;
|
||||
selectedTool: Tool | null;
|
||||
setSelectedTool: (tool: Tool | null) => void;
|
||||
|
|
@ -76,8 +76,8 @@ const ToolsTab = ({
|
|||
const [params, setParams] = useState<Record<string, unknown>>({});
|
||||
const [isToolRunning, setIsToolRunning] = useState(false);
|
||||
const [isOutputSchemaExpanded, setIsOutputSchemaExpanded] = useState(false);
|
||||
const [isMetaExpanded, setIsMetaExpanded] = useState(false);
|
||||
const [metaEntries, setMetaEntries] = useState<
|
||||
const [isMetadataExpanded, setIsMetadataExpanded] = useState(false);
|
||||
const [metadataEntries, setMetadataEntries] = useState<
|
||||
{ id: string; key: string; value: string }[]
|
||||
>([]);
|
||||
const [hasValidationErrors, setHasValidationErrors] = useState(false);
|
||||
|
|
@ -400,7 +400,7 @@ const ToolsTab = ({
|
|||
variant="outline"
|
||||
className="h-6 px-2"
|
||||
onClick={() =>
|
||||
setMetaEntries((prev) => [
|
||||
setMetadataEntries((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id:
|
||||
|
|
@ -419,30 +419,30 @@ const ToolsTab = ({
|
|||
Add Pair
|
||||
</Button>
|
||||
</div>
|
||||
{metaEntries.length === 0 ? (
|
||||
{metadataEntries.length === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
No meta pairs.
|
||||
No metadata pairs.
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{metaEntries.map((entry, index) => (
|
||||
{metadataEntries.map((entry, index) => (
|
||||
<div
|
||||
key={entry.id}
|
||||
className="flex items-center gap-2 w-full"
|
||||
>
|
||||
<Label
|
||||
htmlFor={`meta-key-${entry.id}`}
|
||||
htmlFor={`metadata-key-${entry.id}`}
|
||||
className="text-xs shrink-0"
|
||||
>
|
||||
Key
|
||||
</Label>
|
||||
<Input
|
||||
id={`meta-key-${entry.id}`}
|
||||
id={`metadata-key-${entry.id}`}
|
||||
value={entry.key}
|
||||
placeholder="e.g. requestId"
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setMetaEntries((prev) =>
|
||||
setMetadataEntries((prev) =>
|
||||
prev.map((m, i) =>
|
||||
i === index ? { ...m, key: value } : m,
|
||||
),
|
||||
|
|
@ -451,18 +451,18 @@ const ToolsTab = ({
|
|||
className="h-8 flex-1"
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`meta-value-${entry.id}`}
|
||||
htmlFor={`metadata-value-${entry.id}`}
|
||||
className="text-xs shrink-0"
|
||||
>
|
||||
Value
|
||||
</Label>
|
||||
<Input
|
||||
id={`meta-value-${entry.id}`}
|
||||
id={`metadata-value-${entry.id}`}
|
||||
value={entry.value}
|
||||
placeholder="e.g. 12345"
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setMetaEntries((prev) =>
|
||||
setMetadataEntries((prev) =>
|
||||
prev.map((m, i) =>
|
||||
i === index ? { ...m, value } : m,
|
||||
),
|
||||
|
|
@ -475,7 +475,7 @@ const ToolsTab = ({
|
|||
variant="ghost"
|
||||
className="h-8 w-8 p-0 ml-auto shrink-0"
|
||||
onClick={() =>
|
||||
setMetaEntries((prev) =>
|
||||
setMetadataEntries((prev) =>
|
||||
prev.filter((_, i) => i !== index),
|
||||
)
|
||||
}
|
||||
|
|
@ -533,10 +533,12 @@ const ToolsTab = ({
|
|||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => setIsMetaExpanded(!isMetaExpanded)}
|
||||
onClick={() =>
|
||||
setIsMetadataExpanded(!isMetadataExpanded)
|
||||
}
|
||||
className="h-6 px-2"
|
||||
>
|
||||
{isMetaExpanded ? (
|
||||
{isMetadataExpanded ? (
|
||||
<>
|
||||
<ChevronUp className="h-3 w-3 mr-1" />
|
||||
Collapse
|
||||
|
|
@ -551,7 +553,9 @@ const ToolsTab = ({
|
|||
</div>
|
||||
<div
|
||||
className={`transition-all ${
|
||||
isMetaExpanded ? "" : "max-h-[8rem] overflow-y-auto"
|
||||
isMetadataExpanded
|
||||
? ""
|
||||
: "max-h-[8rem] overflow-y-auto"
|
||||
}`}
|
||||
>
|
||||
<JsonView data={selectedTool._meta} />
|
||||
|
|
@ -565,17 +569,16 @@ const ToolsTab = ({
|
|||
|
||||
try {
|
||||
setIsToolRunning(true);
|
||||
const meta = metaEntries.reduce<Record<string, unknown>>(
|
||||
(acc, { key, value }) => {
|
||||
if (key.trim() !== "") acc[key] = value;
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
);
|
||||
const metadata = metadataEntries.reduce<
|
||||
Record<string, unknown>
|
||||
>((acc, { key, value }) => {
|
||||
if (key.trim() !== "") acc[key] = value;
|
||||
return acc;
|
||||
}, {});
|
||||
await callTool(
|
||||
selectedTool.name,
|
||||
params,
|
||||
Object.keys(meta).length ? meta : undefined,
|
||||
Object.keys(metadata).length ? metadata : undefined,
|
||||
);
|
||||
} finally {
|
||||
setIsToolRunning(false);
|
||||
|
|
|
|||
|
|
@ -716,10 +716,10 @@ describe("ToolsTab", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("Meta Display", () => {
|
||||
const toolWithMeta = {
|
||||
describe("Metadata Display", () => {
|
||||
const toolWithMetadata = {
|
||||
name: "metaTool",
|
||||
description: "Tool with meta",
|
||||
description: "Tool with metadata",
|
||||
inputSchema: {
|
||||
type: "object" as const,
|
||||
properties: {
|
||||
|
|
@ -732,10 +732,10 @@ describe("ToolsTab", () => {
|
|||
},
|
||||
} as unknown as Tool;
|
||||
|
||||
it("should display meta section when tool has _meta", () => {
|
||||
it("should display metadata section when tool has _meta", () => {
|
||||
renderToolsTab({
|
||||
tools: [toolWithMeta],
|
||||
selectedTool: toolWithMeta,
|
||||
tools: [toolWithMetadata],
|
||||
selectedTool: toolWithMetadata,
|
||||
});
|
||||
|
||||
expect(screen.getByText("Meta:")).toBeInTheDocument();
|
||||
|
|
@ -744,10 +744,10 @@ describe("ToolsTab", () => {
|
|||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should toggle meta schema expansion", () => {
|
||||
it("should toggle metadata schema expansion", () => {
|
||||
renderToolsTab({
|
||||
tools: [toolWithMeta],
|
||||
selectedTool: toolWithMeta,
|
||||
tools: [toolWithMetadata],
|
||||
selectedTool: toolWithMetadata,
|
||||
});
|
||||
|
||||
// There might be multiple Expand buttons (Output Schema, Meta). We need the one within Meta section
|
||||
|
|
@ -777,13 +777,13 @@ describe("ToolsTab", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("Meta submission", () => {
|
||||
it("should send meta values when provided", async () => {
|
||||
describe("Metadata submission", () => {
|
||||
it("should send metadata values when provided", async () => {
|
||||
const callToolMock = jest.fn(async () => {});
|
||||
|
||||
renderToolsTab({ selectedTool: mockTools[0], callTool: callToolMock });
|
||||
|
||||
// Add a meta key/value pair
|
||||
// Add a metadata key/value pair
|
||||
const addPairButton = screen.getByRole("button", { name: /add pair/i });
|
||||
await act(async () => {
|
||||
fireEvent.click(addPairButton);
|
||||
|
|
@ -815,19 +815,19 @@ describe("ToolsTab", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("ToolResults Meta", () => {
|
||||
it("should display meta information when present in toolResult", () => {
|
||||
const resultWithMeta = {
|
||||
describe("ToolResults Metadata", () => {
|
||||
it("should display metadata information when present in toolResult", () => {
|
||||
const resultWithMetadata = {
|
||||
content: [],
|
||||
_meta: { info: "details", version: 2 },
|
||||
};
|
||||
|
||||
renderToolsTab({
|
||||
selectedTool: mockTools[0],
|
||||
toolResult: resultWithMeta,
|
||||
toolResult: resultWithMetadata,
|
||||
});
|
||||
|
||||
// Only ToolResults meta should be present since selectedTool has no _meta
|
||||
// Only ToolResults metadata 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();
|
||||
|
|
|
|||
|
|
@ -167,9 +167,9 @@ export function useConnection({
|
|||
|
||||
// Add metadata to the request if available, but skip for tool calls
|
||||
// as they handle metadata merging separately
|
||||
const shouldAddGeneralMeta =
|
||||
const shouldAddGeneralMetadata =
|
||||
request.method !== "tools/call" && Object.keys(metadata).length > 0;
|
||||
const requestWithMeta = shouldAddGeneralMeta
|
||||
const requestWithMetadata = shouldAddGeneralMetadata
|
||||
? {
|
||||
...request,
|
||||
params: {
|
||||
|
|
@ -208,16 +208,16 @@ export function useConnection({
|
|||
let response;
|
||||
try {
|
||||
response = await mcpClient.request(
|
||||
requestWithMeta,
|
||||
requestWithMetadata,
|
||||
schema,
|
||||
mcpRequestOptions,
|
||||
);
|
||||
|
||||
pushHistory(requestWithMeta, response);
|
||||
pushHistory(requestWithMetadata, response);
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : String(error);
|
||||
pushHistory(requestWithMeta, { error: errorMessage });
|
||||
pushHistory(requestWithMetadata, { error: errorMessage });
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue