Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthHeaderFromContext ¶
AuthHeaderFromContext 从 context 中取出 Authorization header 值。 若 context 中不存在则返回空字符串。
func ContextWithAuthHeader ¶
ContextWithAuthHeader 返回一个携带 Authorization header 值的子 context。 调用方通常是 HTTP 中间件,把客户端原始 Authorization 注入 context, 供下游的 MCP tool handler 透传到 outgoing HTTP 请求(如 AutoBridge 调用 gateway)。
func LoggingMiddleware ¶
LoggingMiddleware 是简易的 HTTP 请求日志中间件, 记录 method、path、status 和 duration。
func NewAuthMiddleware ¶
NewAuthMiddleware 创建 HTTP 认证中间件。 若 authFn 为 nil 则直接放行(无认证模式); 否则在调用下游 handler 前执行认证,失败时返回 401 JSON 错误。
无论 authFn 是否 nil,本中间件都会通过 r.WithContext 把原始 Authorization header 注入到请求 context,使下游 AutoBridge tool handler 能透传给 gateway。 这样即便 SecurityConfig.Enable=false(authFn=nil),客户端携带的 Authorization 仍可被透传到 gateway,保证审计与鉴权链路完整。
Types ¶
type AuthFunc ¶
AuthFunc 是 MCP 认证回调函数签名。 验证成功返回 nil,失败返回 error。 pkg/cfg.SecurityConfig.VerifyHTTPRequest 满足此签名。
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 封装 MCP Server 及其 HTTP handler
func (*Server) Close ¶
Close 优雅关闭 MCP Server 的所有活跃 sessions 采用 best-effort 策略:遍历所有活跃 session 逐个关闭,收集第一个错误但继续关闭剩余 session。 SDK handler 无导出的 Close 方法,关闭 session 后 HTTP 连接会自然终止。