Skip to content

Commit 412b93f

Browse files
agu-znerzhulart
authored andcommitted
Protocol extensibility (agentclientprotocol#79)
* Add _meta to all types * Ext methods and notifications * Add extMethod and extNotification to typescript lib * Fix decoders and add tests * Extensibility docs * Reference docs from doc comments * Use _ prefix for custom methods
1 parent b5846fe commit 412b93f

22 files changed

Lines changed: 2080 additions & 56 deletions

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"protocol/file-system",
5959
"protocol/terminals",
6060
"protocol/agent-plan",
61+
"protocol/extensibility",
6162
"protocol/schema"
6263
]
6364
},

docs/protocol/extensibility.mdx

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: "Extensibility"
3+
description: "Adding custom data and capabilities"
4+
---
5+
6+
The Agent Client Protocol provides built-in extension mechanisms that allow implementations to add custom functionality while maintaining compatibility with the core protocol. These mechanisms ensure that Agents and Clients can innovate without breaking interoperability.
7+
8+
## The `_meta` Field
9+
10+
All types in the protocol include a `_meta` field that implementations can use to attach custom information. This includes requests, responses, notifications, and even nested types like content blocks, tool calls, plan entries, and capability objects.
11+
12+
```json
13+
{
14+
"jsonrpc": "2.0",
15+
"id": 1,
16+
"method": "session/prompt",
17+
"params": {
18+
"sessionId": "sess_abc123def456",
19+
"prompt": [
20+
{
21+
"type": "text",
22+
"text": "Hello, world!"
23+
}
24+
],
25+
"_meta": {
26+
"zed.dev/debugMode": true
27+
}
28+
}
29+
}
30+
```
31+
32+
Implementations **MUST NOT** add any custom fields at the root of a type that's part of the specification. All possible names are reserved for future protocol versions.
33+
34+
## Extension Methods
35+
36+
The protocol reserves any method name starting with an underscore (`_`) for custom extensions. This allows implementations to add new functionality without the risk of conflicting with future protocol versions.
37+
38+
Extension methods follow standard [JSON-RPC 2.0](https://www.jsonrpc.org/specification) semantics:
39+
40+
- **[Requests](https://www.jsonrpc.org/specification#request_object)** - Include an `id` field and expect a response
41+
- **[Notifications](https://www.jsonrpc.org/specification#notification)** - Omit the `id` field and are one-way (fire-and-forget)
42+
43+
### Custom Requests
44+
45+
In addition to the requests specified by the protocol, implementations **MAY** expose and call custom JSON-RPC requests as long as their name starts with an underscore (`_`).
46+
47+
```json
48+
{
49+
"jsonrpc": "2.0",
50+
"id": 1,
51+
"method": "_zed.dev/workspace/buffers",
52+
"params": {
53+
"language": "rust"
54+
}
55+
}
56+
```
57+
58+
Upon receiveing a custom request, implementations **MUST** respond accordingly with the provided `id`:
59+
60+
```json
61+
{
62+
"jsonrpc": "2.0",
63+
"id": 1,
64+
"result": {
65+
"buffers": [
66+
{ "id": 0, "path": "/home/user/project/src/main.rs" },
67+
{ "id": 1, "path": "/home/user/project/src/editor.rs" }
68+
]
69+
}
70+
}
71+
```
72+
73+
If the receiveing end doesn't recognize the custom method name, it should respond with the standard "Method not found" error:
74+
75+
```json
76+
{
77+
"jsonrpc": "2.0",
78+
"id": 1,
79+
"error": {
80+
"code": -32601,
81+
"message": "Method not found"
82+
}
83+
}
84+
```
85+
86+
To avoid such cases, extensions **SHOULD** advertise their [custom capabilities](#advertising-custom-capabilities) so that callers can check their availability first and adapt their interface accordingly.
87+
88+
### Custom Notifications
89+
90+
Custom notifications are regular JSON-RPC notifications that start with an underscore (`_`). Like all notifications, they omit the `id` field:
91+
92+
```json
93+
{
94+
"jsonrpc": "2.0",
95+
"method": "_zed.dev/file_opened",
96+
"params": {
97+
"path": "/home/user/project/src/editor.rs"
98+
}
99+
}
100+
```
101+
102+
Unlike with custom requests, implementations **SHOULD** ignore unrecognized notifications.
103+
104+
## Advertising Custom Capabilities
105+
106+
Implementations **SHOULD** use the `_meta` field in capability objects to advertise support for extensions and their methods:
107+
108+
```json
109+
{
110+
"jsonrpc": "2.0",
111+
"id": 0,
112+
"result": {
113+
"protocolVersion": 1,
114+
"agentCapabilities": {
115+
"loadSession": true,
116+
"_meta": {
117+
"zed.dev": {
118+
"workspace": true,
119+
"fileNotifications": true
120+
}
121+
}
122+
}
123+
}
124+
}
125+
```
126+
127+
This allows implementations to negotiate custom features during initialization without breaking compatibility with standard Clients and Agents.

docs/protocol/initialization.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ Capabilities are high-level and are not attached to a specific base protocol con
9999

100100
Capabilities may specify the availability of protocol methods, notifications, or a subset of their parameters. They may also signal behaviors of the Agent or Client implementation.
101101

102+
Implementations can also [advertise custom capabilities](./extensibility#advertising-custom-capabilities) using the `_meta` field to indicate support for protocol extensions.
103+
102104
### Client Capabilities
103105

104106
The Client **SHOULD** specify whether it supports the following capabilities:

docs/protocol/overview.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,19 @@ All methods follow standard JSON-RPC 2.0 [error handling](https://www.jsonrpc.or
149149
- Errors include an `error` object with `code` and `message`
150150
- Notifications never receive responses (success or error)
151151

152+
## Extensibility
153+
154+
The protocol provides built-in mechanisms for adding custom functionality while maintaining compatibility:
155+
156+
- Add custom data using `_meta` fields
157+
- Create custom methods with `_method` and `_notification`
158+
- Advertise custom capabilities during initialization
159+
160+
Learn about [protocol extensibility](./extensibility) to understand how to use these mechanisms.
161+
152162
## Next Steps
153163

154164
- Learn about [Initialization](./initialization) to understand version and capability negotiation
155165
- Understand [Session Setup](./session-setup) for creating and loading sessions
156166
- Review the [Prompt Turn](./prompt-turn) lifecycle
167+
- Explore [Extensibility](./extensibility) to add custom features

0 commit comments

Comments
 (0)