1fccae1568
Implementa el cliente MCP que permite a los agentes conectarse a servidores MCP externos y usar sus tools como si fueran tools nativas del agente. Arquitectura implementada: - shell/mcp/client.go: Cliente MCP con soporte stdio y SSE - shell/mcp/manager.go: Gestor de múltiples clientes MCP - tools/mcptools/mcp.go: Bridge que convierte MCP tools → tools.Tool - shell/mcp/server.go: Movido desde shell/protocols/ para colocación junto al client Cambios en config: - MCPServerCfg extendido con campos Transport, Command, Args, Env, Headers, Prefix, Timeout para soportar stdio y SSE transport Integración en runtime: - agents/runtime.go: Inicializa MCP manager si config.Tools.MCP.Enabled - buildToolRegistry: Registra tools MCP automáticamente con prefijos configurables - Agent: Campo mcpManager que se cierra en shutdown Transportes soportados: - stdio: Lanza subproceso (ej: npx -y @anthropic/mcp-server-brave-search) - SSE: Se conecta a servidor HTTP MCP Las tools MCP son indistinguibles de tools nativas desde el punto de vista del LLM. Auto-discovery via ListTools(), conversión de JSON Schema a tools.Param. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
// Package mcp provides MCP client and server implementations.
|
|
package mcp
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|
"github.com/mark3labs/mcp-go/server"
|
|
|
|
"github.com/enmanuel/agents/pkg/tools"
|
|
)
|
|
|
|
// MCPServer exposes agent tools as an MCP server.
|
|
type MCPServer struct {
|
|
srv *server.MCPServer
|
|
logger *slog.Logger
|
|
}
|
|
|
|
// NewMCPServer creates an MCP server exposing the given tool specs.
|
|
func NewMCPServer(name, version string, specs []tools.ToolSpec, logger *slog.Logger) *MCPServer {
|
|
srv := server.NewMCPServer(name, version)
|
|
|
|
for _, spec := range specs {
|
|
spec := spec // capture
|
|
tool := mcp.NewTool(spec.Name,
|
|
mcp.WithDescription(spec.Description),
|
|
)
|
|
srv.AddTool(tool, func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
// Placeholder handler — wire real execution here
|
|
return mcp.NewToolResultText(fmt.Sprintf("tool %s called", spec.Name)), nil
|
|
})
|
|
}
|
|
|
|
return &MCPServer{srv: srv, logger: logger}
|
|
}
|
|
|
|
// ServeStdio runs the MCP server over stdin/stdout (for Claude Desktop / CLI integration).
|
|
func (m *MCPServer) ServeStdio(ctx context.Context) error {
|
|
m.logger.Info("mcp server starting on stdio")
|
|
return server.ServeStdio(m.srv)
|
|
}
|