Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.1",
"class-variance-authority": "^0.7.0",
Expand Down
7 changes: 5 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const App = () => {
<Bell className="w-4 h-4 mr-2" />
Notifications
</TabsTrigger>
<TabsTrigger value="tools" disabled>
<TabsTrigger value="tools">
<Hammer className="w-4 h-4 mr-2" />
Tools
</TabsTrigger>
Expand Down Expand Up @@ -243,7 +243,10 @@ const App = () => {
listTools={listTools}
callTool={callTool}
selectedTool={selectedTool}
setSelectedTool={setSelectedTool}
setSelectedTool={(tool) => {
setSelectedTool(tool);
setToolResult("");
}}
toolResult={toolResult}
error={error}
/>
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/PromptsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TabsContent } from "@/components/ui/tabs";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { useState } from "react";
import { Label } from "@/components/ui/label";

export type Prompt = {
name: string;
Expand Down Expand Up @@ -98,7 +99,9 @@ const PromptsTab = ({
)}
{selectedPrompt.arguments?.map((arg) => (
<div key={arg.name}>
<Label htmlFor={arg.name}>{arg.name}</Label>
<Input
id={arg.name}
placeholder={`Enter ${arg.name}`}
value={promptArgs[arg.name] || ""}
onChange={(e) =>
Expand Down
62 changes: 48 additions & 14 deletions client/src/components/ToolsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { TabsContent } from "@/components/ui/tabs";
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";
import { Input } from "@/components/ui/input";
import { Send, AlertCircle } from "lucide-react";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { useState } from "react";
import { Label } from "@/components/ui/label";

export type Tool = {
name: string;
description: string;
inputSchema: {
type: string;
properties: Record<string, { type: string; description: string }>;
};
};

const ToolsTab = ({
Expand All @@ -26,7 +32,7 @@ const ToolsTab = ({
toolResult: string;
error: string | null;
}) => {
const [params, setParams] = useState("");
const [params, setParams] = useState<Record<string, unknown>>({});

return (
<TabsContent value="tools" className="grid grid-cols-2 gap-4">
Expand All @@ -46,6 +52,9 @@ const ToolsTab = ({
onClick={() => setSelectedTool(tool)}
>
<span className="flex-1">{tool.name}</span>
<span className="text-sm text-gray-500">
{tool.description}
</span>
</div>
))}
</div>
Expand All @@ -67,22 +76,47 @@ const ToolsTab = ({
</Alert>
) : selectedTool ? (
<div className="space-y-4">
<Textarea
placeholder="Tool parameters (JSON)"
className="h-32 font-mono"
value={params}
onChange={(e) => setParams(e.target.value)}
/>
<Button
onClick={() => callTool(selectedTool.name, JSON.parse(params))}
>
<p className="text-sm text-gray-600">
{selectedTool.description}
</p>
{Object.entries(selectedTool.inputSchema.properties).map(
([key, value]) => (
<div key={key}>
<Label
htmlFor={key}
className="block text-sm font-medium text-gray-700"
>
{key}
</Label>
<Input
type={value.type === "number" ? "number" : "text"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably useful to at least handle booleans as well, by rendering a checkbox. (This could be a follow-up though)

id={key}
name={key}
placeholder={value.description}
onChange={(e) =>
setParams({
...params,
[key]:
value.type === "number"
? Number(e.target.value)
: e.target.value,
})
}
/>
</div>
),
)}
<Button onClick={() => callTool(selectedTool.name, params)}>
<Send className="w-4 h-4 mr-2" />
Run Tool
</Button>
{toolResult && (
<pre className="bg-gray-50 p-4 rounded text-sm overflow-auto max-h-64">
{JSON.stringify(toolResult, null, 2)}
</pre>
<>
<h4 className="font-semibold mb-2">Tool Result:</h4>
<pre className="bg-gray-50 p-4 rounded text-sm overflow-auto max-h-64">
{toolResult}
</pre>
</>
)}
</div>
) : (
Expand Down
24 changes: 24 additions & 0 deletions client/src/components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
)

const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
))
Label.displayName = LabelPrimitive.Root.displayName

export { Label }
7 changes: 7 additions & 0 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@
dependencies:
"@radix-ui/react-use-layout-effect" "1.1.0"

"@radix-ui/react-label@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-label/-/react-label-2.1.0.tgz#3aa2418d70bb242be37c51ff5e51a2adcbc372e3"
integrity sha512-peLblDlFw/ngk3UWq0VnYaOLy6agTZZ+MUO/WhVfm14vJGML+xH4FAl2XQGLqdefjNb7ApRg6Yn7U42ZhmYXdw==
dependencies:
"@radix-ui/react-primitive" "2.0.0"

"@radix-ui/react-presence@1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-presence/-/react-presence-1.1.1.tgz#98aba423dba5e0c687a782c0669dcd99de17f9b1"
Expand Down
2 changes: 1 addition & 1 deletion server/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class McpClient {
return await this.client.request(
{
method: "tools/call",
params: { name, ...params },
params: { name, arguments: params },
},
CallToolResultSchema,
);
Expand Down
7 changes: 3 additions & 4 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ wss.on("connection", (ws: WebSocket) => {
command.name &&
command.params
) {
const result = await mcpClient.callTool(
command.name + "asdf",
command.params,
const result = await mcpClient.callTool(command.name, command.params);
ws.send(
JSON.stringify({ type: "toolResult", data: result.toolResult }),
);
ws.send(JSON.stringify({ type: "toolResult", data: result }));
}
} catch (error) {
console.error("Error:", error);
Expand Down