rest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(dsn string) (core.Source, error)

New creates a new REST API adapter. The dsn format is: rest://baseURL?apiKey=xxx&specURL=xxx&timeout=30 Headers can be provided as: header_X-Custom=value

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) Close

func (r *RESTAdapter) Close(_ context.Context) error

func (*RESTAdapter) Connect

func (r *RESTAdapter) Connect(ctx context.Context) error

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

Jump to

Keyboard shortcuts

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