Documentation
¶
Overview ¶
Package mcpruntime 实现 XOps v2 MCP(Model Context Protocol)协议运行时与双传输引擎 (stdio JSON-RPC 2.0 + Streamable HTTP + 10 GiB HTTP 流式传输,ADR-006 / ADR-007 / ADR-008 / Plan P3-T5)。
核心安全与架构不变量:
- 双模态 FS 物理隔离(ADR-007):本包及全部子包物理禁止引用 ports.OperatorReadFS (由 xopsvet/archbound 强制),所有本地文件读写均仅通过基于 os.Root 的 ports.ScopedRootFS 完成;
- 严格六边形解耦:严禁导入 core/internal/pool、core/internal/sshnet/** 或 core/osfs, 全部业务操作均经 usecase/* 与 gate.Authorizer 执行;
- 启动期自动对账与恢复:ServeStdio / ServeHTTPListener / ListenAndServeHTTP 均在放行任何入站请求前 自动执行 O(1) 崩溃审计对账(Gate reconciler)与传输日志恢复(TransferService.RecoverAllTransfers), 遇存储/门控故障严格 Fail-Closed,对 TransferUncertainCommit 忠实记录且保持零副作用;
- StrictAgentProfile + Halted 熔断:任一 AuditPostWriteError 触发 Gate.IsHalted() 后, 全部 JSON-RPC 方法、7 个判别式工具与 HTTP 流式传输端点均立即拒绝新请求;
- 全部后台协程受 core/conc.Nursery 监督(0 裸 go、0 goleak、0 init()、0 可变包级 var、0 nolint 豁免)。
Index ¶
- Variables
- type AuditReconcileFunc
- type Server
- func (s *Server) Close(ctx context.Context) error
- func (s *Server) HandleMessage(ctx context.Context, raw []byte) ([]byte, bool, error)
- func (s *Server) Handler() http.Handler
- func (s *Server) IsClosed() bool
- func (s *Server) ListenAndServeHTTP(ctx context.Context, addr string) error
- func (s *Server) Prepare(ctx context.Context) (StartupReport, error)
- func (s *Server) ServeHTTPListener(ctx context.Context, ln net.Listener) error
- func (s *Server) ServeStdio(ctx context.Context, in io.Reader, out io.Writer) error
- func (s *Server) StartupReport() StartupReport
- type ServerConfig
- type StartupReport
- func (r StartupReport) AuditReport() algebraic.Option[ports.CrashReconcileReport]
- func (r StartupReport) CorruptTransfers() []TransferRecoverySummary
- func (r StartupReport) IsValid() bool
- func (r StartupReport) IsZero() bool
- func (r StartupReport) RecoveredTransfers() []TransferRecoverySummary
- func (r StartupReport) UncertainTransfers() []TransferRecoverySummary
- type TransferRecoverySummary
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidConfig 表示 ServerConfig 缺少必填依赖或限流/超时参数非法。 ErrInvalidConfig = domi18n.Sentinel(domi18n.KeyMCPInvalidConfig) // ErrServerNotInitialized 表示在 nil 或零值未初始化 Server 上调用方法。 ErrServerNotInitialized = domi18n.Sentinel(domi18n.KeyMCPServerNotInit) // ErrServerClosed 表示 MCP Server 已关闭,拒绝新请求或启动传输。 ErrServerClosed = domi18n.Sentinel(domi18n.KeyMCPServerClosed) // ErrNonLoopbackAddress 表示在未显式允许非回环监听时传入了非回环 HTTP 监听地址。 ErrNonLoopbackAddress = domi18n.Sentinel(domi18n.KeyMCPNonLoopback) // ErrMessageTooLarge 表示入站 JSON-RPC 报文超出最大允许字节上限。 ErrMessageTooLarge = domi18n.Sentinel(domi18n.KeyMCPMessageTooLarge) // ErrStartupReconcileFailed 表示启动期 O(1) 崩溃审计对账失败,严格 Fail-Closed 拒绝启动服务。 ErrStartupReconcileFailed = domi18n.Sentinel(domi18n.KeyMCPStartupReconcile) // ErrStartupRecoveryFailed 表示启动期传输 Journal 恢复遇到基础设施或损坏故障,拒绝启动服务。 ErrStartupRecoveryFailed = domi18n.Sentinel(domi18n.KeyMCPStartupRecovery) )
本包导出的不可变哨兵错误,供 core/engine、entry/mcpcmd 与测试经 errors.Is 精确区分运行期故障。
Functions ¶
This section is empty.
Types ¶
type AuditReconcileFunc ¶
type AuditReconcileFunc func(ctx context.Context) (ports.CrashReconcileReport, error)
AuditReconcileFunc 定义启动期 O(1) 跨进程崩溃审计对账函数签名(由 core/engine 接线至 Gate.ReconcileCrashedAudits)。
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 是 XOps v2 MCP 协议运行时核心(支持 stdio 与 Streamable HTTP 双传输 + 10 GiB 流式端点); 零值恒未初始化并严格失败关闭。
func NewServer ¶
func NewServer(cfg ServerConfig) (*Server, error)
NewServer 校验全部显式依赖、编译 7 个判别式工具 Schema 并构造 MCP Server 实例。
func (*Server) Close ¶
Close 幂等优雅关闭 MCP Server,取消全部在途传输与会话并等待收敛(受 ctx 有界约束): 尽力释放本 Server 追踪的非持久化活跃句柄(PTY/Forward/GUI/Mux)并清空本地索引, 故意不中止带 Journal 的可恢复 10 GiB 流式传输以保留断点续传与崩溃恢复契约(底层池句柄由 Engine.Close 统一回收)。
func (*Server) HandleMessage ¶
HandleMessage 处理单条入站 JSON-RPC 2.0 MCP 报文并返回确定性 JSON 响应字节; 严格强制 IsClosed() 停机门禁与 Prepare 启动对账/恢复 Fail-Closed 门禁; 当报文为通知(无 id)时返回 (nil, false, nil);Gate 处于 Halted 熔断态时拒绝全部请求并返回 -32001。
func (*Server) Handler ¶
Handler 返回完整的 Streamable HTTP MCP 与 10 GiB 流式传输 http.Handler; 供 ServeHTTPListener / ListenAndServeHTTP 及本地回环集成测试直接挂载,全部端点均受 Host/Origin/Session/Halted 保护。
func (*Server) ListenAndServeHTTP ¶
ListenAndServeHTTP 校验本地回环绑定地址(默认物理禁止非回环绑定),启动 Streamable HTTP 与 10 GiB 流式传输服务。
func (*Server) Prepare ¶
func (s *Server) Prepare(ctx context.Context) (StartupReport, error)
Prepare 执行 MCP Server 启动期自动对账(O(1) 崩溃审计对账)与传输日志恢复(RecoverJournals); 幂等且并发安全:一旦启动期检查成功完成即缓存报告,遇门控熔断或基础设施故障严格 Fail-Closed 拒绝放行。
func (*Server) ServeHTTPListener ¶
ServeHTTPListener 在调用方传入的 TCP 监听器上运行受 core/conc.Nursery 监督的 Streamable HTTP 服务: 启动前自动执行 Prepare(O(1) 崩溃审计对账 + RecoverJournals),取消或 Close 时同步优雅排空(0 goleak)。
func (*Server) ServeStdio ¶
ServeStdio 启动标准 MCP stdio(换行分隔 JSON-RPC 2.0)单流同步传输循环:
- 启动前自动执行 Prepare(O(1) 崩溃审计对账 + RecoverJournals);
- 严格实施入站单条报文大小有界读取(防 OOM 炸弹),逐条同步保序处理并输出响应行(0 裸 go);
- 输入流到达 io.EOF 时确定性退出并返回 nil;若上层(如 entry/mcpcmd)在阻塞读期间取消 ctx 或调用 Server.Close, 调用方需同时关闭传入的 in 读端以立即解除底层阻塞读取并完成优雅停机。
func (*Server) StartupReport ¶
func (s *Server) StartupReport() StartupReport
StartupReport 返回最近一次成功 Prepare 的启动期对账与恢复报告快照;未就绪时返回零值。
type ServerConfig ¶
type ServerConfig struct {
// Gate 是必填的安全能力门控授权器(用于实时探测 Halted 熔断与策略配置档)。
Gate gate.Authorizer
// ReconcileAudits 为启动期 O(1) 崩溃审计对账回调(StrictAgentProfile 下默认必填)。
ReconcileAudits AuditReconcileFunc
// AllowOptionalReconciler 仅在测试或非严格场景显式允许缺少 AuditReconciler 时跳过审计对账(默认 false 失败关闭)。
AllowOptionalReconciler bool
// 用例服务依赖(均由 core/engine 注入;其中 Transfer 与 Automation 物理不携带 OperatorReadFS)。
Inventory *ucinv.Service
Session *ucsess.Service
Transfer *uctrans.Service
Automation *ucauto.Service
Observability *ucobs.Service
// ScopedFS 为基于 os.Root 的沙箱本地文件系统端口(物理禁止 OperatorReadFS)。
ScopedFS ports.ScopedRootFS
// TransferRoot 可选指定 MCP 流式传输本地下载/沙箱源根目录(位于 ScopedFS 管控下)。
TransferRoot algebraic.Option[pathalg.LocalDir]
// ArtifactRoot 可选指定 GUI 截图产物沙箱根目录(未设置时回退 TransferRoot)。
ArtifactRoot algebraic.Option[pathalg.LocalDir]
// Clock 与 Entropy 为必填的确定性时钟与显式熵源端口(零 time.Now / crypto/rand)。
Clock ports.Clock
Entropy ports.Entropy
SystemBus *events.SystemBus
// MCP 协议元信息与传输安全限制。
ServerName string
ServerVersion string
Instructions string
MaxMessageBytes int64
MaxTrackedHandles int
HTTPChunkSize int64
MaxHTTPSessions int
AllowNonLoopbackHTTP bool
HTTPAllowedOrigins []string
HTTPAllowedHosts []string
HTTPReadHeaderTimeout algebraic.Option[algebraic.Duration]
HTTPShutdownTimeout algebraic.Option[algebraic.Duration]
PruneSupersededJournals bool
FailOnCorruptJournal bool
}
ServerConfig 定义 MCP 运行时 Server 的全显式依赖注入配置; 物理上严禁接收 ports.OperatorReadFS,且所有时长配置均使用 algebraic.Duration(零裸 time.Duration)。
type StartupReport ¶
type StartupReport struct {
// contains filtered or unexported fields
}
StartupReport 封装 MCP Server 启动期自动执行的 O(1) 崩溃审计对账与双代 Journal 恢复结果; 零值恒未就绪(valid == false)。
func (StartupReport) AuditReport ¶
func (r StartupReport) AuditReport() algebraic.Option[ports.CrashReconcileReport]
AuditReport 返回启动期崩溃审计对账报告(若已执行)。
func (StartupReport) CorruptTransfers ¶
func (r StartupReport) CorruptTransfers() []TransferRecoverySummary
CorruptTransfers 返回启动期发现的损坏日志摘要副本(零副作用)。
func (StartupReport) RecoveredTransfers ¶
func (r StartupReport) RecoveredTransfers() []TransferRecoverySummary
RecoveredTransfers 返回启动期健康恢复的传输摘要副本。
func (StartupReport) UncertainTransfers ¶
func (r StartupReport) UncertainTransfers() []TransferRecoverySummary
UncertainTransfers 返回启动期发现的 TransferUncertainCommit 隔离摘要副本(零副作用)。
type TransferRecoverySummary ¶
type TransferRecoverySummary struct {
TransferID security.OperationID `json:"transfer_id"`
StateKind fsm.TransferStateKind `json:"state_kind,omitzero"`
SelectedGen uint64 `json:"selected_gen"`
PrunedGenerations []uint64 `json:"pruned_generations,omitzero"`
UncertainCommit bool `json:"uncertain_commit,omitzero"`
Error string `json:"error,omitzero"`
}
TransferRecoverySummary 记录单条传输任务在启动期恢复扫描中的脱敏摘要(零副作用)。
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package protocol 定义 XOps v2 MCP 运行时(core/internal/mcpruntime)的强类型 JSON-RPC 2.0 与 MCP 协议报文编解码器、7 个判别式工具 Schema 契约、两步审批信封 DTO 以及脱敏错误分类器(ADR-001 / ADR-006 / ADR-008)。
|
Package protocol 定义 XOps v2 MCP 运行时(core/internal/mcpruntime)的强类型 JSON-RPC 2.0 与 MCP 协议报文编解码器、7 个判别式工具 Schema 契约、两步审批信封 DTO 以及脱敏错误分类器(ADR-001 / ADR-006 / ADR-008)。 |
|
Package tools 实现 XOps v2 MCP 运行时的全部 7 个强类型判别式工具处理器 (nodes、terminal_exec、terminal_session、file、transfer、tunnel、gui,ADR-006 / ADR-007 / ADR-008 / Plan P3-T5)。
|
Package tools 实现 XOps v2 MCP 运行时的全部 7 个强类型判别式工具处理器 (nodes、terminal_exec、terminal_session、file、transfer、tunnel、gui,ADR-006 / ADR-007 / ADR-008 / Plan P3-T5)。 |