A Go-based Model Context Protocol (MCP) Host service with AI agent capabilities. This service acts as an intelligent agent that connects to multiple MCP servers, integrates with Ollama (OpenAI-compatible LLM), and provides an agentic AI experience to users.
Deploy go-mcp-host as a microservice in your infrastructure.
# Clone the repository
git clone https://github.com/d4l-data4life/go-mcp-host.git
cd go-mcp-host
# Copy and configure
cp config.example.yaml config.yaml
# Edit config.yaml to add your MCP servers
# Start PostgreSQL
make docker-database
# Run the service
make run
The service will be available at http://localhost:8080.
# See detailed deployment guide
cd deploy
cat README.md
# Quick deploy
helm install go-mcp-host ./helm-chart \
-f examples/local/values.yaml \
--namespace mcp-host
See deploy/README.md for full deployment documentation.
Embed MCP Host functionality into your own Go application.
go get github.com/d4l-data4life/go-mcp-host
package main
import (
"context"
"fmt"
"log"
"github.com/d4l-data4life/go-mcp-host/pkg/config"
"github.com/d4l-data4life/go-mcp-host/pkg/mcphost"
"github.com/google/uuid"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func main() {
// Setup database
db, err := gorm.Open(postgres.Open("host=localhost port=5432 user=mcphost dbname=mcphost password=postgres sslmode=disable"), &gorm.Config{})
if err != nil {
log.Fatal(err)
}
// Create MCP Host
host, err := mcphost.NewHost(context.Background(), mcphost.Config{
MCPServers: []config.MCPServerConfig{
{
Name: "weather",
Type: "stdio",
Command: "npx",
Args: []string{"-y", "@h1deya/mcp-server-weather"},
Enabled: true,
Description: "Weather information server",
},
},
LLMEndpoint: "http://localhost:11434",
DB: db,
})
if err != nil {
log.Fatal(err)
}
// Chat with the agent
response, err := host.Chat(context.Background(), mcphost.ChatRequest{
ConversationID: uuid.New(),
UserID: uuid.New(),
UserMessage: "What's the weather in New York?",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(response.Message.Content)
}
Run examples:
# Simple library usage
go run examples/simple_library/simple_library.go
# Web server integration
go run examples/embed_in_webserver/embed_in_webserver.go
# Agent package (mid-level)
go run examples/agent_chat/agent_chat.go
# Low-level MCP usage
go run examples/ollama_with_mcp/ollama_with_mcp.go
See examples/README.md for detailed documentation.
┌────────────────────────────────────────────────────┐
│ Frontend (React/API) │
└────────────────────────┬───────────────────────────┘
│ HTTP/WebSocket
┌────────────────────────▼───────────────────────────┐
│ go-mcp-host │
│ ┌───────────────────────────────────────────────┐ │
│ │ Agent Orchestrator │ │
│ │ - Context gathering │ │
│ │ - Tool execution loop │ │
│ │ - Response generation │ │
│ └───────────┬───────────────────────┬───────────┘ │
│ │ │ │
│ ┌───────────▼──────────┐ ┌─────────▼──────────┐ │
│ │ MCP Manager │ │ LLM Client │ │
│ │ - Session mgmt │ │ - Ollama API │ │
│ │ - Client pooling │ │ - Function calls │ │
│ └───────────┬──────────┘ └────────────────────┘ │
│ │ │
└──────────────┼─────────────────────────────────────┘
│
┌──────────┼──────────┐
│ │ │
┌───▼───┐ ┌───▼───┐ ┌───▼───┐
│ MCP │ │ MCP │ │ MCP │
│Server1│ │Server2│ │Server3│
│(stdio)│ │(HTTP) │ │(stdio)│
└───────┘ └───────┘ └───────┘
Configure MCP servers in config.yaml:
mcp_servers:
# Stdio server example
- name: weather
type: stdio
command: npx
args:
- "-y"
- "@h1deya/mcp-server-weather"
enabled: true
description: "Weather information server"
# HTTP server example
- name: my-api
type: http
url: "https://api.example.com/mcp"
headers:
X-API-Key: "your-api-key"
forwardBearer: true # Forward user's bearer token
enabled: true
description: "My custom MCP server"
Key environment variables:
PORT - HTTP port (default: 8080)CORS_HOSTS - Allowed CORS originsDB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS - Database connectionREMOTE_KEYS_URL - JWT validation endpoint (optional)DEBUG - Enable debug loggingSee config.example.yaml for all options.
POST /api/v1/auth/register - Register new userPOST /api/v1/auth/login - LoginGET /api/v1/conversations - List conversationsPOST /api/v1/conversations - Create conversationDELETE /api/v1/conversations/:id - Delete conversationPOST /api/v1/messages - Send messageWS /api/v1/messages/stream - Stream responsesGET /api/v1/mcp/servers - List MCP serversGET /api/v1/mcp/tools - List available toolsSee swagger/api.yml for the full API specification.
# Build binary
make build
# Build Docker image
make docker-build
# Run tests
make test
# Run linter
make lint
go-mcp-host/
├── cmd/
│ └── api/ # Main application entry point
├── pkg/
│ ├── agent/ # Agent orchestration logic
│ ├── mcp/ # MCP protocol implementation
│ │ ├── client/ # MCP client core
│ │ ├── manager/ # Session management
│ │ ├── protocol/ # Protocol types
│ │ └── transport/ # Stdio/HTTP transports
│ ├── llm/ # LLM integration (Ollama)
│ ├── handlers/ # HTTP handlers
│ ├── models/ # Database models
│ ├── config/ # Configuration
│ ├── auth/ # Authentication
│ ├── server/ # HTTP server setup
│ └── mcphost/ # Public API for library usage
├── deploy/
│ ├── helm-chart/ # Kubernetes Helm chart
│ └── examples/ # Example configurations
├── docs/ # Additional documentation
├── examples/ # Usage examples
├── sql/ # Database migrations
└── swagger/ # API specification
# Run all tests
make test
# Run with coverage
make test-coverage
# Run integration tests (requires running database)
make docker-database
make test-integration
Contributions are welcome! Please:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)gofmt and golangci-lintSee .cursorrules for detailed coding standards.
Apache License 2.0 - see LICENSE for details.
Made with ❤️ by Data4Life