Documentation
¶
Index ¶
- Constants
- Variables
- type Error
- type ErrorData
- type Message
- type RPCError
- type Request
- type Response
- type Server
- func (s *Server) Action(name string) (protocol.Action, bool)
- func (s *Server) AuditSnapshot() []audit.Event
- func (s *Server) BeginEnrollment() (display string, err error)
- func (s *Server) Call(ctx context.Context, req Request) (Response, error)
- func (s *Server) ExtConnected() bool
- func (s *Server) Serve(ctx context.Context, ln net.Listener, mux *http.ServeMux) error
- func (s *Server) Version() string
Constants ¶
const ( CodeInvalidRequest = "INVALID_REQUEST" CodeInternal = "INTERNAL_ERROR" CodeRateLimited = "RATE_LIMITED" CodeOperationExpired = "OPERATION_EXPIRED" )
Variables ¶
var ( // ErrNotConnected 表示当前没有已配对的扩展连接。 ErrNotConnected = errors.New("extension not connected") // ErrDisconnected 表示在途请求因扩展连接断开而作废。 ErrDisconnected = errors.New("extension connection lost") )
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID string `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
Message is one JSON-RPC 2.0 request, notification, success response, or error response.
type Request ¶
type Request struct {
ClientID string `json:"clientId"`
Action string `json:"action"`
Input json.RawMessage `json:"input"`
}
type Response ¶
type Response struct {
OK bool `json:"ok"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 是桥接 daemon 的 WS 服务核心:accept、双向认证握手、envelope 路由与阻塞写模型。 v1 只允许一个扩展实例:新完成握手的连接替换旧连接。
信任模型是扁平的:接入(enrollment)建立唯一长期密钥 K 即确立信任,CLI 与所有 MCP agent 都 经这条可信通道继承信任,不再逐客户端配对/铸令牌/撤销(docs/threat-model.md)。
func (*Server) AuditSnapshot ¶
AuditSnapshot 返回守卫侧安全事件的快照。
func (*Server) BeginEnrollment ¶
BeginEnrollment 打开一次接入窗口,返回展示形配对码(XXXX-XXXX)。供 sctl connect 使用; 码只在终端显示、绝不经 WS 下发给任何连接(docs/threat-model.md)。
func (*Server) Call ¶
Call 把一次 bridge action 转发给扩展并阻塞等待应答。write=true 的写调用可能挂起数分钟 (等待用户在浏览器审批)。调用方 ctx 取消 / 超过 writeDecisionTTL / 扩展断开时:
- ctx 取消 / 超时:向扩展发 $/cancelRequest 作废该操作,返回相应错误;
- 扩展断开:隐式作废全部在途请求,返回 ErrDisconnected。