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
- func BindMCPRoutes(app core.App, e *echo.Echo, version string)
- type AuthInfo
- type Capabilities
- type Content
- type InitializeParams
- type InitializeResult
- type JSONRPCRequest
- type JSONRPCResponse
- type RPCError
- type Resource
- type ResourceContent
- type ResourceHandler
- type ResourceReadParams
- type ResourceReadResult
- type ResourcesCapability
- type SSEClient
- type SSETransport
- type Server
- type ServerInfo
- type StdioTransport
- type Tool
- type ToolCallParams
- type ToolCallResult
- type ToolHandler
- type ToolsCapability
Constants ¶
const ( ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 )
Standard JSON-RPC error codes
Variables ¶
This section is empty.
Functions ¶
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
type Capabilities ¶
type Capabilities struct {
Tools *ToolsCapability `json:"tools,omitempty"`
Resources *ResourcesCapability `json:"resources,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 ResourceContent ¶
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 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 (*Server) Authenticate ¶
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 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 ToolCallParams ¶
type ToolCallResult ¶
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"`
}