feat(agent): add MCP integration (#50)

* feat(agent): add MCP integration

Signed-off-by: mudler <mudler@localai.io>

* Update core/agent/mcp.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Hook MCP Server configuration to creation and setting mask

* Allow to specify a bearer token

* Small fixups

---------

Signed-off-by: mudler <mudler@localai.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Ettore Di Giacinto
2025-03-15 23:25:03 +01:00
committed by GitHub
parent dc2570c90b
commit 33b5b8c8f4
10 changed files with 422 additions and 14 deletions

View File

@@ -39,6 +39,8 @@ type Agent struct {
pause bool
newConversations chan openai.ChatCompletionMessage
mcpActions Actions
}
type RAGDB interface {
@@ -84,6 +86,10 @@ func New(opts ...Option) (*Agent, error) {
// xlog = xlog.New(h)
//programLevel.Set(a.options.logLevel)
xlog.Info("Populating actions from MCP Servers (if any)")
a.initMCPActions()
xlog.Info("Done populating actions from MCP Servers")
xlog.Info(
"Agent created",
"agent", a.Character.Name,
@@ -214,7 +220,7 @@ func (a *Agent) Memory() RAGDB {
}
func (a *Agent) runAction(chosenAction Action, params action.ActionParams) (result action.ActionResult, err error) {
for _, act := range a.systemInternalActions() {
for _, act := range a.availableActions() {
if act.Definition().Name == chosenAction.Definition().Name {
res, err := act.Run(a.actionContext, params)
if err != nil {
@@ -708,7 +714,7 @@ func (a *Agent) consumeJob(job *Job, role string) {
// If we have a hud, display it when answering normally
if a.options.enableHUD {
prompt, err := renderTemplate(hudTemplate, a.prepareHUD(), a.systemInternalActions(), reasoning)
prompt, err := renderTemplate(hudTemplate, a.prepareHUD(), a.availableActions(), reasoning)
if err != nil {
job.Result.Conversation = a.currentConversation
job.Result.Finish(fmt.Errorf("error renderTemplate: %w", err))