-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement MCP Completion Support in Prompts and Resources Tabs #113
base: main
Are you sure you want to change the base?
Implement MCP Completion Support in Prompts and Resources Tabs #113
Conversation
…Resources tabs - create useCompletion hook to fetch completions with debouncing and abort control - Updated `PromptsTab.tsx` and `ResourcesTab.tsx` to utilize the `Combobox` component and `useCompletions` hook, enabling argument autocompletion for prompts and resource URIs as per the MCP specification. - Added a combobox to show completions
const handleCompletion = async ( | ||
ref: ResourceReference | PromptReference, | ||
argName: string, | ||
value: string, | ||
signal?: AbortSignal, | ||
) => { | ||
if (!mcpClient) { | ||
throw new Error("MCP client not connected"); | ||
} | ||
|
||
const request: ClientRequest = { | ||
method: "completion/complete", | ||
params: { | ||
argument: { | ||
name: argName, | ||
value, | ||
}, | ||
ref, | ||
}, | ||
}; | ||
|
||
try { | ||
const response = await mcpClient.complete(request.params, { | ||
signal, | ||
}); | ||
pushHistory(request, response); | ||
|
||
return response?.completion.values || []; | ||
} catch (e: unknown) { | ||
const errorMessage = e instanceof Error ? e.message : String(e); | ||
pushHistory(request, { error: errorMessage }); | ||
|
||
toast.error(errorMessage); | ||
throw e; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the makeRequest
function above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing! Will work on this today.
As a side note - I've noticed that the current Spec does not allow servers to indicate whether they support completions, as far as I understand. So if we request completions from a server that does not provide a handler, we get a Method not found error (-32601).
In the short term, I can address this by tracking that specific error and disable further requests for the selected template or prompt.
Long term I feel it would be good to include completions as part of the capability negotiation
e.g.
const server = new Server({
name: 'My server',
version: '1.0.0',
}, {
capabilities: {
resources: { subscribe: true, completions: true },
prompts: { completions: true},
}
})
Let me know your thoughts or if there's anything I might have overlooked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair callout. If you don't mind, could you open a discussion in the specification repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for sure - modelcontextprotocol/specification#122
Provide a brief summary of your changes
This PR introduces support for developers to test and debug completions in their MCP server implementations, enabling dynamic prompt and resource template completion testing directly within the MCP Inspector.
Motivation and Context
Completion support is a critical feature for MCP servers that implement dynamic prompts and resource templates. This addition allows developers to interactively test and debug their server’s completion logic, ensuring a smooth and efficient development process.
How Has This Been Tested?
Tested with a basic MCP server that provides resource templates and prompts for workspace information (e.g., file structure, language, packages, etc.).
Example Completion Logic
This logic was verified using a mocked Inspector setup to ensure correctness across various completion scenarios.
Breaking Changes
This change is backward-compatible. No updates to existing code or configurations are required.
Types of changes
Checklist
Additional Context
handleCompletion
has it's own abort signal hence why it diverged from usingmakeRequest