server

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package server provides the MCP server implementation for the ProjectMemory service.

Package server provides the MCP server implementation for the ProjectMemory service.

Index

Constants

View Source
const (
	// ErrorCodeInvalidRequest indicates the client sent an invalid request
	ErrorCodeInvalidRequest = "INVALID_REQUEST"

	// ErrorCodeInternalError indicates an internal server error
	ErrorCodeInternalError = "INTERNAL_ERROR"

	// ErrorCodeAuthenticationError indicates an authentication failure
	ErrorCodeAuthenticationError = "AUTHENTICATION_ERROR"

	// ErrorCodeResourceNotFound indicates a requested resource was not found
	ErrorCodeResourceNotFound = "RESOURCE_NOT_FOUND"

	// ErrorCodeBadGateway indicates a failure in an upstream service
	ErrorCodeBadGateway = "BAD_GATEWAY"
)

Common error codes

View Source
const (
	StatusCodeValidationError = "VALIDATION_ERROR"
	StatusCodePermissionError = "PERMISSION_ERROR"
	StatusCodeDatabaseError   = "DATABASE_ERROR"
	StatusCodeNetworkError    = "NETWORK_ERROR"
	StatusCodeInternalError   = "INTERNAL_ERROR"
	StatusCodeConfigError     = "CONFIG_ERROR"
	StatusCodeExternalError   = "EXTERNAL_ERROR"
	StatusCodeUnknownError    = "UNKNOWN_ERROR"
)

Error response codes

Variables

View Source
var (
	ErrServerNotInitialized = errors.New("server not initialized")
	ErrMissingDependencies  = errors.New("one or more required dependencies are nil")
)

Common server error types

Functions

func HandleBadGateway

func HandleBadGateway(w http.ResponseWriter, message string, err error)

HandleBadGateway handles 502 Bad Gateway errors

func HandleBadRequest

func HandleBadRequest(w http.ResponseWriter, message string, err error)

HandleBadRequest handles 400 Bad Request errors

func HandleError

func HandleError(w http.ResponseWriter, err error)

HandleError handles any error, inspecting its type to determine the appropriate HTTP response

func HandleInternalError

func HandleInternalError(w http.ResponseWriter, message string, err error)

HandleInternalError handles 500 Internal Server Error errors

func HandleNotFound

func HandleNotFound(w http.ResponseWriter, message string, err error)

HandleNotFound handles 404 Not Found errors

func HandleUnauthorized

func HandleUnauthorized(w http.ResponseWriter, message string, err error)

HandleUnauthorized handles 401 Unauthorized errors

func WriteError added in v0.1.4

func WriteError(w http.ResponseWriter, err error, status int)

WriteError writes an error response to the HTTP response writer

Types

type ContextToolServer

type ContextToolServer interface {
	// Initialize initializes the server with dependencies and configurations.
	Initialize() error

	// Start starts the MCP server on the specified transport.
	Start() error

	// Stop gracefully shuts down the MCP server.
	Stop() error
}

ContextToolServer defines the interface for the MCP server that handles context-related tool calls from MCP clients.

type ErrorResponse

type ErrorResponse struct {
	Status     string                 `json:"status"`
	Code       string                 `json:"code"`
	Message    string                 `json:"message"`
	Details    map[string]interface{} `json:"details,omitempty"`
	StackTrace string                 `json:"stack_trace,omitempty"`
}

ErrorResponse represents the structure of error responses sent by the API

type ErrorWithStatus

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

ErrorWithStatus creates an error with an HTTP status code

func NewErrorWithStatus

func NewErrorWithStatus(err error, status int, code, message string) *ErrorWithStatus

NewErrorWithStatus creates a new error with HTTP status code

func (*ErrorWithStatus) Error

func (e *ErrorWithStatus) Error() string

Error returns the error message

func (*ErrorWithStatus) ErrorCode

func (e *ErrorWithStatus) ErrorCode() string

ErrorCode returns the application error code

func (*ErrorWithStatus) Message

func (e *ErrorWithStatus) Message() string

Message returns the client-friendly message

func (*ErrorWithStatus) StatusCode

func (e *ErrorWithStatus) StatusCode() int

StatusCode returns the HTTP status code

func (*ErrorWithStatus) Unwrap

func (e *ErrorWithStatus) Unwrap() error

Unwrap returns the underlying error

type MCPContextToolServer

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

MCPContextToolServer implements the ContextToolServer interface for handling MCP tool calls related to context storage and retrieval.

func NewContextToolServer

func NewContextToolServer(store contextstore.ContextStore, summarizer summarizer.Summarizer, embedder vector.Embedder) *MCPContextToolServer

NewContextToolServer creates a new MCPContextToolServer instance.

func (*MCPContextToolServer) Initialize

func (s *MCPContextToolServer) Initialize() error

Initialize initializes the server with dependencies and configurations.

func (*MCPContextToolServer) Start

func (s *MCPContextToolServer) Start() error

Start starts the MCP server on the specified transport.

func (*MCPContextToolServer) Stop

func (s *MCPContextToolServer) Stop() error

Stop gracefully shuts down the MCP server.

Jump to

Keyboard shortcuts

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