feat: enrich search with msglib display entities
This commit is contained in:
@@ -9,15 +9,19 @@ import (
|
||||
|
||||
"isphere-ai-bridge/internal/helperclient"
|
||||
"isphere-ai-bridge/internal/isphere"
|
||||
"isphere-ai-bridge/internal/msglib"
|
||||
"isphere-ai-bridge/internal/tools"
|
||||
)
|
||||
|
||||
const (
|
||||
ServerName = "isphere-ai-bridge"
|
||||
ServerTitle = "iSphere AI Bridge"
|
||||
ServerVersion = "0.1.0"
|
||||
EnvPacketLogFileKey = "ISPHERE_PACKET_LOG_FILE"
|
||||
EnvPacketLogDirKey = "ISPHERE_PACKET_LOG_DIR"
|
||||
ServerName = "isphere-ai-bridge"
|
||||
ServerTitle = "iSphere AI Bridge"
|
||||
ServerVersion = "0.1.0"
|
||||
EnvPacketLogFileKey = "ISPHERE_PACKET_LOG_FILE"
|
||||
EnvPacketLogDirKey = "ISPHERE_PACKET_LOG_DIR"
|
||||
EnvMsgLibSidecarExeKey = "ISPHERE_MSGLIB_SIDECAR_EXE"
|
||||
EnvMsgLibSQLiteDLLKey = "ISPHERE_MSGLIB_SQLITE_DLL"
|
||||
EnvMsgLibDBKey = "ISPHERE_MSGLIB_DB"
|
||||
)
|
||||
|
||||
func NewServer() *mcp.Server {
|
||||
@@ -44,10 +48,41 @@ func NewServerFromEnv() (*mcp.Server, error) {
|
||||
}
|
||||
source = loaded
|
||||
}
|
||||
return NewServerWithReceiveSource(source), nil
|
||||
displaySource, err := msgLibDisplayEntitySourceFromEnv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewServerWithSources(source, displaySource), nil
|
||||
}
|
||||
|
||||
func msgLibDisplayEntitySourceFromEnv() (tools.DisplayEntitySource, error) {
|
||||
sidecarExe := strings.TrimSpace(os.Getenv(EnvMsgLibSidecarExeKey))
|
||||
sqliteDLL := strings.TrimSpace(os.Getenv(EnvMsgLibSQLiteDLLKey))
|
||||
dbPath := strings.TrimSpace(os.Getenv(EnvMsgLibDBKey))
|
||||
configured := 0
|
||||
for _, value := range []string{sidecarExe, sqliteDLL, dbPath} {
|
||||
if value != "" {
|
||||
configured++
|
||||
}
|
||||
}
|
||||
if configured == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if configured != 3 {
|
||||
return nil, fmt.Errorf("configure MsgLib source: set all of %s, %s, and %s, or set none", EnvMsgLibSidecarExeKey, EnvMsgLibSQLiteDLLKey, EnvMsgLibDBKey)
|
||||
}
|
||||
cfg, err := msglib.ConfigFromEnv()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("configure MsgLib source: %w", err)
|
||||
}
|
||||
return msglib.NewClient(cfg), nil
|
||||
}
|
||||
|
||||
func NewServerWithReceiveSource(source tools.ReceiveMessagesSource) *mcp.Server {
|
||||
return NewServerWithSources(source, nil)
|
||||
}
|
||||
|
||||
func NewServerWithSources(source tools.ReceiveMessagesSource, displaySource tools.DisplayEntitySource) *mcp.Server {
|
||||
server := mcp.NewServer(&mcp.Implementation{
|
||||
Name: ServerName,
|
||||
Title: ServerTitle,
|
||||
@@ -55,8 +90,8 @@ func NewServerWithReceiveSource(source tools.ReceiveMessagesSource) *mcp.Server
|
||||
}, nil)
|
||||
tools.RegisterWinHelperTools(server, helperclient.Client{})
|
||||
tools.RegisterISphereReadTools(server, source)
|
||||
tools.RegisterISphereContactTools(server, source)
|
||||
tools.RegisterISphereGroupTools(server, source)
|
||||
tools.RegisterISphereContactToolsWithDisplayEntities(server, source, displaySource)
|
||||
tools.RegisterISphereGroupToolsWithDisplayEntities(server, source, displaySource)
|
||||
tools.RegisterISphereFileTools(server, source)
|
||||
return server
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user