Skip to content

Commit b025bff

Browse files
authored
Merge pull request modelcontextprotocol#767 from pja-ant/fix766
Fix issue 766 - Completions not populated until you start typing
2 parents b7ef160 + 1778ab7 commit b025bff

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

client/src/components/PromptsTab.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ const PromptsTab = ({
6363
clearCompletions();
6464
}, [clearCompletions, selectedPrompt]);
6565

66-
const handleInputChange = async (argName: string, value: string) => {
67-
setPromptArgs((prev) => ({ ...prev, [argName]: value }));
68-
66+
const triggerCompletions = (argName: string, value: string) => {
6967
if (selectedPrompt) {
7068
requestCompletions(
7169
{
@@ -79,6 +77,16 @@ const PromptsTab = ({
7977
}
8078
};
8179

80+
const handleInputChange = async (argName: string, value: string) => {
81+
setPromptArgs((prev) => ({ ...prev, [argName]: value }));
82+
triggerCompletions(argName, value);
83+
};
84+
85+
const handleFocus = async (argName: string) => {
86+
const currentValue = promptArgs[argName] || "";
87+
triggerCompletions(argName, currentValue);
88+
};
89+
8290
const handleGetPrompt = () => {
8391
if (selectedPrompt) {
8492
getPrompt(selectedPrompt.name, promptArgs);
@@ -143,6 +151,7 @@ const PromptsTab = ({
143151
onInputChange={(value) =>
144152
handleInputChange(arg.name, value)
145153
}
154+
onFocus={() => handleFocus(arg.name)}
146155
options={completions[arg.name] || []}
147156
/>
148157

client/src/components/ui/combobox.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface ComboboxProps {
1919
value: string;
2020
onChange: (value: string) => void;
2121
onInputChange: (value: string) => void;
22+
onFocus?: () => void;
2223
options: string[];
2324
placeholder?: string;
2425
emptyMessage?: string;
@@ -29,13 +30,24 @@ export function Combobox({
2930
value,
3031
onChange,
3132
onInputChange,
33+
onFocus,
3234
options = [],
3335
placeholder = "Select...",
3436
emptyMessage = "No results found.",
3537
id,
3638
}: ComboboxProps) {
3739
const [open, setOpen] = React.useState(false);
3840

41+
const handleOpenChange = React.useCallback(
42+
(newOpen: boolean) => {
43+
setOpen(newOpen);
44+
if (newOpen && onFocus) {
45+
onFocus();
46+
}
47+
},
48+
[onFocus],
49+
);
50+
3951
const handleSelect = React.useCallback(
4052
(option: string) => {
4153
onChange(option);
@@ -52,7 +64,7 @@ export function Combobox({
5264
);
5365

5466
return (
55-
<Popover open={open} onOpenChange={setOpen}>
67+
<Popover open={open} onOpenChange={handleOpenChange}>
5668
<PopoverTrigger asChild>
5769
<Button
5870
variant="outline"

0 commit comments

Comments
 (0)