mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-08 22:36:28 +00:00
Tests / Integration Tests (push) Skipped
Build , Vet Test, and Lint / Build (push) Successful in 1m33s
Tests / Unit Tests (push) Successful in 2m1s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 2m36s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 2m38s
Build , Vet Test, and Lint / Lint Code (push) Successful in 2m49s
Tests / Race Detector (push) Successful in 4m31s
BREAKING CHANGE: Config.ReadOnly is now a *bool and unset means read-only. Use ReadOnly: resolvemcp.Bool(false) to enable insert/update/delete, annotations and function calls. Adds the Bool helper and updates docs.
51 lines
2.3 KiB
Go
51 lines
2.3 KiB
Go
// 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.
|
|
//
|
|
// # How an agent uses it
|
|
//
|
|
// The tool set is fixed and does not grow with the models:
|
|
//
|
|
// list_tables tables the caller may use, their description and allowed operations
|
|
// describe_table columns, types, keys, relations, writable fields, limits
|
|
// select_table read rows: filters, sort, columns, preloads, paging, cursors
|
|
// insert_into_table / update_table / delete_from_table
|
|
// writes; filter-based writes are previewed (dry_run) and need the
|
|
// confirm_token from the preview
|
|
// list_functions / call_function registered stored functions
|
|
// resolvespec_annotate optional free-text notes (Config.EnableAnnotations)
|
|
//
|
|
// The same guide is sent to MCP clients as the server instructions.
|
|
//
|
|
// The server is read-only by default (Config.ReadOnly nil means on); set
|
|
// ReadOnly: resolvemcp.Bool(false) to enable the write tools.
|
|
//
|
|
// # Setting it up
|
|
//
|
|
// handler := resolvemcp.NewHandlerWithGORM(db, resolvemcp.Config{BaseURL: "http://localhost:8080"})
|
|
// handler.RegisterModel("public", "users", &User{})
|
|
//
|
|
// r := mux.NewRouter()
|
|
// resolvemcp.SetupMuxRoutes(r, handler, securityList) // requires an authenticated caller
|
|
//
|
|
// # Describing the API for agents
|
|
//
|
|
// Models 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.
|
|
//
|
|
// ExportCatalog 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:
|
|
//
|
|
// handler.ExportCatalog("docs/mcp-catalog.md")
|
|
//
|
|
// # Security
|
|
//
|
|
// Routes 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.
|
|
package resolvemcp
|