|
| 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. |
0 commit comments