main.go

Overview

The main.go file demonstrates the integration of Model Context Protocol (MCP) tools with an Agent Development Kit (ADK) agent. It provides two modes to run MCP tools:

  1. Local in-memory MCP server mode: Defines and registers a Go function (GetWeather) as an MCP tool served by an in-memory MCP server.

  2. GitHub remote MCP server mode: Connects to GitHub’s remote MCP server using an OAuth2-authenticated HTTP client.

The program creates a Large Language Model (LLM) agent configured with the MCP toolset, then launches the agent for interactive use. The main responsibilities covered include setting up MCP transports, creating and configuring the LLM model and agent, and handling graceful shutdown on interrupt signals.


Package and Imports


Types

Input

type Input struct {
	City string `json:"city" jsonschema:"city name"`
}

Output

type Output struct {
	WeatherSummary string `json:"weather_summary" jsonschema:"weather summary in the given city"`
}

Functions

GetWeather

func GetWeather(ctx context.Context, req *mcp.CallToolRequest, input Input) (*mcp.CallToolResult, Output, error)

localMCPTransport

func localMCPTransport(ctx context.Context) mcp.Transport

githubMCPTransport

func githubMCPTransport(ctx context.Context) mcp.Transport

main

func main()

Implementation Details and Algorithms


Interactions with Other System Components


Usage Example

export GOOGLE_API_KEY="your-google-api-key"
go run main.go
export GOOGLE_API_KEY="your-google-api-key"
export GITHUB_PAT="your-github-pat"
export AGENT_MODE="github"
go run main.go

Agent will start and accept commands, using the get_weather tool implemented either locally or remotely.


Diagram: File Structure and Function Relationships

flowchart TD
A[main] --> B[Gemini Model Init]
A --> C[Select MCP Transport]
C -->|AGENT_MODE=local| D[localMCPTransport]
C -->|AGENT_MODE=github| E[githubMCPTransport]
D --> F[In-memory MCP Server]
F --> G[Register GetWeather Tool]
E --> H[GitHub MCP Remote Server]
A --> I[Create MCP Toolset]
I --> J[mcptoolset.New]
A --> K[Create llmagent]
K --> L[Use Gemini Model]
K --> I
A --> M[Launcher Execute]

This documentation describes the purpose, architecture, and detailed function of the main.go file, including how it implements MCP tool integration with an LLM agent and supports different MCP transport modes. The provided diagram illustrates the key initialization and composition steps of the program.