Documentation
¶
Overview ¶
Package rest provides a REST API adapter for CoreMCP. It can discover API endpoints from OpenAPI/Swagger specs and expose them as MCP tools.
Index ¶
- func New(dsn string) (core.Source, error)
- type Endpoint
- type EndpointParam
- type OpenAPIInfo
- type OpenAPIOperation
- type OpenAPIParameter
- type OpenAPIPath
- type OpenAPIRequestBody
- type OpenAPISpec
- type RESTAdapter
- func (r *RESTAdapter) Close(_ context.Context) error
- func (r *RESTAdapter) Connect(ctx context.Context) error
- func (r *RESTAdapter) ExecuteProcedure(ctx context.Context, name string, params map[string]string) (*core.QueryResult, error)
- func (r *RESTAdapter) ExecuteQuery(_ context.Context, _ string, _ ...any) (*core.QueryResult, error)
- func (r *RESTAdapter) GetAPIDescription() string
- func (r *RESTAdapter) GetEndpoints() []Endpoint
- func (r *RESTAdapter) GetProcedures(_ context.Context) ([]core.StoredProcedure, error)
- func (r *RESTAdapter) GetSchema(ctx context.Context) ([]core.TableSchema, error)
- func (r *RESTAdapter) GetViews(_ context.Context) ([]core.ViewSchema, error)
- func (r *RESTAdapter) Name() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Endpoint ¶
type Endpoint struct {
Path string
Method string
OperationID string
Summary string
Description string
Parameters []EndpointParam
HasBody bool
}
Endpoint represents a discovered REST endpoint that can be exposed as an MCP tool.
type EndpointParam ¶
type EndpointParam struct {
Name string
In string // query, path, header
Description string
Required bool
Type string
Enum []string
}
EndpointParam represents a parameter for an endpoint.
type OpenAPIInfo ¶
type OpenAPIInfo struct {
Title string `json:"title"`
Description string `json:"description"`
Version string `json:"version"`
}
OpenAPIInfo contains API metadata.
type OpenAPIOperation ¶
type OpenAPIOperation struct {
Summary string `json:"summary"`
Description string `json:"description"`
OperationID string `json:"operationId"`
Parameters []OpenAPIParameter `json:"parameters"`
RequestBody *OpenAPIRequestBody `json:"requestBody"`
}
OpenAPIOperation represents a single endpoint operation.
type OpenAPIParameter ¶
type OpenAPIParameter struct {
Name string `json:"name"`
In string `json:"in"` // query, path, header
Description string `json:"description"`
Required bool `json:"required"`
Schema *struct {
Type string `json:"type"`
Enum []string `json:"enum"`
Format string `json:"format"`
} `json:"schema"`
}
OpenAPIParameter represents a path, query, or header parameter.
type OpenAPIPath ¶
type OpenAPIPath map[string]OpenAPIOperation
OpenAPIPath represents the operations available on a path.
type OpenAPIRequestBody ¶
type OpenAPIRequestBody struct {
Content map[string]struct {
Schema json.RawMessage `json:"schema"`
} `json:"content"`
}
OpenAPIRequestBody represents the request body structure.
type OpenAPISpec ¶
type OpenAPISpec struct {
OpenAPI string `json:"openapi"`
Info OpenAPIInfo `json:"info"`
Paths map[string]OpenAPIPath `json:"paths"`
}
OpenAPISpec represents a minimal OpenAPI 3.0 structure for endpoint discovery.
type RESTAdapter ¶
type RESTAdapter struct {
// contains filtered or unexported fields
}
RESTAdapter provides access to REST APIs with optional OpenAPI discovery.
func (*RESTAdapter) ExecuteProcedure ¶
func (r *RESTAdapter) ExecuteProcedure(ctx context.Context, name string, params map[string]string) (*core.QueryResult, error)
ExecuteProcedure executes a REST API call by operation ID.
func (*RESTAdapter) ExecuteQuery ¶
func (r *RESTAdapter) ExecuteQuery(_ context.Context, _ string, _ ...any) (*core.QueryResult, error)
ExecuteQuery is not supported for REST; use ExecuteProcedure instead.
func (*RESTAdapter) GetAPIDescription ¶
func (r *RESTAdapter) GetAPIDescription() string
GetAPIDescription returns a description of the API for AI context.
func (*RESTAdapter) GetEndpoints ¶
func (r *RESTAdapter) GetEndpoints() []Endpoint
GetEndpoints returns all discovered endpoints in a stable sorted order. Endpoints without an operationId are skipped — they cannot be addressed by name.
func (*RESTAdapter) GetProcedures ¶
func (r *RESTAdapter) GetProcedures(_ context.Context) ([]core.StoredProcedure, error)
func (*RESTAdapter) GetSchema ¶
func (r *RESTAdapter) GetSchema(ctx context.Context) ([]core.TableSchema, error)
GetSchema returns the discovered API endpoints as "tables" for schema context. Each column's description includes the parameter location (path/query/header) so the AI can reconstruct the correct call.
func (*RESTAdapter) GetViews ¶
func (r *RESTAdapter) GetViews(_ context.Context) ([]core.ViewSchema, error)
func (*RESTAdapter) Name ¶
func (r *RESTAdapter) Name() string