- Adding proprietary features to your agent or client
- Implementing experimental capabilities
- Integrating with custom systems
Overview
Both sides of the connection support extension methods:- Agent side: Implement
extMethodandextNotificationin yourAgentimplementation - Client side: Implement
extMethodandextNotificationin yourClientimplementation
Extension methods and notifications work just like standard protocol methods, using the same JSON-RPC 2.0 message format.
Agent Extension Methods
Agents can handle custom requests from clients by implementing the optionalextMethod and extNotification methods:
Receiving Extension Methods
Sending Extension Methods (Agent to Client)
Agents can call custom methods on the client usingAgentSideConnection:
Client Extension Methods
Clients can handle custom requests from agents similarly:Receiving Extension Methods
Sending Extension Methods (Client to Agent)
Naming Conventions
Use Reverse Domain Names
Prefix your extension methods with a reverse domain name:Use Descriptive Names
Method names should clearly indicate their purpose:Type Safety with Extensions
For better type safety, define interfaces for your extension methods:Complete Example
Here’s a complete example showing bidirectional extension methods:Best Practices
- Always use namespaced method names to avoid conflicts
- Document your extensions clearly for users of your implementation
- Handle unknown methods gracefully by throwing
RequestError.methodNotFound - Version your extension methods if you expect them to change
- Consider backward compatibility when modifying extension method behavior
Related
- Error Handling - Throwing errors in extension methods
- Connection Lifecycle - Understanding connection state