Skip to content

Commit 03129d2

Browse files
authored
Merge pull request modelcontextprotocol#598 from connor4312/connor4312/597
fix: include previously-resolved variables in completions request
2 parents a52e9d7 + 1f60cf5 commit 03129d2

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

docs/specification/draft/server/utilities/completion.mdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,49 @@ what is being completed through a reference type:
7676
}
7777
```
7878

79+
For prompts or URI templates with multiple arguments, clients should resolve them in the order they are presented by the server, and include each previous completion in the `context.arguments` object to provide context for subsequent requests.
80+
81+
**Request:**
82+
83+
```json
84+
{
85+
"jsonrpc": "2.0",
86+
"id": 1,
87+
"method": "completion/complete",
88+
"params": {
89+
"ref": {
90+
"type": "ref/prompt",
91+
"name": "code_review"
92+
},
93+
"argument": {
94+
"name": "framework",
95+
"value": "fla"
96+
},
97+
"context": {
98+
"arguments": {
99+
"language": "python"
100+
}
101+
}
102+
}
103+
}
104+
```
105+
106+
**Response:**
107+
108+
```json
109+
{
110+
"jsonrpc": "2.0",
111+
"id": 1,
112+
"result": {
113+
"completion": {
114+
"values": ["flask"],
115+
"total": 1,
116+
"hasMore": false
117+
}
118+
}
119+
}
120+
```
121+
79122
### Reference Types
80123

81124
The protocol supports two types of completion references:
@@ -117,6 +160,8 @@ sequenceDiagram
117160
- `argument`: Object containing:
118161
- `name`: Argument name
119162
- `value`: Current value
163+
- `context`: Object containing:
164+
- `arguments`: A mapping of already-resolved argument names to their values.
120165

121166
### CompleteResult
122167

schema/draft/schema.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/draft/schema.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ export interface CallToolResult extends Result {
705705
* Whether the tool call ended in an error.
706706
*
707707
* If not set, this is assumed to be false (the call was successful).
708-
*
708+
*
709709
* Any errors that originate from the tool SHOULD be reported inside the result
710710
* object, with `isError` set to true, _not_ as an MCP protocol-level error
711711
* response. Otherwise, the LLM would not be able to see that an error occurred
@@ -816,7 +816,7 @@ export interface Tool {
816816
};
817817

818818
/**
819-
* An optional JSON Schema object defining the structure of the tool's output returned in
819+
* An optional JSON Schema object defining the structure of the tool's output returned in
820820
* the structuredContent field of a CallToolResult.
821821
*/
822822
outputSchema?: {
@@ -1131,6 +1131,16 @@ export interface CompleteRequest extends Request {
11311131
*/
11321132
value: string;
11331133
};
1134+
1135+
/**
1136+
* Additional, optional context for completions
1137+
*/
1138+
context?: {
1139+
/**
1140+
* Previously-resolved variables in a URI template or prompt.
1141+
*/
1142+
arguments?: { [key: string]: string };
1143+
};
11341144
};
11351145
}
11361146

@@ -1258,7 +1268,7 @@ export interface ElicitRequest extends Request {
12581268
* Restricted schema definitions that only allow primitive types
12591269
* without nested objects or arrays.
12601270
*/
1261-
export type PrimitiveSchemaDefinition =
1271+
export type PrimitiveSchemaDefinition =
12621272
| StringSchema
12631273
| NumberSchema
12641274
| BooleanSchema
@@ -1307,7 +1317,7 @@ export interface ElicitResult extends Result {
13071317
* - "cancel": User dismissed without making an explicit choice
13081318
*/
13091319
action: "accept" | "decline" | "cancel";
1310-
1320+
13111321
/**
13121322
* The submitted form data, only present when action is "accept".
13131323
* Contains values matching the requested schema.

0 commit comments

Comments
 (0)