SEP-2293 Add Support for Completions Metadata#2293
SEP-2293 Add Support for Completions Metadata#2293evalstate wants to merge 8 commits intomodelcontextprotocol:mainfrom
Conversation
Co-authored-by: Kent C. Dodds <me@kentcdodds.com>
|
Nice @evalstate, GitHub really wants this for issue, PR and commit completions for example, where the title or commit message could be displayed to provide helpful context, where it's basically useless without additional text. |
- Regenerate index.mdx and docs.json with SEP-2293 Draft - Remove orphaned 2148/2149 .mdx files (upstream removed these SEPs)
Maintainer Activity CheckHi @evalstate! You're assigned to this SEP but there hasn't been any activity from you in 18 days. Please provide an update on:
If you're no longer able to sponsor this SEP, please let us know so we can find another maintainer. This is an automated message from the SEP lifecycle bot. |
|
@evalstate can you please resolve the conflicts and re-run the SEP generator? |
| This change is fully backward compatible: | ||
|
|
||
| - **Existing servers** returning `string[]` require zero changes. | ||
| - **Existing clients** that expect `string[]` will encounter object items only if a new-style server is deployed. Such clients SHOULD handle unknown item shapes gracefully (e.g., by extracting a `value` property if present or skipping unrecognised items). |
There was a problem hiding this comment.
How can an existing client extract the value property? It doesn't know about the value property.
I think to be backwards compatible, new servers need to return string if the client is not on the new version of the spec.
| Recommended migration path: | ||
|
|
||
| 1. Clients update to handle `string | CompletionValue` (additive, no breaking change). | ||
| 2. Servers optionally migrate completions to rich objects where they add value. |
There was a problem hiding this comment.
We cannot reasonably expect all clients to update before servers start rolling this out. I think the migration path should be that SDKs automatically extract the value and return that instead when talking to old clients.
There was a problem hiding this comment.
and we'd need version bump
There was a problem hiding this comment.
Commenting from the Go SDK side: I agree this is not an "additive, optional enrichment" as we're replacing a string in the schema with a union type. Go doesn't have union types, so this essentially means we need to replace string with a struct, which is a backwards incompatible SDK API change.
We would likely need to follow a similar path as we did with adding tools to sampling:
- create a new variant of
CompleteResultthat has the changes applied, - add additional method for calling completion API on the client side that would use the new result type as a return type (e.g.
CompleteWithMetadatain addition to existingComplete), - modify the existing
Completeto strip the additional metadata ifCompletionValues were returned from the server, - add additional handler type for completions on the server side (e.g.
CompletionWithMetadataHandlerin addition to existingCompletionHandler) that would use the new result type, - use the new handler for completion requests if provided and the most recent spec version was negotiated with the client, otherwise use the old handler.
Hope this helps!
|
|
||
| Clients that receive `CompletionValue` objects: | ||
|
|
||
| 1. **MUST** use the `value` field (not `title`) when constructing subsequent `completion/complete` requests (i.e., in `context.arguments` or as the argument value). |
There was a problem hiding this comment.
I'm confused. I don't use completions much, so apologies if I'm missing something, but Isn't the idea of completions that the user types things and it shows a list of options prefixed by what you type? If the value is an ID (e.g. 1234) but the title is a user-readable string (e.g. Python), I assume the user is typing Pyt... not 123..., so the partial completion is the title, not the value? What value do you send if the user has typed Pyt...?
There was a problem hiding this comment.
I think this is a real challenge, given the completion not search, it is meant to be the value, I think @evalstate is spiritually correct and the title would show to ensure the user is getting the expected completion result, but they'd have to type the actual value.
Places GitHub might use this:
- pull request number show titles
- commit sha show commit title
- issue number show title
- project ID show title
But you complete the value, the server gets the partial value to be completed and returns new completions as you type more chars, if you allow for typing the title it would mean:
- you'd have to rely on an initial completion request from blank string definitely returning results
- the client/user having to find the full value in the potentially partial initial completion result.
So yeah, I think this wording is correct as is.
There was a problem hiding this comment.
In the motivation and context section it says:
With this setup, the user would naturally type the title rather than the ID and the server could filter based on the title (or any other field) instead of just the ID.
This seems to contradict what is being proposed?
There was a problem hiding this comment.
or is the idea that the server will filter on both and return the union? So I can type either 12 or Py to get Python?
This supercedes #589 authored by @kentcdodds to bring it to the new SEP format. The text below is broadly the same.
This adds (non-breaking) support for
titleanddescriptionin the completions server response which clients can use to display something different for a value than the value itself.: #1440
Motivation and Context
@connor4312 demonstrates the need for this in a real world setting today:
The user experience could be much better if they could provide display values.
Here's another example from a Journaling server I run (screenshot from MCP Inspector):
This is the best they can do. Users have to just know what ID they want. Would be better if I could display the journal entry title and the date in parentheses.
With this setup, the user would naturally type the title rather than the ID and the server could filter based on the title (or any other field) instead of just the ID.
How Has This Been Tested?
No, but it's a common pattern in many libraries with UX experiences like this.
Breaking Changes
I'm not a huge fan of having two ways to do this, but for simple use cases, it's much better to just use an array of strings so there's a good argument to support both an array of
value/displayValueobjects as well as an array of strings. If we do go this direction, then there is no breaking change here.Types of changes
Checklist
Additional context
Closes #585