mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-16 16:07:33 +08:00
add mcp (Model Context Protocol) support
This commit is contained in:
@@ -234,6 +234,10 @@ type Config struct {
|
||||
EnableGZip bool
|
||||
EnableRequestLog bool
|
||||
|
||||
// MCP
|
||||
EnableMCPServer bool
|
||||
MCPAllowedRemoteIPs []*core.IPPattern
|
||||
|
||||
// Database
|
||||
DatabaseConfig *DatabaseConfig
|
||||
EnableQueryLog bool
|
||||
@@ -377,6 +381,12 @@ func LoadConfiguration(configFilePath string) (*Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = loadMCPServerConfiguration(config, cfgFile, "mcp")
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = loadDatabaseConfiguration(config, cfgFile, "database")
|
||||
|
||||
if err != nil {
|
||||
@@ -540,6 +550,35 @@ func loadServerConfiguration(config *Config, configFile *ini.File, sectionName s
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadMCPServerConfiguration(config *Config, configFile *ini.File, sectionName string) error {
|
||||
config.EnableMCPServer = getConfigItemBoolValue(configFile, sectionName, "enable_mcp", false)
|
||||
mcpAllowedRemoteIps := getConfigItemStringValue(configFile, sectionName, "mcp_allowed_remote_ips", "")
|
||||
|
||||
if mcpAllowedRemoteIps != "" {
|
||||
remoteIPs := strings.Split(mcpAllowedRemoteIps, ",")
|
||||
config.MCPAllowedRemoteIPs = make([]*core.IPPattern, 0, len(remoteIPs))
|
||||
|
||||
for i := 0; i < len(remoteIPs); i++ {
|
||||
ip := strings.TrimSpace(remoteIPs[i])
|
||||
pattern, err := core.ParseIPPattern(ip)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if pattern == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
config.MCPAllowedRemoteIPs = append(config.MCPAllowedRemoteIPs, pattern)
|
||||
}
|
||||
} else {
|
||||
config.MCPAllowedRemoteIPs = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadDatabaseConfiguration(config *Config, configFile *ini.File, sectionName string) error {
|
||||
dbConfig := &DatabaseConfig{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user