Eino Tool - MCP
Overview
Model Context Protocol (MCP) is a standardized open protocol introduced by Anthropic for model access to resources. Eino provides wrappers so you can directly use resources exposed by an existing MCP Server.
This section introduces the MCPTool wrapper, which implements Eino’s InvokableTool interface (Eino: ToolsNode guide).
Also see:
Usage
QuickStart
First create an MCP client. Eino leverages the open-source SDK mark3labs/mcp-go:
import "github.com/mark3labs/mcp-go/client"
// stdio client
cli, err := client.NewStdioMCPClient(myCommand, myEnvs, myArgs...)
// sse client
cli, err := client.NewSSEMCPClient(myBaseURL)
// sse client needs to manually start asynchronous communication
// while stdio does not require it.
err = cli.Start(ctx)
mcp-go also supports other methods to create a Client (such as InProcess). For more information, see: https://mcp-go.dev/transports
Considering client reuse, the wrapper assumes the client has finished Initialize with the Server; you need to perform client initialization yourself:
import "github.com/mark3labs/mcp-go/mcp"
initRequest := mcp.InitializeRequest{}
initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
initRequest.Params.ClientInfo = mcp.Implementation{
Name: "example-client",
Version: "1.0.0",
}
_, err = cli.Initialize(ctx, initRequest)
Then create Eino tools using the Client:
import "github.com/cloudwego/eino-ext/components/tool/mcp"
tools, err := mcp.GetTools(ctx, &mcp.Config{Cli: cli})
Tools can be called directly:
for i, mcpTool := range mcpTools {
fmt.Println(i, ":")
info, err := mcpTool.Info(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println("Name:", info.Name)
fmt.Println("Desc:", info.Desc)
fmt.Println()
}
You can also use tools within any Eino Agent; for example with ReAct Agent:
import (
"github.com/cloudwego/eino/flow/agent/react"
"github.com/cloudwego/eino-ext/components/tool/mcp"
)
llm, err := /*create a chat model*/
tools, err := mcp.GetTools(ctx, &mcp.Config{Cli: cli})
agent, err := react.NewAgent(ctx, &react.AgentConfig{
Model: llm,
ToolsConfig: compose.ToolsNodeConfig{Tools: tools},
})
Specify Tool by Name
GetTools supports filtering by tool names to avoid unintended tools:
import "github.com/cloudwego/eino-ext/components/tool/mcp"
tools, err := mcp.GetTools(ctx, &mcp.Config{
Cli: cli,
ToolNameList: []string{"name"},
})
More Information
Practice example: https://github.com/cloudwego/eino-ext/blob/main/components/tool/mcp/examples/mcp.go
