Skip to content

Commit de474e5

Browse files
committed
feat: Add context argument to completion handlers
This commit adds a `context` argument to the completion handlers in `PromptsTab`, `ResourcesTab`, `useCompletionState`, and `useConnection`. The context argument allows passing additional information to the completion engine, which can be used to improve the quality of the completions. The context is passed as a dictionary of key-value pairs. The `ResourcesTab` component was also updated to pass `templateValues` as the `context` to the completion handler. The `useConnection` hook was updated to include the context in the completion request sent to the server.
1 parent 56ef795 commit de474e5

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

client/src/components/PromptsTab.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const PromptsTab = ({
4848
ref: PromptReference | ResourceReference,
4949
argName: string,
5050
value: string,
51+
context?: Record<string, string>,
5152
) => Promise<string[]>;
5253
completionsSupported: boolean;
5354
promptContent: string;

client/src/components/ResourcesTab.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const ResourcesTab = ({
5252
ref: ResourceReference | PromptReference,
5353
argName: string,
5454
value: string,
55+
context?: Record<string, string>,
5556
) => Promise<string[]>;
5657
completionsSupported: boolean;
5758
resourceContent: string;
@@ -94,6 +95,7 @@ const ResourcesTab = ({
9495
},
9596
key,
9697
value,
98+
templateValues,
9799
);
98100
}
99101
};

client/src/lib/hooks/useCompletionState.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function useCompletionState(
2828
ref: ResourceReference | PromptReference,
2929
argName: string,
3030
value: string,
31+
context?: Record<string, string>,
3132
signal?: AbortSignal,
3233
) => Promise<string[]>,
3334
completionsSupported: boolean = true,
@@ -66,6 +67,7 @@ export function useCompletionState(
6667
ref: ResourceReference | PromptReference,
6768
argName: string,
6869
value: string,
70+
context?: Record<string, string>,
6971
) => {
7072
if (!completionsSupported) {
7173
return;
@@ -82,10 +84,13 @@ export function useCompletionState(
8284
}));
8385

8486
try {
87+
console.log(state);
88+
8589
const values = await handleCompletion(
8690
ref,
8791
argName,
8892
value,
93+
context,
8994
abortController.signal,
9095
);
9196

@@ -97,6 +102,7 @@ export function useCompletionState(
97102
}));
98103
}
99104
} catch {
105+
console.error("completion failed");
100106
if (!abortController.signal.aborted) {
101107
setState((prev) => ({
102108
...prev,

client/src/lib/hooks/useConnection.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export function useConnection({
170170
ref: ResourceReference | PromptReference,
171171
argName: string,
172172
value: string,
173+
context?: Record<string, string>,
173174
signal?: AbortSignal,
174175
): Promise<string[]> => {
175176
if (!mcpClient || !completionsSupported) {
@@ -187,6 +188,12 @@ export function useConnection({
187188
},
188189
};
189190

191+
if (context) {
192+
request["params"]["context"] = {
193+
arguments: context,
194+
};
195+
}
196+
190197
try {
191198
const response = await makeRequest(request, CompleteResultSchema, {
192199
signal,

0 commit comments

Comments
 (0)