Help us shape the future of Go! Take the 2026 Go Developer Survey

mcpserver

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 47 Imported by: 0

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

View Source
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

func B5BodyDigest(method string, payload any) ([32]byte, error)

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.

func NewHTTPHandler

func NewHTTPHandler(
	runtime *bootstrap.Runtime,
	cfg config.Config,
	logger zerolog.Logger,
	options ...HTTPOption,
) (http.Handler, error)

NewHTTPHandler creates the multi-tenant Streamable HTTP endpoint.

func RunStdio

func RunStdio(ctx context.Context, options Options) error

RunStdio blocks while serving MCP JSON-RPC on stdin/stdout. This function itself never writes stdout; the SDK owns the protocol channel exclusively.

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 B5OpenSessionInput struct {
	TenantID    string `json:"tenant_id,omitempty"`
	PrincipalID string `json:"principal_id,omitempty"`
}

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 B5PlanStatement struct {
	OperationID string `json:"operation_id"`
	SQL         string `json:"sql"`
	Reason      string `json:"reason"`
}

type B5SessionInput

type B5SessionInput struct{ B5Continuation }

type B5SessionView

type B5SessionView struct {
	SessionID          string           `json:"session_id"`
	ContinuationSecret string           `json:"continuation_secret,omitempty"`
	OwnerEpoch         uint64           `json:"owner_epoch"`
	Status             b5.SessionStatus `json:"status"`
	StickyRoute        string           `json:"sticky_route,omitempty"`
}

type B5ToolService

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

func NewServer(ctx context.Context, options Options) (*Server, error)

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL