|
| 1 | +--- |
| 2 | +name: sacp-v2-migration |
| 3 | +description: Migrate Rust code from sacp v1.x to v2.0 role-based API. Use when upgrading sacp dependencies, fixing JrHandlerChain errors, or when code references MessageAndCx or old connection patterns. |
| 4 | +--- |
| 5 | + |
| 6 | +# SACP v2 Migration |
| 7 | + |
| 8 | +## Instructions |
| 9 | + |
| 10 | +Apply these transformations when migrating from sacp v1.x to v2.0: |
| 11 | + |
| 12 | +### 1. Replace JrHandlerChain with role builder |
| 13 | + |
| 14 | +```rust |
| 15 | +// Before |
| 16 | +JrHandlerChain::new() |
| 17 | + |
| 18 | +// After - choose based on what you're building: |
| 19 | +AgentToClient::builder() // agent serving a client |
| 20 | +ClientToAgent::builder() // client connecting to agent |
| 21 | +UntypedRole::builder() // tests or dynamic scenarios |
| 22 | +``` |
| 23 | + |
| 24 | +### 2. Add connection_cx to all handlers |
| 25 | + |
| 26 | +```rust |
| 27 | +// Before |
| 28 | +.on_receive_request(async move |req: InitializeRequest, request_cx| { |
| 29 | + |
| 30 | +// After |
| 31 | +.on_receive_request(async move |req: InitializeRequest, request_cx, _cx| { |
| 32 | +``` |
| 33 | + |
| 34 | +### 3. Update on_receive_message |
| 35 | + |
| 36 | +```rust |
| 37 | +// Before |
| 38 | +.on_receive_message(async move |message: MessageAndCx<UntypedMessage, UntypedMessage>| { |
| 39 | + message.respond_with_error(error) |
| 40 | +}) |
| 41 | + |
| 42 | +// After |
| 43 | +.on_receive_message(async move |message: MessageCx, cx: JrConnectionCx<AgentToClient>| { |
| 44 | + message.respond_with_error(error, cx) |
| 45 | +}) |
| 46 | +``` |
| 47 | + |
| 48 | +### 4. Parameterize JrConnectionCx |
| 49 | + |
| 50 | +```rust |
| 51 | +// Before |
| 52 | +|cx: sacp::JrConnectionCx| |
| 53 | + |
| 54 | +// After |
| 55 | +|cx: sacp::JrConnectionCx<ClientToAgent>| |
| 56 | +``` |
| 57 | + |
| 58 | +### 5. Use cx directly for notifications |
| 59 | + |
| 60 | +```rust |
| 61 | +// Before |
| 62 | +request_cx.connection_cx().send_notification(notification)?; |
| 63 | + |
| 64 | +// After |
| 65 | +cx.send_notification(notification)?; |
| 66 | +``` |
| 67 | + |
| 68 | +### 6. Replace successor extension methods |
| 69 | + |
| 70 | +The `sacp-proxy` crate is deleted. Replace `_from_successor` and `to_successor` extension methods with endpoint-targeted sends: |
| 71 | + |
| 72 | +```rust |
| 73 | +// Before (sacp-proxy) |
| 74 | +cx.send_request(request.to_successor())?; |
| 75 | +let inner = response.from_successor()?; |
| 76 | + |
| 77 | +// After |
| 78 | +cx.send_request_to(sacp::Agent, request)?; |
| 79 | +``` |
| 80 | + |
| 81 | +### 7. Replace message.connection_cx() calls |
| 82 | + |
| 83 | +`MessageAndCx` no longer has a `connection_cx()` method. Use the `cx` parameter passed to your handler: |
| 84 | + |
| 85 | +```rust |
| 86 | +// Before |
| 87 | +.on_receive_message(async move |message: MessageAndCx<...>| { |
| 88 | + let cx = message.connection_cx(); |
| 89 | + cx.send_notification(notif)?; |
| 90 | +}) |
| 91 | + |
| 92 | +// After |
| 93 | +.on_receive_message(async move |message: MessageCx, cx: JrConnectionCx<AgentToClient>| { |
| 94 | + cx.send_notification(notif)?; |
| 95 | +}) |
| 96 | +``` |
| 97 | + |
| 98 | +### 8. Update Cargo.toml |
| 99 | + |
| 100 | +Remove `sacp-proxy` dependency entirely - it's merged into `sacp`. MCP server types are now in `sacp::mcp_server`. |
| 101 | + |
| 102 | +## Compiler error quick fixes |
| 103 | + |
| 104 | +| Error | Fix | |
| 105 | +|-------|-----| |
| 106 | +| `expected 3 parameters, found 2` | Add `_cx` as third handler parameter | |
| 107 | +| `trait JrRole is not implemented` | Add role parameter: `JrConnectionCx<YourRole>` | |
| 108 | +| `cannot find type MessageAndCx` | Use `MessageCx` | |
| 109 | +| `method connection_cx not found` | Use `cx` parameter passed to handler | |
| 110 | +| `cannot find to_successor/from_successor` | Use `send_request_to(sacp::Agent, ...)` | |
| 111 | +| `cannot find sacp_proxy` | Remove dep, use `sacp::mcp_server` | |
0 commit comments