- Notifications
You must be signed in to change notification settings - Fork949
Description
Describe the feature or problem you’d like to solve
MCP supportscompletions for resources. I have added support for resources in VS Code and noticed that there are no completions yet :)
Proposed solution
Help to provide completions for the template resources we provide.
Kapture.2025-05-21.at.16.21.18.mp4
completion/complete
is wrapped inmcp-go
via:
mcp-go provides:
// CompleteRequest is a request from the client to the server, to ask for completion options.type CompleteRequest struct {RequestParams struct {Ref any `json:"ref"` // Can be PromptReference or ResourceReferenceArgument struct {// The name of the argumentName string `json:"name"`// The value of the argument to use for completion matching.Value string `json:"value"`} `json:"argument"`} `json:"params"`}
// CompleteResult is the server's response to a completion/complete requesttype CompleteResult struct {ResultCompletion struct {// An array of completion values. Must not exceed 100 items.Values []string `json:"values"`// The total number of completion options available. This can exceed the// number of values actually sent in the response.Total int `json:"total,omitempty"`// Indicates whether there are additional completion options beyond those// provided in the current response, even if the exact total is unknown.HasMore bool `json:"hasMore,omitempty"`} `json:"completion"`}
And the interface is:
// Complete requests completion options for a given argumentComplete(ctx context.Context,request mcp.CompleteRequest,) (*mcp.CompleteResult, error)
And the github API client can useclient.Search.Repositories(ctx, "query", &github.SearchOptions{})
with a custom query string.client.Search.Commits(ctx, "query", &github.SearchOptions{})
Query options includeuser:USERNAME
org:ORGNAME
andrepo:USERNAME/REPO
where USERNAME can be ORGNAME.
Other APIs includecommits, resp, err := client.Repositories.ListCommits(ctx, owner, repo, opts)
You can search issues and PRs withresult, resp, err := client.Search.Issues(ctx, query, opts)
branches, resp, err := client.Repositories.ListBranches(ctx, owner, repo, opts)client.Search.Commits(ctx, "query", &github.SearchOptions{})
The types of resources we want to provide completions for are here:
// GetRepositoryResourceContent defines the resource template and handler for getting repository content.func GetRepositoryResourceContent(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {return mcp.NewResourceTemplate("repo://{owner}/{repo}/contents{/path*}", // Resource templatet("RESOURCE_REPOSITORY_CONTENT_DESCRIPTION", "Repository Content"),),RepositoryResourceContentsHandler(getClient)}// GetRepositoryResourceBranchContent defines the resource template and handler for getting repository content for a branch.func GetRepositoryResourceBranchContent(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {return mcp.NewResourceTemplate("repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", // Resource templatet("RESOURCE_REPOSITORY_CONTENT_BRANCH_DESCRIPTION", "Repository Content for specific branch"),),RepositoryResourceContentsHandler(getClient)}// GetRepositoryResourceCommitContent defines the resource template and handler for getting repository content for a commit.func GetRepositoryResourceCommitContent(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {return mcp.NewResourceTemplate("repo://{owner}/{repo}/sha/{sha}/contents{/path*}", // Resource templatet("RESOURCE_REPOSITORY_CONTENT_COMMIT_DESCRIPTION", "Repository Content for specific commit"),),RepositoryResourceContentsHandler(getClient)}// GetRepositoryResourceTagContent defines the resource template and handler for getting repository content for a tag.func GetRepositoryResourceTagContent(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {return mcp.NewResourceTemplate("repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", // Resource templatet("RESOURCE_REPOSITORY_CONTENT_TAG_DESCRIPTION", "Repository Content for specific tag"),),RepositoryResourceContentsHandler(getClient)}// GetRepositoryResourcePrContent defines the resource template and handler for getting repository content for a pull request.func GetRepositoryResourcePrContent(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {return mcp.NewResourceTemplate("repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", // Resource templatet("RESOURCE_REPOSITORY_CONTENT_PR_DESCRIPTION", "Repository Content for specific pull request"),),RepositoryResourceContentsHandler(getClient)}
And the completion response should always be a resource reference.
From the MCP Spec docs:
User Interaction Model
Completion in MCP is designed to support interactive user experiences similar to IDE code completion.
For example, applications may show completion suggestions in a dropdown or popup menu as users type, with the ability to filter and select from available options.
However, implementations are free to expose completion through any interface pattern that suits their needs—the protocol itself does not mandate any specific user interaction model.
Requesting Completions
To get completion suggestions, clients send a completion/complete request specifying what is being completed through a reference type:
Request:
Copy
{
"jsonrpc": "2.0",
"id": 1,
"method": "completion/complete",
"params": {
"ref": {
"type": "ref/prompt",
"name": "code_review"
},
"argument": {
"name": "language",
"value": "py"
}
}
}
Response:
Copy
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"completion": {
"values": ["python", "pytorch", "pyside"],
"total": 10,
"hasMore": true
}
}
}
ref/resourceReferences a resource URI{"type": "ref/resource", "uri": "file:///{path}"}
## The goalWe want to respond to completion requests, by providing resource results a.k.a `ref/resource` also `ResourceReference` in `mcp-go`.## HowAdd a `repository_completions.go` with the appropriate handler for completions requests, and ensure that completions are an enabled feature on the server.You should be able to use the mock and test features in the repo to actually validate the work, by performing completion requests and using known responses to ensure the endpoint works as expected.We can iterate once we know how the UI actually responds.Having working support for this feature is goal number one.## QAWe should be certain that the server responds appropriately to completion requests and proactively provides real resources. We also can provide actual files by listing those (the templates can already do that for repository roots).