|
| 1 | +--- |
| 2 | +title: Argument Completion |
| 3 | +--- |
| 4 | +Argument Completion enables servers to provide argument completion for prompt and resource URI arguments. Clients can request completion options for specific arguments, and servers can return ranked suggestions. This allows clients to build rich user interfaces with intelligent argument completion for argument values. |
| 5 | + |
| 6 | +> **_NOTE:_** Argument Completion in MCP is similar to traditional IDE argument completion - it provides contextual suggestions based on available options, rather than AI-powered completion. The server maintains a fixed set of valid values for each argument and returns matching suggestions based on partial input. |
| 7 | +
|
| 8 | +## Capabilities |
| 9 | + |
| 10 | +Support for argument completion is not indicated by a dedicated capability - servers that expose prompts or resources with arguments implicitly support argument completion for those arguments. Clients may attempt argument completion requests for any prompt or resource argument. |
| 11 | + |
| 12 | +## Concepts |
| 13 | + |
| 14 | +### Completion References |
| 15 | + |
| 16 | +When requesting completions, clients must specify what is being completed using a reference type: |
| 17 | + |
| 18 | +- `ref/prompt`: References a prompt by name |
| 19 | +- `ref/resource`: References a resource by URI |
| 20 | + |
| 21 | +The reference identifies the context for completion suggestions. |
| 22 | + |
| 23 | +### Completion Results |
| 24 | + |
| 25 | +Servers return an array of completion values ranked by relevance, with a maximum of 100 items per response. If more results are available beyond the first 100, servers MUST set `hasMore: true` in the response to indicate that additional results can be retrieved with subsequent requests. The optional `total` field allows servers to specify the complete number of matches available, even if not all are returned in a single response. |
| 26 | + |
| 27 | +> **_NOTE:_** MCP does not currently support pagination of completion results - clients that need more than the first 100 matches must issue new completion requests with more specific argument values to narrow down the results. |
| 28 | +
|
| 29 | +## Use Cases |
| 30 | + |
| 31 | +Common use cases for argument completion include: |
| 32 | + |
| 33 | +### Prompt Argument Completion |
| 34 | + |
| 35 | +A client requesting completion options for a prompt argument: |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "ref": { |
| 40 | + "type": "ref/prompt", |
| 41 | + "name": "code_review" |
| 42 | + }, |
| 43 | + "argument": { |
| 44 | + "name": "language", |
| 45 | + "value": "py" |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +The server might respond with language suggestions: |
| 51 | + |
| 52 | +```json |
| 53 | +{ |
| 54 | + "completion": { |
| 55 | + "values": ["python", "pytorch", "pyside", "pyyaml"], |
| 56 | + "total": 10, |
| 57 | + "hasMore": true |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### Resource URI Completion |
| 63 | + |
| 64 | +A client completing a path in a resource URI template: |
| 65 | + |
| 66 | +```json |
| 67 | +{ |
| 68 | + "ref": { |
| 69 | + "type": "ref/resource", |
| 70 | + "uri": "file://{path}" |
| 71 | + }, |
| 72 | + "argument": { |
| 73 | + "name": "path", |
| 74 | + "value": "/home/user/doc" |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +The server could respond with matching paths: |
| 80 | + |
| 81 | +```json |
| 82 | +{ |
| 83 | + "completion": { |
| 84 | + "values": [ |
| 85 | + "/home/user/documents", |
| 86 | + "/home/user/docker", |
| 87 | + "/home/user/downloads" |
| 88 | + ], |
| 89 | + "hasMore": false |
| 90 | + } |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +## Diagram |
| 95 | + |
| 96 | +The following diagram visualizes a typical argument completion interaction between client and server: |
| 97 | + |
| 98 | +```mermaid |
| 99 | +sequenceDiagram |
| 100 | + participant Client |
| 101 | + participant Server |
| 102 | +
|
| 103 | + Note over Client,Server: Client requests completion options |
| 104 | + Client->>Server: completion/complete |
| 105 | + Server-->>Client: CompleteResult |
| 106 | +
|
| 107 | + Note over Client,Server: Client may request more specific results |
| 108 | + opt New completions requested |
| 109 | + Client->>Server: completion/complete |
| 110 | + Server-->>Client: CompleteResult |
| 111 | + end |
| 112 | +``` |
| 113 | + |
| 114 | +## Messages |
| 115 | + |
| 116 | +This section defines the protocol messages for argument completion in the Model Context Protocol (MCP). |
| 117 | + |
| 118 | +### Requesting Completions |
| 119 | + |
| 120 | +#### Request |
| 121 | + |
| 122 | +To get completion suggestions, the client MUST send a `completion/complete` request. |
| 123 | + |
| 124 | +Method: `completion/complete` |
| 125 | +Params: |
| 126 | + - `ref`: A `PromptReference` or `ResourceReference` indicating what is being completed |
| 127 | + - `argument`: Object containing: |
| 128 | + - `name`: The name of the argument being completed |
| 129 | + - `value`: The current value to get completions for |
| 130 | + |
| 131 | +Example: |
| 132 | +```json |
| 133 | +{ |
| 134 | + "jsonrpc": "2.0", |
| 135 | + "id": 1, |
| 136 | + "method": "completion/complete", |
| 137 | + "params": { |
| 138 | + "ref": { |
| 139 | + "type": "ref/prompt", |
| 140 | + "name": "code_review" |
| 141 | + }, |
| 142 | + "argument": { |
| 143 | + "name": "language", |
| 144 | + "value": "py" |
| 145 | + } |
| 146 | + } |
| 147 | +} |
| 148 | +``` |
| 149 | + |
| 150 | +#### Response |
| 151 | + |
| 152 | +The server MUST respond with a `CompleteResult` containing: |
| 153 | + |
| 154 | +- `completion`: Object containing: |
| 155 | + - `values`: Array of completion suggestions (maximum 100) |
| 156 | + - `total`: Optional total number of matches available |
| 157 | + - `hasMore`: Optional boolean indicating if additional results exist |
| 158 | + |
| 159 | +Example: |
| 160 | +```json |
| 161 | +{ |
| 162 | + "jsonrpc": "2.0", |
| 163 | + "id": 1, |
| 164 | + "result": { |
| 165 | + "completion": { |
| 166 | + "values": ["python", "pytorch", "pyside"], |
| 167 | + "total": 10, |
| 168 | + "hasMore": true |
| 169 | + } |
| 170 | + } |
| 171 | +} |
| 172 | +``` |
| 173 | + |
| 174 | +## Error Handling |
| 175 | + |
| 176 | +Servers MUST return appropriate errors if: |
| 177 | +- The referenced prompt or resource does not exist |
| 178 | +- The argument name is invalid |
| 179 | +- Completion cannot be provided for other reasons |
| 180 | + |
| 181 | +Clients SHOULD be prepared to handle cases where completion is temporarily unavailable or returns errors. |
| 182 | + |
| 183 | +## Security Considerations |
| 184 | + |
| 185 | +Implementations MUST carefully consider: |
| 186 | +- Rate limiting completion requests to prevent abuse |
| 187 | +- Access control for sensitive completion suggestions |
| 188 | +- Validation of completion inputs to prevent injection attacks |
0 commit comments