Documentation
¶
Overview ¶
Package mcpkit provides small, opinionated helpers shared by Go MCP servers.
It standardizes server metadata, tool safety annotations, local stdio lifecycle, and bounded stateless HTTP transport. Applications retain their tool schemas, authentication, authorization, auditing, and domain behavior.
Index ¶
- Constants
- func Destructive(idempotent, openWorld bool) *mcp.ToolAnnotations
- func MustServer(cfg ServerConfig) *mcp.Server
- func Mutating(idempotent, openWorld bool) *mcp.ToolAnnotations
- func NewServer(cfg ServerConfig) (*mcp.Server, error)
- func NormalClose(err error) bool
- func ReadOnly(openWorld bool) *mcp.ToolAnnotations
- func RunStdio(ctx context.Context, server *mcp.Server) error
- func StatelessHTTP(factory func(*http.Request) *mcp.Server, opts HTTPOptions) (http.Handler, error)
- type HTTPOptions
- type ServerConfig
Constants ¶
const DefaultMaxRequestBodyBytes int64 = 1 << 20
Variables ¶
This section is empty.
Functions ¶
func Destructive ¶
func Destructive(idempotent, openWorld bool) *mcp.ToolAnnotations
Destructive marks a write that may overwrite, revoke, or delete state.
func MustServer ¶
func MustServer(cfg ServerConfig) *mcp.Server
MustServer is NewServer for application initialization where invalid static configuration is a programming error.
func Mutating ¶
func Mutating(idempotent, openWorld bool) *mcp.ToolAnnotations
Mutating marks an additive or non-destructive write. Idempotent describes whether repeating the same call has no additional effect.
func NewServer ¶
func NewServer(cfg ServerConfig) (*mcp.Server, error)
NewServer constructs an official-SDK server with consistent metadata.
func NormalClose ¶
NormalClose reports errors produced by an expected client disconnect or caller cancellation. Wrapped errors must preserve their cause for errors.Is; message text is deliberately not used to classify process exit status.
func ReadOnly ¶
func ReadOnly(openWorld bool) *mcp.ToolAnnotations
ReadOnly marks a tool as side-effect free and idempotent. Set openWorld when it may read from arbitrary external entities rather than a closed service or configured data set. MCP annotations are advisory client hints; applications must still enforce authorization and safety policy in their handlers.
func RunStdio ¶
RunStdio serves until the client disconnects or ctx is cancelled. Normal transport closure is reported as success so command entry points do not need to duplicate SDK-specific EOF handling.
func StatelessHTTP ¶
StatelessHTTP returns a JSON-response Streamable HTTP handler with a request body limit and browser cross-origin protection.
The returned handler is publicly callable unless the application wraps it in authentication and authorization middleware. Cross-origin and localhost protections defend browser and DNS-rebinding boundaries; they are not access control and non-browser clients may send neither relevant header. Public deployments must also provide appropriate rate, concurrency, and request timeout limits. Authentication should wrap this handler so the factory can derive identity from r.Context; returning nil for a missing identity makes the SDK reject the request.
SDK logging can include tool arguments at debug level. Do not attach a debug logger in production when tool inputs may contain sensitive information.
Types ¶
type HTTPOptions ¶
type HTTPOptions struct {
// MaxRequestBodyBytes defaults to 1 MiB. Negative values are invalid; zero
// selects the default rather than disabling the limit.
MaxRequestBodyBytes int64
Logger *slog.Logger
// TrustedOrigins permits exact browser Origin values such as
// "https://console.example.com" while retaining protection against all
// other cross-origin browser requests.
TrustedOrigins []string
// DisableBrowserOriginProtection disables only Go's outer Origin and
// Sec-Fetch-Site checks. It does not disable the SDK's independent localhost
// DNS-rebinding protection and it is not an authentication mechanism. Use it
// only when a trusted outer HTTP layer already enforces browser origins.
DisableBrowserOriginProtection bool
// DisableLocalhostProtection permits reverse proxies that connect to a
// loopback listener while preserving the external Host header. Use it only
// when a trusted proxy or network boundary prevents direct untrusted access
// to that listener. Browser origin protection remains independent.
DisableLocalhostProtection bool
}
HTTPOptions controls the bounded stateless Streamable HTTP helper.
type ServerConfig ¶
type ServerConfig struct {
Name string
Version string
Instructions string
Logger *slog.Logger
PageSize int
}
ServerConfig is the metadata and behavior shared by one application's MCP server. Name is required. Version should normally be the application build version rather than a separate MCP API version.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mcpkittest provides black-box MCP test connections.
|
Package mcpkittest provides black-box MCP test connections. |