mcp

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const LatestSupportedMCPVersion = MCPProtocolVersion20250618

LatestSupportedMCPVersion defines the latest supported version of Model Context Protocol (MCP)

View Source
const MCPProtocolVersionHeaderName = "MCP-Protocol-Version"

MCPProtocolVersionHeaderName defines the HTTP header name for the MCP protocol version

View Source
const ToolResultStructuredContentMinVersion = MCPProtocolVersion20250618

ToolResultStructuredContentMinVersion defines the minimum version of structured content supported in tool results

Variables

View Source
var (
	Container = &MCPContainer{}
)

Initialize a mcp handler container singleton instance

View Source
var MCPAddTransactionToolHandler = &mcpAddTransactionToolHandler{}
View Source
var MCPQueryAllAccountsBalanceToolHandler = &mcpQueryAllAccountsBalanceToolHandler{}
View Source
var MCPQueryAllAccountsToolHandler = &mcpQueryAllAccountsToolHandler{}
View Source
var MCPQueryAllTransactionCategoriesToolHandler = &mcpQueryAllTransactionCategoriesToolHandler{}
View Source
var MCPQueryAllTransactionTagsToolHandler = &mcpQueryAllTransactionTagsToolHandler{}
View Source
var MCPQueryLatestExchangeRatesToolHandler = &mcpQueryLatestExchangeRatesToolHandler{}
View Source
var MCPQueryTransactionsToolHandler = &mcpQueryTransactionsToolHandler{}

SupportedMCPVersion defines a map of supported MCP versions

Functions

func InitializeMCPHandlers

func InitializeMCPHandlers(config *settings.Config) error

InitializeMCPHandlers initializes the all mcp handlers according to the config

Types

type MCPAccountBalanceInfo added in v1.2.0

type MCPAccountBalanceInfo struct {
	Name               string `json:"name" jsonschema_description:"Account name"`
	Type               string `json:"type" jsonschema:"enum=asset,enum=liability" jsonschema_description:"Account type (asset or liability)"`
	Balance            string `json:"balance,omitempty" jsonschema_description:"Current balance of the account"`
	OutstandingBalance string `` /* 142-byte string literal not displayed */
	Currency           string `json:"currency" jsonschema_description:"Currency code of the account (e.g. USD, EUR)"`
}

MCPAccountBalanceInfo defines the structure of account balance information

type MCPAddTransactionRequest

type MCPAddTransactionRequest struct {
	Type                   string   `` /* 133-byte string literal not displayed */
	Time                   string   `` /* 130-byte string literal not displayed */
	SecondaryCategoryName  string   `json:"category_name" jsonschema_description:"Secondary category name for the transaction"`
	AccountName            string   `json:"account_name" jsonschema_description:"Account name for the transaction"`
	Amount                 string   `json:"amount" jsonschema_description:"Transaction amount"`
	DestinationAccountName string   `` /* 128-byte string literal not displayed */
	DestinationAmount      string   `json:"destination_amount,omitempty" jsonschema_description:"Destination amount for transfer transactions (optional)"`
	Tags                   []string `` /* 127-byte string literal not displayed */
	Comment                string   `json:"comment,omitempty" jsonschema_description:"Transaction description"`
	DryRun                 bool     `json:"dry_run,omitempty" jsonschema_description:"If true, the transaction will not be saved, only validated (optional)"`
}

MCPAddTransactionRequest represents all parameters of the add transaction request

type MCPAddTransactionResponse

type MCPAddTransactionResponse struct {
	Success                   bool   `json:"success" jsonschema_description:"Indicates whether this operation is successful"`
	DryRun                    bool   `` /* 128-byte string literal not displayed */
	AccountBalance            string `` /* 138-byte string literal not displayed */
	DestinationAccountBalance string `` /* 195-byte string literal not displayed */
}

MCPAddTransactionResponse represents the response structure for add transaction

type MCPAllQueryTransactionTagsResponse

type MCPAllQueryTransactionTagsResponse struct {
	Tags []string `json:"tags" jsonschema_description:"List of transaction tags"`
}

MCPAllQueryTransactionTagsResponse represents the response structure for querying transaction tags

type MCPAudioContent

type MCPAudioContent struct {
	Type     string `json:"type"`
	MimeType string `json:"mimeType"`
	Data     string `json:"data"` // Base64 encoded content for binary data
}

MCPAudioContent defines the audio content structure used in MCP

func NewMCPAudioContent

func NewMCPAudioContent(data []byte, mimeType string) *MCPAudioContent

NewMCPAudioContent creates a new instance of MCPAudioContent with the given data and MIME type

type MCPAvailableServices

type MCPAvailableServices interface {
	GetTransactionService() *services.TransactionService
	GetTransactionCategoryService() *services.TransactionCategoryService
	GetTransactionTagService() *services.TransactionTagService
	GetAccountService() *services.AccountService
	GetUserService() *services.UserService
}

MCPAvailableServices holds the services available for MCP tools

type MCPBlobResourceContents

type MCPBlobResourceContents struct {
	URI      string `json:"uri"`
	Blob     string `json:"blob"` // Base64 encoded content of the resource
	MimeType string `json:"mimeType,omitempty"`
}

MCPBlobResourceContents defines the blob contents structure of a resource in the MCP

type MCPCallToolRequest

type MCPCallToolRequest struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

MCPCallToolRequest defines the request structure for listing tools in the MCP

type MCPCallToolResponse

type MCPCallToolResponse[T MCPTextContent | MCPImageContent | MCPAudioContent | MCPResourceLink | MCPEmbeddedResource] struct {
	Content           []*T `json:"content"`
	StructuredContent any  `json:"structuredContent,omitempty"`
	IsError           bool `json:"isError,omitempty"`
}

MCPCallToolResponse defines the response structure for calling a tool in the MCP

type MCPCapabilities

type MCPCapabilities struct {
	Resources *MCPResourceCapabilities `json:"resources,omitempty"`
	Tools     *MCPToolCapabilities     `json:"tools,omitempty"`
	Prompts   *MCPPromptCapabilities   `json:"prompts,omitempty"`
}

MCPCapabilities defines the capabilities of the MCP server

type MCPContainer

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

MCPContainer contains the all mcp handlers

func (*MCPContainer) GetMCPTools

func (c *MCPContainer) GetMCPTools() []*MCPTool

GetMCPTools returns the registered MCP tools

func (*MCPContainer) HandleTool

func (c *MCPContainer) HandleTool(ctx *core.WebContext, callToolReq *MCPCallToolRequest, user *models.User, currentConfig *settings.Config, services MCPAvailableServices) (any, error)

HandleTool returns the result of the MCP tool handler based on the tool name

type MCPEmbeddedResource

type MCPEmbeddedResource struct {
	Type     string `json:"type"`
	Resource any    `json:"resource"`
}

MCPEmbeddedResource defines the embedded resource content structure used in MCP

func NewMCPEmbeddedResource

func NewMCPEmbeddedResource[T MCPTextResourceContents | MCPBlobResourceContents](resource *T) *MCPEmbeddedResource

NewMCPEmbeddedResource creates a new instance of MCPEmbeddedResource with the given resource

type MCPImageContent

type MCPImageContent struct {
	Type     string `json:"type"`
	MimeType string `json:"mimeType"`
	Data     string `json:"data"` // Base64 encoded content for binary data
}

MCPImageContent defines the image content structure used in MCP

func NewMCPImageContent

func NewMCPImageContent(data []byte, mimeType string) *MCPImageContent

NewMCPImageContent creates a new instance of MCPImageContent with the given data and MIME type

type MCPImplementation

type MCPImplementation struct {
	Name    string `json:"name"`
	Title   string `json:"title,omitempty"`
	Version string `json:"version"`
}

MCPImplementation defines the client/server information structure sent in the MCP initialization request/response

type MCPInitializeRequest

type MCPInitializeRequest struct {
	ProtocolVersion string             `json:"protocolVersion"`
	ClientInfo      *MCPImplementation `json:"clientInfo"`
}

MCPInitializeRequest defines the request structure for initializing the MCP connection

type MCPInitializeResponse

type MCPInitializeResponse struct {
	ProtocolVersion string             `json:"protocolVersion"`
	Capabilities    *MCPCapabilities   `json:"capabilities"`
	ServerInfo      *MCPImplementation `json:"serverInfo"`
}

MCPInitializeResponse defines the response structure for the MCP initialization request

type MCPListResourcesResponse

type MCPListResourcesResponse struct {
	Resources  []*MCPResource `json:"resources"`
	NextCursor string         `json:"nextCursor,omitempty"`
}

MCPListResourcesResponse defines the response structure for listing resources in the MCP

type MCPListToolsResponse

type MCPListToolsResponse struct {
	Tools      []*MCPTool `json:"tools"`
	NextCursor string     `json:"nextCursor,omitempty"`
}

MCPListToolsResponse defines the response structure for listing tools in the MCP

type MCPPromptCapabilities

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

MCPPromptCapabilities defines the capabilities related to prompts in the MCP

type MCPProtocolVersion

type MCPProtocolVersion string

MCPProtocolVersion defines the type for Model Context Protocol (MCP) version

const (
	MCPProtocolVersion20250618 MCPProtocolVersion = "2025-06-18"
	MCPProtocolVersion20250326 MCPProtocolVersion = "2025-03-26"
	MCPProtocolVersion20241105 MCPProtocolVersion = "2024-11-05"
)

MCP Protocol Versions

type MCPQueryAllAccountsBalanceResponse added in v1.2.0

type MCPQueryAllAccountsBalanceResponse struct {
	CashAccounts                 []*MCPAccountBalanceInfo `json:"cashAccounts,omitempty" jsonschema_description:"List of cash account balances"`
	CheckingAccounts             []*MCPAccountBalanceInfo `json:"checkingAccounts,omitempty" jsonschema_description:"List of checking account balances"`
	SavingsAccounts              []*MCPAccountBalanceInfo `json:"savingsAccounts,omitempty" jsonschema_description:"List of savings account balances"`
	CreditCardAccounts           []*MCPAccountBalanceInfo `json:"creditCardAccounts,omitempty" jsonschema_description:"List of credit card account outstanding balances"`
	VirtualAccounts              []*MCPAccountBalanceInfo `json:"virtualAccounts,omitempty" jsonschema_description:"List of virtual account balances"`
	DebtAccounts                 []*MCPAccountBalanceInfo `json:"debtAccounts,omitempty" jsonschema_description:"List of debt account outstanding balances"`
	ReceivableAccounts           []*MCPAccountBalanceInfo `json:"receivableAccounts,omitempty" jsonschema_description:"List of receivable account balances"`
	CertificateOfDepositAccounts []*MCPAccountBalanceInfo `json:"certificateOfDepositAccounts,omitempty" jsonschema_description:"List of certificate of deposit account balances"`
	InvestmentAccounts           []*MCPAccountBalanceInfo `json:"investmentAccounts,omitempty" jsonschema_description:"List of investment account balances"`
}

MCPQueryAllAccountsBalanceResponse represents the response structure for querying accounts balance

type MCPQueryAllAccountsResponse

type MCPQueryAllAccountsResponse struct {
	CashAccounts                 []string `json:"cashAccounts,omitempty" jsonschema_description:"List of cash account names"`
	CheckingAccounts             []string `json:"checkingAccounts,omitempty" jsonschema_description:"List of checking account names"`
	SavingsAccounts              []string `json:"savingsAccounts,omitempty" jsonschema_description:"List of savings account names"`
	CreditCardAccounts           []string `json:"creditCardAccounts,omitempty" jsonschema_description:"List of credit card account names"`
	VirtualAccounts              []string `json:"virtualAccounts,omitempty" jsonschema_description:"List of virtual account names"`
	DebtAccounts                 []string `json:"debtAccounts,omitempty" jsonschema_description:"List of debt account names"`
	ReceivableAccounts           []string `json:"receivableAccounts,omitempty" jsonschema_description:"List of receivable account names"`
	CertificateOfDepositAccounts []string `json:"certificateOfDepositAccounts,omitempty" jsonschema_description:"List of certificate of deposit account names"`
	InvestmentAccounts           []string `json:"investmentAccounts,omitempty" jsonschema_description:"List of investment account names"`
}

MCPQueryAllAccountsResponse represents the response structure for querying accounts

type MCPQueryAllTransactionCategoriesResponse

type MCPQueryAllTransactionCategoriesResponse struct {
	IncomeCategories   map[string][]string `` /* 167-byte string literal not displayed */
	ExpenseCategories  map[string][]string `` /* 169-byte string literal not displayed */
	TransferCategories map[string][]string `` /* 171-byte string literal not displayed */
}

MCPQueryAllTransactionCategoriesResponse represents the response structure for querying transaction categories

type MCPQueryExchangeRateInfo

type MCPQueryExchangeRateInfo struct {
	Currency string `json:"currency" jsonschema_description:"Currency code (e.g. USD)"`
	Rate     string `json:"rate_to_base" jsonschema_description:"The amount of the base currency that can be obtained for 1 unit of this currency"`
}

MCPQueryExchangeRateInfo defines the structure of exchange rate information for a specific currency

type MCPQueryExchangeRatesRequest

type MCPQueryExchangeRatesRequest struct {
	Currencies string `json:"currencies" jsonschema_description:"Comma-separated list of currencies to query exchange rates for (e.g. USD,CNY,EUR)"`
}

MCPQueryExchangeRatesRequest represents all parameters of the query exchange rates request

type MCPQueryExchangeRatesResponse

type MCPQueryExchangeRatesResponse struct {
	BaseCurrency string                      `json:"base_currency" jsonschema_description:"Base currency code (e.g. USD)"`
	UpdateTime   string                      `` /* 131-byte string literal not displayed */
	Rates        []*MCPQueryExchangeRateInfo `json:"rates" jsonschema_description:"Exchange rates for the specified currencies"`
}

MCPQueryExchangeRatesResponse represents the response structure for querying exchange rates

type MCPQueryTransactionsRequest

type MCPQueryTransactionsRequest struct {
	StartTime             string `` /* 144-byte string literal not displayed */
	EndTime               string `` /* 143-byte string literal not displayed */
	Type                  string `` /* 167-byte string literal not displayed */
	SecondaryCategoryName string `` /* 127-byte string literal not displayed */
	AccountName           string `json:"account_name,omitempty" jsonschema_description:"Account name to filter transactions by (optional)"`
	Keyword               string `json:"keyword,omitempty" jsonschema_description:"Keyword to search in transaction description (optional)"`
	Count                 int32  `json:"count,omitempty" jsonschema:"default=100" jsonschema_description:"Maximum number of results to return (default: 100)"`
	Page                  int32  `json:"page,omitempty" jsonschema:"default=1" jsonschema_description:"Page number for pagination (default: 1)"`
	ResponseFields        string `` /* 235-byte string literal not displayed */
}

MCPQueryTransactionsRequest represents all parameters of the query transactions request

type MCPQueryTransactionsResponse

type MCPQueryTransactionsResponse struct {
	TotalCount   int64                 `json:"total_count" jsonschema_description:"Total number of transactions matching the query"`
	CurrentPage  int32                 `json:"current_page" jsonschema_description:"Current page number of the results"`
	TotalPage    int32                 `` /* 131-byte string literal not displayed */
	Transactions []*MCPTransactionInfo `json:"transactions" jsonschema_description:"List of transactions matching the query"`
}

MCPQueryTransactionsResponse represents the response structure for querying transactions

type MCPReadResourceRequest

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

MCPReadResourceRequest defines the request structure for reading a resource in the MCP

type MCPReadResourceResponse

type MCPReadResourceResponse[T MCPTextResourceContents | MCPBlobResourceContents] struct {
	Contents []*T `json:"contents"`
}

MCPReadResourceResponse defines the response structure for reading a resource in the MCP

type MCPResource

type MCPResource struct {
	URI         string `json:"uri"`
	Name        string `json:"name"`
	Size        int    `json:"size,omitempty"`
	MimeType    string `json:"mimeType,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
}

MCPResource defines the structure of a resource in the MCP

type MCPResourceCapabilities

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

MCPResourceCapabilities defines the capabilities related to resources in the MCP

type MCPResourceLink struct {
	URI         string `json:"uri"`
	Type        string `json:"type"`
	Name        string `json:"name"`
	Size        int    `json:"size,omitempty"`
	MimeType    string `json:"mimeType,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
}

MCPResourceLink defines the resource link content structure used in MCP

func NewMCPResourceLink(uri string, name string) *MCPResourceLink

NewMCPResourceLink creates a new instance of MCPResourceLink with the given parameters

type MCPTextContent

type MCPTextContent struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

MCPTextContent defines the text content structure used in MCP

func NewMCPTextContent

func NewMCPTextContent(text string) *MCPTextContent

NewMCPTextContent creates a new instance of MCPTextContent with the given text

type MCPTextResourceContents

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

MCPTextResourceContents defines the text contents structure of a resource in the MCP

type MCPTool

type MCPTool struct {
	Name         string             `json:"name"`
	InputSchema  *jsonschema.Schema `json:"inputSchema"`
	OutputSchema *jsonschema.Schema `json:"outputSchema,omitempty"`
	Title        string             `json:"title,omitempty"`
	Description  string             `json:"description,omitempty"`
}

MCPTool defines the structure of a tool in the MCP

type MCPToolCapabilities

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

MCPToolCapabilities defines the capabilities related to tools in the MCP

type MCPToolHandler

type MCPToolHandler[T MCPTextContent | MCPImageContent | MCPAudioContent | MCPResourceLink | MCPEmbeddedResource] interface {
	// Name returns the name of the MCP tool
	Name() string

	// Description returns the description of the MCP tool
	Description() string

	// InputType returns the input type for the MCP tool request
	InputType() reflect.Type

	// OutputType returns the output type for the MCP tool response
	OutputType() reflect.Type

	// Handle processes the MCP call tool request and returns the response
	Handle(*core.WebContext, *MCPCallToolRequest, *models.User, *settings.Config, MCPAvailableServices) (any, []*T, error)
}

MCPToolHandler defines the MCP tool handler

type MCPTransactionInfo

type MCPTransactionInfo struct {
	Time                   string `json:"time,omitempty" jsonschema_description:"Time of the transaction in RFC 3339 format (e.g. 2023-01-01T12:00:00Z)"`
	Type                   string `` /* 133-byte string literal not displayed */
	Amount                 string `json:"amount" jsonschema_description:"Amount of the transaction in the specified currency"`
	Currency               string `json:"currency,omitempty" jsonschema_description:"Currency code of the transaction (e.g. USD, EUR)"`
	SecondaryCategoryName  string `json:"category_name,omitempty" jsonschema_description:"Secondary category name for the transaction"`
	AccountName            string `json:"account_name,omitempty" jsonschema_description:"Account name for the transaction"`
	DestinationAmount      string `json:"destination_amount,omitempty" jsonschema_description:"Destination amount for transfer transactions (optional)"`
	DestinationCurrency    string `` /* 139-byte string literal not displayed */
	DestinationAccountName string `` /* 128-byte string literal not displayed */
	Comment                string `json:"comment,omitempty" jsonschema_description:"Description of the transaction"`
}

MCPTransactionInfo defines the structure of transaction information

Jump to

Keyboard shortcuts

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