mcp

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package mcp implements the Model Context Protocol server for PostgreBase. MCP is a JSON-RPC 2.0 based protocol that allows AI models to interact with external tools and data sources.

Index

Constants

View Source
const (
	ParseError     = -32700
	InvalidRequest = -32600
	MethodNotFound = -32601
	InvalidParams  = -32602
	InternalError  = -32603
)

Standard JSON-RPC error codes

Variables

This section is empty.

Functions

func BindMCPRoutes

func BindMCPRoutes(app core.App, e *echo.Echo, version string)

BindMCPRoutes registers MCP routes on the echo instance

Types

type AuthInfo

type AuthInfo struct {
	Admin      *models.Admin
	Record     *models.Record
	IsMCPToken bool // true if authenticated via MCP-specific token
	TokenName  string
}

AuthInfo holds the authenticated user information

func AuthenticateStdio

func AuthenticateStdio(s *Server, token string) (*AuthInfo, error)

AuthenticateStdio validates the token for stdio mode

type Capabilities

type Capabilities struct {
	Tools     *ToolsCapability     `json:"tools,omitempty"`
	Resources *ResourcesCapability `json:"resources,omitempty"`
}

type Content

type Content struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

type InitializeParams

type InitializeParams struct {
	ProtocolVersion string      `json:"protocolVersion"`
	Capabilities    interface{} `json:"capabilities"`
	ClientInfo      interface{} `json:"clientInfo"`
}

MCP protocol structures

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string       `json:"protocolVersion"`
	Capabilities    Capabilities `json:"capabilities"`
	ServerInfo      ServerInfo   `json:"serverInfo"`
}

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

JSON-RPC 2.0 structures

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id,omitempty"`
	Result  interface{} `json:"result,omitempty"`
	Error   *RPCError   `json:"error,omitempty"`
}

type RPCError

type RPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type Resource

type Resource struct {
	URI         string `json:"uri"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	MimeType    string `json:"mimeType,omitempty"`
}

type ResourceContent

type ResourceContent struct {
	URI      string `json:"uri"`
	MimeType string `json:"mimeType,omitempty"`
	Text     string `json:"text,omitempty"`
}

type ResourceHandler

type ResourceHandler func(uri string) (*ResourceReadResult, error)

ResourceHandler is a function that reads a resource

type ResourceReadParams

type ResourceReadParams struct {
	URI string `json:"uri"`
}

type ResourceReadResult

type ResourceReadResult struct {
	Contents []ResourceContent `json:"contents"`
}

type ResourcesCapability

type ResourcesCapability struct {
	Subscribe   bool `json:"subscribe"`
	ListChanged bool `json:"listChanged"`
}

type SSEClient

type SSEClient struct {
	ID       string
	Messages chan []byte
	Done     chan bool
}

SSEClient represents a connected SSE client

type SSETransport

type SSETransport struct {
	// contains filtered or unexported fields
}

SSETransport handles SSE-based MCP transport over HTTP

func NewSSETransport

func NewSSETransport(app core.App, version string) *SSETransport

NewSSETransport creates a new SSE transport

func (*SSETransport) HandleMessage

func (t *SSETransport) HandleMessage(c echo.Context) error

HandleMessage handles incoming JSON-RPC messages (POST /api/mcp/message)

func (*SSETransport) HandleSSE

func (t *SSETransport) HandleSSE(c echo.Context) error

HandleSSE handles the SSE connection endpoint (GET /api/mcp/sse)

func (*SSETransport) HandleStreamableHTTP

func (t *SSETransport) HandleStreamableHTTP(c echo.Context) error

HandleStreamableHTTP handles the streamable HTTP transport (POST /api/mcp/stream) This is a simplified version that combines request/response in a single HTTP call

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the MCP server

func NewServer

func NewServer(app core.App, version string) *Server

NewServer creates a new MCP server instance

func (*Server) Authenticate

func (s *Server) Authenticate(token string) (*AuthInfo, error)

Authenticate validates the token and returns auth info

func (*Server) HandleRequest

func (s *Server) HandleRequest(req *JSONRPCRequest) *JSONRPCResponse

HandleRequest processes a JSON-RPC request and returns a response

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type StdioTransport

type StdioTransport struct {
	// contains filtered or unexported fields
}

StdioTransport handles stdio-based MCP transport

func NewStdioTransport

func NewStdioTransport(app core.App, version string) *StdioTransport

NewStdioTransport creates a new stdio transport

func (*StdioTransport) Run

func (t *StdioTransport) Run(token string) error

Run starts the stdio transport loop

type Tool

type Tool struct {
	Name        string      `json:"name"`
	Description string      `json:"description,omitempty"`
	InputSchema interface{} `json:"inputSchema"`
}

type ToolCallParams

type ToolCallParams struct {
	Name      string                 `json:"name"`
	Arguments map[string]interface{} `json:"arguments,omitempty"`
}

type ToolCallResult

type ToolCallResult struct {
	Content []Content `json:"content"`
	IsError bool      `json:"isError,omitempty"`
}

type ToolHandler

type ToolHandler func(args map[string]interface{}) (*ToolCallResult, error)

ToolHandler is a function that handles a tool call

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool `json:"listChanged"`
}

Jump to

Keyboard shortcuts

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