Documentation
¶
Overview ¶
Package mcpserver exposes the frozen AgentSQL tools over MCP stdio and authenticated multi-tenant Streamable HTTP. HTTP transport sessions are stateful by default and can be explicitly rolled back to stateless mode.
Index ¶
- Constants
- func B5BodyDigest(method string, payload any) ([32]byte, error)
- func NewHTTPHandler(runtime *bootstrap.Runtime, cfg config.Config, logger zerolog.Logger, ...) (http.Handler, error)
- func RunStdio(ctx context.Context, options Options) error
- type B5BeginInput
- type B5Continuation
- type B5CoordinatorService
- func (service *B5CoordinatorService) Begin(ctx context.Context, agentID string, input B5BeginInput) (b5coordinator.Result, error)
- func (service *B5CoordinatorService) CheckB5Datasource(ctx context.Context, datasourceID string) error
- func (service *B5CoordinatorService) CloseSession(ctx context.Context, agentID string, input B5SessionInput) (B5SessionView, error)
- func (service *B5CoordinatorService) Commit(ctx context.Context, agentID string, input B5FinishInput) (b5coordinator.Result, error)
- func (service *B5CoordinatorService) Execute(ctx context.Context, agentID string, input B5ExecuteInput) (b5coordinator.Result, error)
- func (service *B5CoordinatorService) OpenSession(ctx context.Context, agentID string, input B5OpenSessionInput) (B5SessionView, error)
- func (service *B5CoordinatorService) Rollback(ctx context.Context, agentID string, input B5FinishInput) (b5coordinator.Result, error)
- func (service *B5CoordinatorService) SessionStatus(ctx context.Context, agentID string, input B5SessionInput) (B5SessionView, error)
- func (service *B5CoordinatorService) Shutdown(ctx context.Context) error
- func (service *B5CoordinatorService) TransactionStatus(ctx context.Context, agentID string, input B5FinishInput) (b5coordinator.Result, error)
- type B5DatasourceAuthority
- type B5ExecuteInput
- type B5FinishInput
- type B5OpenSessionInput
- type B5Options
- type B5PlanStatement
- type B5SessionInput
- type B5SessionView
- type B5ToolService
- type HTTPOption
- type HumanDelegationVerifier
- type Options
- type Server
- type ToolResponse
Constants ¶
const ( // MCPSessionExpiredHeader tells clients that a supplied transport session // ID is no longer present and initialize must be performed again. MCPSessionExpiredHeader = "Mcp-Session-Expired" MCPSessionExpiredValue = "1" )
Variables ¶
This section is empty.
Functions ¶
func B5BodyDigest ¶
B5BodyDigest returns the canonical digest signed by the continuation proof. Proof and claimed digest fields are blanked before encoding, so neither can self-authenticate. The schema and method are domain-separated.
Types ¶
type B5BeginInput ¶
type B5BeginInput struct {
B5Continuation
TransactionID string `json:"transaction_id"`
DatasourceID string `json:"datasource_id"`
Dialect string `json:"dialect"`
ServerMajor int `json:"server_major"`
KeyRevision uint64 `json:"key_revision"`
DatasourceRevision uint64 `json:"datasource_revision"`
PolicyRevision uint64 `json:"policy_revision"`
ApprovalID string `json:"approval_id,omitempty"`
Statements []B5PlanStatement `json:"statements"`
}
type B5Continuation ¶
type B5Continuation struct {
SessionID string `json:"session_id" jsonschema:"显式 AgentSQL session ID;不得传 MCP transport session ID"`
OwnerEpoch uint64 `json:"owner_epoch"`
RequestID string `json:"request_id"`
ContinuationProof string `json:"continuation_proof"`
BodyDigest string `json:"body_digest" jsonschema:"参与 continuation proof 的 32-byte hex digest"`
ExpectedSeq *uint64 `json:"expected_seq,omitempty"`
}
type B5CoordinatorService ¶
type B5CoordinatorService struct {
Directory *b5session.Directory
Coordinator *b5coordinator.Coordinator
Analyzer b5coordinator.Analyzer
AnalyzerResolver b5coordinator.PlanAnalyzerResolver
InstanceID string
StickyRoute string
FinalFence func(context.Context, b5coordinator.Result) error
Admission func() error
CheckDialect func(context.Context, string) error
ResolveDatasource func(context.Context, string) (B5DatasourceAuthority, error)
Limits b5coordinator.ResourceLimits
// contains filtered or unexported fields
}
B5CoordinatorService adapts the reviewed directory and planned coordinator to MCP without exposing either a raw SQL executor or a database session.
func (*B5CoordinatorService) Begin ¶
func (service *B5CoordinatorService) Begin(ctx context.Context, agentID string, input B5BeginInput) (b5coordinator.Result, error)
func (*B5CoordinatorService) CheckB5Datasource ¶
func (service *B5CoordinatorService) CheckB5Datasource(ctx context.Context, datasourceID string) error
CheckB5Datasource is the metadata-only dialect gate used before parsing a plan. Production wires it to a repository lookup that never opens a business connection.
func (*B5CoordinatorService) CloseSession ¶
func (service *B5CoordinatorService) CloseSession(ctx context.Context, agentID string, input B5SessionInput) (B5SessionView, error)
func (*B5CoordinatorService) Commit ¶
func (service *B5CoordinatorService) Commit(ctx context.Context, agentID string, input B5FinishInput) (b5coordinator.Result, error)
func (*B5CoordinatorService) Execute ¶
func (service *B5CoordinatorService) Execute(ctx context.Context, agentID string, input B5ExecuteInput) (b5coordinator.Result, error)
func (*B5CoordinatorService) OpenSession ¶
func (service *B5CoordinatorService) OpenSession(ctx context.Context, agentID string, input B5OpenSessionInput) (B5SessionView, error)
func (*B5CoordinatorService) Rollback ¶
func (service *B5CoordinatorService) Rollback(ctx context.Context, agentID string, input B5FinishInput) (b5coordinator.Result, error)
func (*B5CoordinatorService) SessionStatus ¶
func (service *B5CoordinatorService) SessionStatus(ctx context.Context, agentID string, input B5SessionInput) (B5SessionView, error)
func (*B5CoordinatorService) Shutdown ¶
func (service *B5CoordinatorService) Shutdown(ctx context.Context) error
func (*B5CoordinatorService) TransactionStatus ¶
func (service *B5CoordinatorService) TransactionStatus(ctx context.Context, agentID string, input B5FinishInput) (b5coordinator.Result, error)
type B5DatasourceAuthority ¶
type B5DatasourceAuthority struct {
Dialect, Mode string
ServerMajor int
KeyRevision, DatasourceRevision, PolicyRevision uint64
}
B5DatasourceAuthority contains only server-verified facts. The service overwrites all matching client fields before coordinator preflight.
type B5ExecuteInput ¶
type B5ExecuteInput struct {
B5Continuation
TransactionID string `json:"transaction_id"`
OperationID string `json:"operation_id"`
Ordinal int `json:"ordinal"`
}
type B5FinishInput ¶
type B5FinishInput struct {
B5Continuation
TransactionID string `json:"transaction_id"`
}
type B5OpenSessionInput ¶
type B5Options ¶
type B5Options struct {
B5Sessions bool
B5TxPostgres bool
B5TxMySQL bool
Service B5ToolService
}
B5Options is deliberately zero/off by default. Tests and, after S10, the activation assembly must opt in explicitly. MySQL cannot be enabled in v0.4.
type B5PlanStatement ¶
type B5SessionInput ¶
type B5SessionInput struct{ B5Continuation }
type B5SessionView ¶
type B5ToolService ¶
type B5ToolService interface {
OpenSession(context.Context, string, B5OpenSessionInput) (B5SessionView, error)
CloseSession(context.Context, string, B5SessionInput) (B5SessionView, error)
SessionStatus(context.Context, string, B5SessionInput) (B5SessionView, error)
Begin(context.Context, string, B5BeginInput) (b5coordinator.Result, error)
Execute(context.Context, string, B5ExecuteInput) (b5coordinator.Result, error)
Commit(context.Context, string, B5FinishInput) (b5coordinator.Result, error)
Rollback(context.Context, string, B5FinishInput) (b5coordinator.Result, error)
TransactionStatus(context.Context, string, B5FinishInput) (b5coordinator.Result, error)
Shutdown(context.Context) error
}
B5ToolService is the narrow MCP-to-coordinator bridge. It does not expose a raw executor, database handle, transaction, or arbitrary SQL execution.
type HTTPOption ¶
type HTTPOption func(*httpHandlerOptions)
HTTPOption extends the T15 mux without changing its default routes.
func WithAdminAPI ¶
func WithAdminAPI(handler http.Handler) HTTPOption
WithAdminAPI mounts the T16 management API below /api/v1/.
func WithB5Sessions ¶
func WithB5Sessions(options B5Options) HTTPOption
WithB5Sessions installs the production B5 surface selected by bootstrap. The zero value remains feature-off so component tests and explicit rollback configurations preserve the pre-B5 server surface.
func WithHumanDelegation ¶ added in v1.0.0
func WithHumanDelegation(verifier HumanDelegationVerifier) HTTPOption
WithHumanDelegation supplies the live human-session verifier used when mcp.delegation.require_human_token is enabled.
func WithOAuthAccessVerifier ¶ added in v1.2.0
func WithOAuthAccessVerifier(verifier HumanDelegationVerifier) HTTPOption
WithOAuthAccessVerifier overrides external issuer discovery for a trusted test or deployment verifier.
func WithWebConsole ¶
func WithWebConsole(handler http.Handler) HTTPOption
WithWebConsole mounts the embedded T17 single-page application at /.
type HumanDelegationVerifier ¶ added in v1.0.0
type HumanDelegationVerifier interface {
Verify(context.Context, string, string) (rbac.Principal, error)
}
HumanDelegationVerifier validates a live human access token independently of the MCP Agent API key.
type Options ¶
type Options struct {
APIKey string
Runtime *bootstrap.Runtime
Logger zerolog.Logger
Version string
B5 B5Options
SealedStdio bool
}
Options configures one authenticated stdio MCP server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server owns the SDK server and the immutable bound-Agent handlers.
func NewServer ¶
NewServer authenticates the stdio API key once and registers the base tools plus the production-selected B5 tools.
func (*Server) RunSealedStdioStreams ¶ added in v0.5.1
func (server *Server) RunSealedStdioStreams(ctx context.Context, reader io.ReadCloser, writer io.WriteCloser) error
RunSealedStdioStreams retains the v0.5.0 length-prefixed wire format for existing custom integrations that explicitly opt in to it.
func (*Server) RunStdioStreams ¶
func (server *Server) RunStdioStreams(ctx context.Context, reader io.ReadCloser, writer io.WriteCloser) error
RunStdioStreams serves standard newline-delimited MCP over the supplied streams. It permits end-to-end testing without replacing process stdin/stdout.
type ToolResponse ¶
type ToolResponse struct {
Decision string `json:"decision"`
ErrorCode string `json:"error_code,omitempty"`
ErrorStage string `json:"error_stage,omitempty"`
Reason string `json:"reason"`
Suggestion string `json:"suggestion"`
RetrySameRequest *bool `json:"retry_same_request,omitempty"`
NewTransactionAllowed *bool `json:"new_transaction_allowed,omitempty"`
TxEffect string `json:"tx_effect,omitempty"`
DBOutcome string `json:"db_outcome,omitempty"`
AuditDurability string `json:"audit_durability,omitempty"`
ConnectionDisposition string `json:"connection_disposition,omitempty"`
TerminalEventDigest string `json:"terminal_event_digest,omitempty"`
Data any `json:"data,omitempty"`
}