{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package resolvemcp\n\nPackage resolvemcp exposes registered database models as Model Context Protocol (MCP) tools over HTTP (SSE and streamable HTTP), so an AI agent can discover, read and change data without a tool per table.\n\n### How an agent uses it {#hdr-How_an_agent_uses_it}\n\nThe tool set is fixed and does not grow with the models:\n\n\tlist_tables      tables the caller may use, their description and allowed operations\n\tdescribe_table   columns, types, keys, relations, writable fields, limits\n\tselect_table     read rows: filters, sort, columns, preloads, paging, cursors\n\tinsert_into_table / update_table / delete_from_table\n\t                 writes; filter-based writes are previewed (dry_run) and need the\n\t                 confirm_token from the preview\n\tlist_functions / call_function   registered stored functions\n\tresolvespec_annotate             optional free-text notes (Config.EnableAnnotations)\n\nThe same guide is sent to MCP clients as the server instructions.\n\nThe server is read-only by default (Config.ReadOnly nil means on); set ReadOnly: resolvemcp.Bool(false) to enable the write tools.\n\n### Setting it up {#hdr-Setting_it_up}\n\n\thandler := resolvemcp.NewHandlerWithGORM(db, resolvemcp.Config{BaseURL: \"http://localhost:8080\"})\n\thandler.RegisterModel(\"public\", \"users\", \u0026User{})\n\n\tr := mux.NewRouter()\n\tresolvemcp.SetupMuxRoutes(r, handler, securityList) // requires an authenticated caller\n\n### Describing the API for agents {#hdr-Describing_the_API_for_agents}\n\nModels are documented through the model registry (see package modelregistry): SetModelDescription / LoadModelDescriptions on the handler, a ModelDescription() method on the model, or comment tags on its fields (gorm/bun \"comment:\" or comment/note/desc tags). The descriptions show up in list\\_tables and describe\\_table.\n\nExportCatalog writes the whole picture (guide, tools, limits, tables with columns, relations, operations and descriptions) to a JSON or Markdown file on disk, so agents and developers can learn the API without connecting:\n\n\thandler.ExportCatalog(\"docs/mcp-catalog.md\")\n\n### Security {#hdr-Security}\n\nRoutes must be mounted behind Guard(securityList); the \\*Unauthenticated setup functions exist only for use behind another trusted layer. Per-entity rules come from modelregistry.ModelRules, and BeforeHandle/AfterHandle hooks can veto or audit any call.\n\n## Constants\n\n```go\nconst (\n\tCodeInvalidArgument = \"invalid_argument\"\n\tCodeNotFound        = \"not_found\"\n\tCodeForbidden       = \"forbidden\"\n\tCodeLimitExceeded   = \"limit_exceeded\"\n\tCodeInternal        = \"internal\"\n)\n```\nStable error codes returned to MCP clients.\n\n```go\nconst (\n\tParamString  = \"string\"\n\tParamInteger = \"integer\"\n\tParamNumber  = \"number\"\n\tParamBoolean = \"boolean\"\n\tParamObject  = \"object\"\n\tParamArray   = \"array\"\n)\n```\nParameter types a function may declare.\n\n## Functions\n\n```go\nfunc Bool(v bool) *bool\n```\nBool returns a pointer to v, for the optional boolean fields of Config.\n\n```go\nfunc GetEntity(ctx context.Context) string\n```\n\n```go\nfunc GetModel(ctx context.Context) interface{}\n```\n\n```go\nfunc GetModelPtr(ctx context.Context) interface{}\n```\n\n```go\nfunc GetSchema(ctx context.Context) string\n```\n\n```go\nfunc GetTableName(ctx context.Context) string\n```\n\n```go\nfunc Guard(securityList *security.SecurityList) func(http.Handler) http.Handler\n```\nGuard returns middleware that requires an authenticated caller on every request.\n\nThe security list's provider decides which credentials are accepted: build it from a security.ChainAuthenticator over an OAuth bearer token, a session token (header or cookie) and an API key authenticator. The authenticated security.UserContext is placed in the request context, which the MCP transports pass on to every tool call, so rules, row security and OnTxBegin apply to that caller.\n\nUnlike security.NewAuthMiddleware this guard has no guest or optional mode: it ignores security.SkipAuth / security.OptionalAuth markers on the request context, and fails closed (500) when no provider is configured.\n\n```go\nfunc NewClientError(code, message string) error\n```\nNewClientError returns an error that reaches the client as {code, message}.\n\n```go\nfunc NewSSEServer(handler *Handler, securityList *security.SecurityList) http.Handler\n```\nNewSSEServer returns an http.Handler that serves MCP over SSE behind Guard(securityList). If Config.BasePath is set it is used directly; otherwise the base path is detected from each incoming request (by stripping the \"/sse\" or \"/message\" suffix).\n\n\th := resolvemcp.NewSSEServer(handler, securityList)\n\thttp.Handle(\"/api/mcp/\", h)\n\n```go\nfunc NewStreamableHTTPHandler(handler *Handler, securityList *security.SecurityList) http.Handler\n```\nNewStreamableHTTPHandler returns an http.Handler that serves MCP over the streamable HTTP transport behind Guard(securityList). Mount it at the desired path; that path becomes the MCP endpoint.\n\n\th := resolvemcp.NewStreamableHTTPHandler(handler, securityList)\n\thttp.Handle(\"/mcp\", h)\n\tengine.Any(\"/mcp\", gin.WrapH(h))\n\n```go\nfunc OAuth2CallbackHandler(auth *security.DatabaseAuthenticator, providerName, afterLoginRedirect string, cookieOpts ...security.SessionCookieOptions) http.HandlerFunc\n```\nOAuth2CallbackHandler returns an http.HandlerFunc that handles the OAuth2 provider callback: exchanges the authorization code for a session token, writes the session cookie, then either redirects to afterLoginRedirect or writes the LoginResponse as JSON.\n\nRegister it on any router:\n\n\tmux.Handle(\"/auth/google/callback\", resolvemcp.OAuth2CallbackHandler(auth, \"google\", \"/dashboard\"))\n\n```go\nfunc OAuth2LoginHandler(auth *security.DatabaseAuthenticator, providerName string) http.HandlerFunc\n```\nOAuth2LoginHandler returns an http.HandlerFunc that redirects the browser to the OAuth2 provider's authorization URL.\n\nRegister it on any router:\n\n\tmux.Handle(\"/auth/google/login\", resolvemcp.OAuth2LoginHandler(auth, \"google\"))\n\n```go\nfunc RegisterSecurityHooks(handler *Handler, securityList *security.SecurityList)\n```\nRegisterSecurityHooks wires the security package's access-control layer into the resolvemcp handler. Call it once after creating the handler, before registering models.\n\nThe following controls are applied:\n\n  - Per-entity operation rules (CanRead, CanCreate, CanUpdate, CanDelete, CanPublic\\*) stored via RegisterModelWithRules / SetModelRules.\n  - Row-level security: WHERE clause injected per user from the SecurityList provider.\n  - Column-level security: sensitive columns masked/hidden in read results.\n  - Audit logging after each read.\n\n```go\nfunc SetupBunRouterRoutes(router *bunrouter.Router, handler *Handler, securityList *security.SecurityList)\n```\nSetupBunRouterRoutes mounts the MCP HTTP/SSE endpoints on a bunrouter router using the base path from Config.BasePath, behind Guard(securityList).\n\nRoutes registered:\n\n  - GET  {basePath}/sse     — SSE connection endpoint\n  - POST {basePath}/message — JSON-RPC message endpoint\n\n```go\nfunc SetupBunRouterRoutesUnauthenticated(router *bunrouter.Router, handler *Handler)\n```\nSetupBunRouterRoutesUnauthenticated is SetupBunRouterRoutes without the guard. A warning is logged.\n\n```go\nfunc SetupBunRouterStreamableHTTPRoutes(router *bunrouter.Router, handler *Handler, securityList *security.SecurityList)\n```\nSetupBunRouterStreamableHTTPRoutes mounts the MCP streamable HTTP endpoint on a bunrouter router, behind Guard(securityList). The transport uses a single endpoint (Config.BasePath).\n\n```go\nfunc SetupBunRouterStreamableHTTPRoutesUnauthenticated(router *bunrouter.Router, handler *Handler)\n```\nSetupBunRouterStreamableHTTPRoutesUnauthenticated is SetupBunRouterStreamableHTTPRoutes without the guard. A warning is logged.\n\n```go\nfunc SetupMuxOAuth2Routes(muxRouter *mux.Router, auth *security.DatabaseAuthenticator, cfg OAuth2RouteConfig)\n```\nSetupMuxOAuth2Routes registers the OAuth2 login and callback routes on a Gorilla Mux router.\n\nExample:\n\n\tresolvemcp.SetupMuxOAuth2Routes(r, auth, resolvemcp.OAuth2RouteConfig{\n\t    ProviderName: \"google\", LoginPath: \"/auth/google/login\",\n\t    CallbackPath: \"/auth/google/callback\", AfterLoginRedirect: \"/\",\n\t})\n\n```go\nfunc SetupMuxRoutes(muxRouter *mux.Router, handler *Handler, securityList *security.SecurityList)\n```\nSetupMuxRoutes mounts the MCP HTTP/SSE endpoints on the given Gorilla Mux router using the base path from Config.BasePath, behind Guard(securityList).\n\nRoutes registered:\n\n  - GET  {basePath}/sse     — SSE connection endpoint (client subscribes here)\n  - POST {basePath}/message — JSON-RPC message endpoint (client sends requests here)\n\nNothing is mounted (and an error is logged) when securityList has no provider.\n\n```go\nfunc SetupMuxRoutesUnauthenticated(muxRouter *mux.Router, handler *Handler)\n```\nSetupMuxRoutesUnauthenticated is SetupMuxRoutes without the guard. Every caller reaches every registered model, so use it only behind another trusted layer. A warning is logged.\n\n```go\nfunc SetupMuxStreamableHTTPRoutes(muxRouter *mux.Router, handler *Handler, securityList *security.SecurityList)\n```\nSetupMuxStreamableHTTPRoutes mounts the MCP streamable HTTP endpoint on the given Gorilla Mux router, behind Guard(securityList). The streamable HTTP transport uses a single endpoint (Config.BasePath) for all communication: POST for client→server messages, GET for server→client streaming.\n\nNothing is mounted (and an error is logged) when securityList has no provider.\n\n```go\nfunc SetupMuxStreamableHTTPRoutesUnauthenticated(muxRouter *mux.Router, handler *Handler)\n```\nSetupMuxStreamableHTTPRoutesUnauthenticated is SetupMuxStreamableHTTPRoutes without the guard. A warning is logged.\n\n```go\nfunc WithEntity(ctx context.Context, entity string) context.Context\n```\n\n```go\nfunc WithModel(ctx context.Context, model interface{}) context.Context\n```\n\n```go\nfunc WithModelPtr(ctx context.Context, modelPtr interface{}) context.Context\n```\n\n```go\nfunc WithSchema(ctx context.Context, schema string) context.Context\n```\n\n```go\nfunc WithTableName(ctx context.Context, tableName string) context.Context\n```\n\n## Types\n\n```go\ntype Catalog struct {\n\tGeneratedAt time.Time      `json:\"generated_at\"`\n\tServer      string         `json:\"server\"`\n\tVersion     string         `json:\"version\"`\n\tReadOnly    bool           `json:\"read_only\"`\n\tGuide       string         `json:\"guide\"`\n\tLimits      CatalogLimits  `json:\"limits\"`\n\tTools       []CatalogTool  `json:\"tools\"`\n\tTables      []CatalogTable `json:\"tables\"`\n}\n```\nCatalog is a snapshot of what the server offers: the usage guide, the tools, the limits and every table with its columns, relations, allowed operations and descriptions.\n\n```go\nfunc (c Catalog) Markdown() string\n```\nMarkdown renders the catalogue as a Markdown document.\n\n```go\ntype CatalogColumn struct {\n\tName        string `json:\"name\"`\n\tType        string `json:\"type,omitempty\"`\n\tNullable    bool   `json:\"nullable\"`\n\tPrimaryKey  bool   `json:\"primary_key,omitempty\"`\n\tUnique      bool   `json:\"unique,omitempty\"`\n\tWritable    bool   `json:\"writable\"`\n\tDescription string `json:\"description,omitempty\"`\n}\n```\nCatalogColumn is one column of a table.\n\n```go\ntype CatalogLimits struct {\n\tDefaultLimit    int `json:\"default_limit\"`\n\tMaxLimit        int `json:\"max_limit\"`\n\tMaxOffset       int `json:\"max_offset\"`\n\tMaxBatch        int `json:\"max_batch\"`\n\tMaxPreloadDepth int `json:\"max_preload_depth\"`\n\tMaxWriteRows    int `json:\"max_write_rows\"`\n}\n```\nCatalogLimits mirrors the configured server limits.\n\n```go\ntype CatalogTable struct {\n\tTable       string          `json:\"table\"`\n\tDescription string          `json:\"description,omitempty\"`\n\tPurpose     string          `json:\"purpose,omitempty\"`\n\tTags        []string        `json:\"tags,omitempty\"`\n\tOperations  []string        `json:\"operations\"`\n\tPrimaryKey  string          `json:\"primary_key,omitempty\"`\n\tColumns     []CatalogColumn `json:\"columns\"`\n\tRelations   []string        `json:\"relations,omitempty\"`\n}\n```\nCatalogTable is one table in the catalogue.\n\n```go\ntype CatalogTool struct {\n\tName        string `json:\"name\"`\n\tDescription string `json:\"description\"`\n}\n```\nCatalogTool is one MCP tool.\n\n```go\ntype ClientError struct {\n\tCode    string\n\tMessage string\n}\n```\nClientError is an error whose code and message are safe to show to an MCP client. Hooks may return one (NewClientError) to give the client a specific reason; every other error is reported as an opaque internal error with a reference that matches the server log.\n\n```go\nfunc (e *ClientError) Error() string\n```\n\n```go\ntype Config struct {\n\t// BaseURL is the public-facing base URL of the server (e.g. \"http://localhost:8080\").\n\t// It is sent to MCP clients during the SSE handshake so they know where to POST messages.\n\tBaseURL string\n\n\t// BasePath is the URL path prefix where the MCP endpoints are mounted (e.g. \"/mcp\").\n\t// If empty, the path is detected from each incoming request automatically.\n\tBasePath string\n\n\t// DefaultLimit is the page size when a read gives no limit (50).\n\tDefaultLimit int\n\t// MaxLimit caps a read's limit; larger values are clamped (1000).\n\tMaxLimit int\n\t// MaxOffset rejects a read whose offset is larger (100000).\n\tMaxOffset int\n\t// MaxBatch caps the items in one batch create (100).\n\tMaxBatch int\n\t// MaxPreloadDepth caps the depth of a preload path such as \"a.b.c\" (2).\n\tMaxPreloadDepth int\n\t// MaxWriteRows caps the rows a filter-based update or delete may touch (100).\n\tMaxWriteRows int\n\t// QueryTimeout bounds one tool call, hooks and queries included (30s).\n\tQueryTimeout time.Duration\n\t// ConfirmTTL is how long a confirmation token for a filter write stays valid (5m).\n\tConfirmTTL time.Duration\n\n\t// AllowedHosts restricts the Host header accepted by the SSE transport when BaseURL is\n\t// empty (the message endpoint URL sent to clients is built from it). Empty accepts any\n\t// host, with at most 32 distinct base URLs cached; prefer setting BaseURL.\n\tAllowedHosts []string\n\n\t// ReadOnly disables every write and is ON when left nil: set it to Bool(false) to allow\n\t// writes. When on, the insert, update, delete and annotation tools are not registered,\n\t// list_tables and describe_table report only the select operation (no writable columns),\n\t// a write attempted anyway is refused with a \"forbidden\" error, and the server\n\t// instructions tell the agent it cannot write. list_functions/call_function are also\n\t// off, because a registered function may change data, unless AllowFunctionCalls is set.\n\tReadOnly *bool\n\n\t// AllowFunctionCalls keeps list_functions and call_function available on a ReadOnly\n\t// server. Only set it for functions that do not change data; pair it with\n\t// AllowedFunctions to name them. It has no effect when writes are enabled (ReadOnly set to Bool(false)) (functions are\n\t// always available then).\n\tAllowFunctionCalls bool\n\n\t// AllowedFunctions restricts list_functions and call_function to the named functions.\n\t// Empty allows every registered function. A function outside the list is reported as\n\t// unknown, so its existence is not revealed.\n\tAllowedFunctions []string\n\n\t// EnableAnnotations registers the resolvespec_annotate tool. Off by default: annotations\n\t// are free text that agents read back, so enabling the tool opens a write channel into\n\t// agent-visible text. When on, every call runs the BeforeHandle hooks (operation\n\t// \"annotate_set\" / \"annotate_get\") and the writes run in a transaction with OnTxBegin.\n\tEnableAnnotations bool\n\t// contains filtered or unexported fields\n}\n```\nConfig holds configuration for the resolvemcp handler.\n\n```go\ntype Function struct {\n\tName        string\n\tDescription string\n\tParams      []FunctionParam\n\n\t// Handler is the Go callback.\n\tHandler FunctionFunc\n\t// Procedure is the SQL function to call, optionally schema-qualified. Declared params are\n\t// passed positionally in declaration order; an omitted optional param is NULL. Rows\n\t// returned are the result.\n\tProcedure string\n\n\t// Authorize, when set, decides per caller whether the function is listed and callable.\n\t// Return nil to allow.\n\tAuthorize func(ctx context.Context) error\n}\n```\nFunction is a callable registered with Handler.RegisterFunction. Exactly one of Handler (a Go callback) and Procedure (a SQL function called by name) is set.\n\n```go\ntype FunctionFunc func(ctx context.Context, tx common.Database, args map[string]any) (any, error)\n```\nFunctionFunc is a Go function callable through call\\_function. tx is the transaction the call runs in (OnTxBegin already fired on it); args are validated against the declared params.\n\n```go\ntype FunctionParam struct {\n\tName        string\n\tType        string // one of the Param* constants\n\tDescription string\n\tRequired    bool\n}\n```\nFunctionParam declares one argument of a registered function.\n\n```go\ntype Handler struct {\n\t// contains filtered or unexported fields\n}\n```\nHandler exposes registered database models as MCP tools and resources.\n\n```go\nfunc NewHandler(db common.Database, registry common.ModelRegistry, cfg Config) *Handler\n```\nNewHandler creates a Handler with the given database, model registry, and config.\n\n```go\nfunc NewHandlerWithBun(db *bun.DB, cfg Config) *Handler\n```\nNewHandlerWithBun creates a Handler backed by a Bun database connection.\n\n```go\nfunc NewHandlerWithDB(db common.Database, cfg Config) *Handler\n```\nNewHandlerWithDB creates a Handler using an existing common.Database and a new registry.\n\n```go\nfunc NewHandlerWithGORM(db *gorm.DB, cfg Config) *Handler\n```\nNewHandlerWithGORM creates a Handler backed by a GORM database connection.\n\n```go\nfunc (h *Handler) AuthedSSEServer(securityList *security.SecurityList) http.Handler\n```\nAuthedSSEServer wraps SSEServer with required authentication middleware from pkg/security. The middleware reads the session cookie / Authorization header and populates the user context into the request context, making it available to BeforeHandle security hooks. Unauthenticated requests receive 401 before reaching any MCP tool.\n\n```go\nfunc (h *Handler) AuthedStreamableHTTPServer(securityList *security.SecurityList) http.Handler\n```\nAuthedStreamableHTTPServer wraps StreamableHTTPServer with required authentication middleware.\n\n```go\nfunc (h *Handler) BuildCatalog() Catalog\n```\nBuildCatalog snapshots the server's tools and tables. Tables with no allowed operation are left out, exactly as list\\_tables does.\n\n```go\nfunc (h *Handler) EnableOAuthServer(cfg security.OAuthServerConfig, auth *security.DatabaseAuthenticator)\n```\nEnableOAuthServer activates the MCP-standard OAuth2 authorization server on this Handler.\n\nPass a DatabaseAuthenticator to enable direct username/password login — the server acts as its own identity provider and renders a login form at /oauth/authorize. Pass nil to use only external providers registered via RegisterOAuth2Provider.\n\nAfter calling this, HTTPHandler and StreamableHTTPMux serve the full set of RFC-compliant endpoints required by MCP clients alongside the MCP transport:\n\n\tGET  /.well-known/oauth-authorization-server   RFC 8414 — auto-discovery\n\tPOST /oauth/register                            RFC 7591 — dynamic client registration\n\tGET  /oauth/authorize                           OAuth 2.1 + PKCE — start login\n\tPOST /oauth/authorize                           Login form submission (password flow)\n\tPOST /oauth/token                               Bearer token exchange + refresh\n\tGET  /oauth/provider/callback                   External provider redirect target\n\n```go\nfunc (h *Handler) ExportCatalog(path string) error\n```\nExportCatalog writes the catalogue to path. A \".json\" extension writes JSON; anything else writes Markdown. The file is replaced atomically (written to a temp file in the same directory, then renamed) and created with mode 0600. It lists every table the registry allows any operation on, regardless of caller, so keep it out of public directories.\n\n```go\nfunc (h *Handler) GetDatabase() common.Database\n```\nGetDatabase returns the underlying database.\n\n```go\nfunc (h *Handler) HTTPHandler(securityList *security.SecurityList) http.Handler\n```\nHTTPHandler returns a single http.Handler that serves:\n\n  - MCP OAuth2 authorization server endpoints (when EnableOAuthServer has been called)\n  - OAuth2 login + callback routes for every registered provider (legacy cookie flow)\n  - The MCP SSE transport wrapped with required authentication middleware\n\nExample:\n\n\tauth := security.NewGoogleAuthenticator(...)\n\thandler.RegisterOAuth2(auth, cfg)\n\thandler.EnableOAuthServer(security.OAuthServerConfig{Issuer: \"https://api.example.com\"})\n\tsecurity.RegisterSecurityHooks(handler, securityList)\n\thttp.ListenAndServe(\":8080\", handler.HTTPHandler(securityList))\n\n```go\nfunc (h *Handler) Hooks() *HookRegistry\n```\nHooks returns the hook registry.\n\n```go\nfunc (h *Handler) LoadModelDescriptions(path string) (int, error)\n```\nLoadModelDescriptions loads an external JSON map of descriptions keyed by \"schema.entity\" (see modelregistry.LoadModelInfo for the format) and returns how many tables it covered. Loaded entries override the model's own comments.\n\n```go\nfunc (h *Handler) MCPServer() *server.MCPServer\n```\nMCPServer returns the underlying MCP server, e.g. to add custom tools.\n\n```go\nfunc (h *Handler) RegisterFunction(f Function) error\n```\nRegisterFunction makes f callable through the call\\_function meta tool. Only registered functions are callable; there is no way to reach an arbitrary SQL function.\n\n```go\nfunc (h *Handler) RegisterModel(schema, entity string, model interface{}) error\n```\nRegisterModel registers a model. It becomes visible to the fixed meta tools (list\\_tables, select\\_table, ...); no per-model tools are created.\n\n```go\nfunc (h *Handler) RegisterModelWithRules(schema, entity string, model interface{}, rules modelregistry.ModelRules) error\n```\nRegisterModelWithRules registers a model and sets per-entity operation rules (CanRead, CanCreate, CanUpdate, CanDelete, CanPublic\\*, SecurityDisabled). Requires RegisterSecurityHooks to have been called for the rules to be enforced.\n\n```go\nfunc (h *Handler) RegisterOAuth2(auth *security.DatabaseAuthenticator, cfg OAuth2RouteConfig)\n```\nRegisterOAuth2 attaches an OAuth2 provider to the Handler. The login and callback HTTP routes are served by HTTPHandler / StreamableHTTPMux. Call this once per provider before serving requests.\n\nExample:\n\n\tauth := security.NewGoogleAuthenticator(clientID, secret, redirectURL, db)\n\thandler.RegisterOAuth2(auth, resolvemcp.OAuth2RouteConfig{\n\t    ProviderName:       \"google\",\n\t    LoginPath:          \"/auth/google/login\",\n\t    CallbackPath:       \"/auth/google/callback\",\n\t    AfterLoginRedirect: \"/\",\n\t})\n\n```go\nfunc (h *Handler) RegisterOAuth2Provider(auth *security.DatabaseAuthenticator, providerName string)\n```\nRegisterOAuth2Provider adds an external OAuth2 provider to the MCP OAuth2 authorization server. EnableOAuthServer must be called before this. The auth must have been configured with WithOAuth2(providerName, ...) for the given provider name.\n\n```go\nfunc (h *Handler) SSEServer() http.Handler\n```\nSSEServer returns an http.Handler that serves MCP over SSE. Config.BasePath must be set. Config.BaseURL is used when set; if empty it is detected automatically from each incoming request.\n\n```go\nfunc (h *Handler) SetModelDescription(schema, entity string, info modelregistry.ModelInfo) error\n```\nSetModelDescription stores documentation for a registered or soon-to-be-registered table. It returns an error when the handler's registry does not keep model info.\n\n```go\nfunc (h *Handler) SetModelRules(schema, entity string, rules modelregistry.ModelRules) error\n```\nSetModelRules updates the operation rules for an already-registered model. Requires RegisterSecurityHooks to have been called for the rules to be enforced.\n\n```go\nfunc (h *Handler) StreamableHTTPMux(securityList *security.SecurityList) http.Handler\n```\nStreamableHTTPMux returns a single http.Handler that serves:\n\n  - MCP OAuth2 authorization server endpoints (when EnableOAuthServer has been called)\n  - OAuth2 login + callback routes for every registered provider (legacy cookie flow)\n  - The MCP streamable HTTP transport wrapped with required authentication middleware\n\nExample:\n\n\thttp.ListenAndServe(\":8080\", handler.StreamableHTTPMux(securityList))\n\n```go\nfunc (h *Handler) StreamableHTTPServer() http.Handler\n```\nStreamableHTTPServer returns an http.Handler that serves MCP over the streamable HTTP transport. Unlike SSE (which requires two endpoints), streamable HTTP uses a single endpoint for all client-server communication (POST for requests, GET for server-initiated messages). Mount the returned handler at the desired path; the path itself becomes the MCP endpoint.\n\n```go\ntype HookContext struct {\n\tContext      context.Context\n\tHandler      *Handler\n\tSchema       string\n\tEntity       string\n\tModel        interface{}\n\tOptions      common.RequestOptions\n\tOperation    string\n\tID           string\n\tData         interface{}\n\tResult       interface{}\n\tError        error\n\tQuery        common.SelectQuery\n\tAbort        bool\n\tAbortMessage string\n\tAbortCode    int\n\tTx           common.Database\n}\n```\nHookContext contains all the data available to a hook\n\n```go\nfunc (c *HookContext) SetTx(tx common.Database)\n```\nSetTx points the context at the transaction in use (common.TxContext).\n\n```go\ntype HookFunc func(*HookContext) error\n```\nHookFunc is the signature for hook functions\n\n```go\ntype HookRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\nHookRegistry manages all registered hooks\n\n```go\nfunc NewHookRegistry() *HookRegistry\n```\n\n```go\nfunc (r *HookRegistry) Clear(hookType HookType)\n```\n\n```go\nfunc (r *HookRegistry) ClearAll()\n```\n\n```go\nfunc (r *HookRegistry) Execute(hookType HookType, ctx *HookContext) error\n```\n\n```go\nfunc (r *HookRegistry) HasHooks(hookType HookType) bool\n```\n\n```go\nfunc (r *HookRegistry) Register(hookType HookType, hook HookFunc)\n```\n\n```go\nfunc (r *HookRegistry) RegisterMultiple(hookTypes []HookType, hook HookFunc)\n```\n\n```go\ntype HookType string\n```\nHookType defines the type of hook to execute\n\n```go\nconst (\n\t// BeforeHandle fires after model resolution, before operation dispatch.\n\tBeforeHandle HookType = \"before_handle\"\n\n\tBeforeRead HookType = \"before_read\"\n\tAfterRead  HookType = \"after_read\"\n\n\tBeforeCreate HookType = \"before_create\"\n\tAfterCreate  HookType = \"after_create\"\n\n\t// BeforeScan fires on update and delete, with hookCtx.Query set to the select that loads the\n\t// target row. Hooks that narrow the query (row security) run here; a row the query does\n\t// not return is reported as not found and never written.\n\tBeforeScan HookType = \"before_scan\"\n\n\tBeforeUpdate HookType = \"before_update\"\n\tAfterUpdate  HookType = \"after_update\"\n\n\tBeforeDelete HookType = \"before_delete\"\n\tAfterDelete  HookType = \"after_delete\"\n\n\t// BeforeCall and AfterCall fire inside the transaction of a call_function call.\n\t// hookCtx.Entity is the function name, Data the validated arguments (BeforeCall may\n\t// replace them) and Result the function's result (AfterCall).\n\tBeforeCall HookType = \"before_call\"\n\tAfterCall  HookType = \"after_call\"\n\n\t// OnTxBegin fires once, first, inside every transaction the handler opens\n\t// (including the second short transaction for post-commit work). hookCtx.Tx is\n\t// the transaction; use it to stamp transaction-local state such as RLS\n\t// settings. An error or abort rolls the transaction back.\n\tOnTxBegin HookType = common.TxHookName\n)\n```\n\n```go\ntype OAuth2RouteConfig struct {\n\t// ProviderName is the OAuth2 provider name as registered with WithOAuth2()\n\t// (e.g. \"google\", \"github\", \"microsoft\").\n\tProviderName string\n\n\t// LoginPath is the HTTP path that redirects the browser to the OAuth2 provider\n\t// (e.g. \"/auth/google/login\").\n\tLoginPath string\n\n\t// CallbackPath is the HTTP path that the OAuth2 provider redirects back to\n\t// (e.g. \"/auth/google/callback\"). Must match the RedirectURL in OAuth2Config.\n\tCallbackPath string\n\n\t// AfterLoginRedirect is the URL to redirect the browser to after a successful\n\t// login. When empty the LoginResponse JSON is written directly to the response.\n\tAfterLoginRedirect string\n\n\t// CookieOptions customises the session cookie written on successful login.\n\t// Defaults to HttpOnly, Secure, SameSite=Lax when nil.\n\tCookieOptions *security.SessionCookieOptions\n}\n```\nOAuth2RouteConfig configures the OAuth2 HTTP endpoints for a single provider.\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/resolvemcp","name":"resolvemcp","synopsis":"Package resolvemcp exposes registered database models as Model Context Protocol (MCP) tools over HTTP (SSE and streamable HTTP), so an AI agent can discover, read and change data without a tool per table.","isRedistributable":true}
