Merge pull request #10 from modelcontextprotocol/ashwin/promptargs
make prompts pass args
This commit is contained in:
@@ -139,8 +139,8 @@ const App = () => {
|
|||||||
sendWebSocketMessage({ type: "listPrompts" });
|
sendWebSocketMessage({ type: "listPrompts" });
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPrompt = (name: string) => {
|
const getPrompt = (name: string, args: Record<string, unknown> = {}) => {
|
||||||
sendWebSocketMessage({ type: "getPrompt", name });
|
sendWebSocketMessage({ type: "getPrompt", name, args });
|
||||||
};
|
};
|
||||||
|
|
||||||
const listTools = () => {
|
const listTools = () => {
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
import { Send, AlertCircle } from "lucide-react";
|
import { AlertCircle } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||||
import { TabsContent } from "@/components/ui/tabs";
|
import { TabsContent } from "@/components/ui/tabs";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export type Prompt = {
|
export type Prompt = {
|
||||||
id: string;
|
|
||||||
name: string;
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
arguments?: {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
required?: boolean;
|
||||||
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const PromptsTab = ({
|
const PromptsTab = ({
|
||||||
@@ -21,12 +27,24 @@ const PromptsTab = ({
|
|||||||
}: {
|
}: {
|
||||||
prompts: Prompt[];
|
prompts: Prompt[];
|
||||||
listPrompts: () => void;
|
listPrompts: () => void;
|
||||||
getPrompt: (name: string) => void;
|
getPrompt: (name: string, args: Record<string, string>) => void;
|
||||||
selectedPrompt: Prompt | null;
|
selectedPrompt: Prompt | null;
|
||||||
setSelectedPrompt: (prompt: Prompt) => void;
|
setSelectedPrompt: (prompt: Prompt) => void;
|
||||||
promptContent: string;
|
promptContent: string;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
}) => {
|
}) => {
|
||||||
|
const [promptArgs, setPromptArgs] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
|
const handleInputChange = (argName: string, value: string) => {
|
||||||
|
setPromptArgs((prev) => ({ ...prev, [argName]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGetPrompt = () => {
|
||||||
|
if (selectedPrompt) {
|
||||||
|
getPrompt(selectedPrompt.name, promptArgs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabsContent value="prompts" className="grid grid-cols-2 gap-4">
|
<TabsContent value="prompts" className="grid grid-cols-2 gap-4">
|
||||||
<div className="bg-white rounded-lg shadow">
|
<div className="bg-white rounded-lg shadow">
|
||||||
@@ -44,11 +62,11 @@ const PromptsTab = ({
|
|||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{prompts.map((prompt) => (
|
{prompts.map((prompt) => (
|
||||||
<div
|
<div
|
||||||
key={prompt.id}
|
key={prompt.name}
|
||||||
className="flex items-center p-2 rounded hover:bg-gray-50 cursor-pointer"
|
className="flex items-center p-2 rounded hover:bg-gray-50 cursor-pointer"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedPrompt(prompt);
|
setSelectedPrompt(prompt);
|
||||||
getPrompt(prompt.name);
|
setPromptArgs({});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="flex-1">{prompt.name}</span>
|
<span className="flex-1">{prompt.name}</span>
|
||||||
@@ -73,18 +91,40 @@ const PromptsTab = ({
|
|||||||
</Alert>
|
</Alert>
|
||||||
) : selectedPrompt ? (
|
) : selectedPrompt ? (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Textarea
|
{selectedPrompt.description && (
|
||||||
value={promptContent}
|
<p className="text-sm text-gray-600">
|
||||||
readOnly
|
{selectedPrompt.description}
|
||||||
className="h-64 font-mono"
|
</p>
|
||||||
/>
|
)}
|
||||||
<div className="flex space-x-2">
|
{selectedPrompt.arguments?.map((arg) => (
|
||||||
<Input placeholder="Enter your message" />
|
<div key={arg.name}>
|
||||||
<Button>
|
<Input
|
||||||
<Send className="w-4 h-4 mr-2" />
|
placeholder={`Enter ${arg.name}`}
|
||||||
Send
|
value={promptArgs[arg.name] || ""}
|
||||||
</Button>
|
onChange={(e) =>
|
||||||
</div>
|
handleInputChange(arg.name, e.target.value)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{arg.description && (
|
||||||
|
<p className="text-xs text-gray-500 mt-1">
|
||||||
|
{arg.description}
|
||||||
|
{arg.required && (
|
||||||
|
<span className="text-xs mt-1 ml-1">(Required)</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<Button onClick={handleGetPrompt} className="w-full">
|
||||||
|
Get Prompt
|
||||||
|
</Button>
|
||||||
|
{promptContent && (
|
||||||
|
<Textarea
|
||||||
|
value={promptContent}
|
||||||
|
readOnly
|
||||||
|
className="h-64 font-mono"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<Alert>
|
<Alert>
|
||||||
|
|||||||
@@ -80,16 +80,18 @@ export class McpClient {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPrompt(name: string): Promise<GetPromptResult> {
|
async getPrompt(
|
||||||
|
name: string,
|
||||||
|
args?: Record<string, string>,
|
||||||
|
): Promise<GetPromptResult> {
|
||||||
return await this.client.request(
|
return await this.client.request(
|
||||||
{
|
{
|
||||||
method: "prompts/get",
|
method: "prompts/get",
|
||||||
params: { name },
|
params: { name, arguments: args },
|
||||||
},
|
},
|
||||||
GetPromptResultSchema,
|
GetPromptResultSchema,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tool Operations
|
// Tool Operations
|
||||||
async listTools(): Promise<ListToolsResult> {
|
async listTools(): Promise<ListToolsResult> {
|
||||||
return await this.client.request(
|
return await this.client.request(
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ wss.on("connection", (ws: WebSocket) => {
|
|||||||
const prompts = await mcpClient.listPrompts();
|
const prompts = await mcpClient.listPrompts();
|
||||||
ws.send(JSON.stringify({ type: "prompts", data: prompts }));
|
ws.send(JSON.stringify({ type: "prompts", data: prompts }));
|
||||||
} else if (command.type === "getPrompt" && command.name) {
|
} else if (command.type === "getPrompt" && command.name) {
|
||||||
const prompt = await mcpClient.getPrompt(command.name);
|
const prompt = await mcpClient.getPrompt(command.name, command.args);
|
||||||
ws.send(JSON.stringify({ type: "prompt", data: prompt }));
|
ws.send(JSON.stringify({ type: "prompt", data: prompt }));
|
||||||
} else if (command.type === "listTools") {
|
} else if (command.type === "listTools") {
|
||||||
const tools = await mcpClient.listTools();
|
const tools = await mcpClient.listTools();
|
||||||
|
|||||||
Reference in New Issue
Block a user