Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/jackc/pgx/v5 v5.7.5
github.com/jba/slog v0.2.0
github.com/lib/pq v1.10.9
github.com/mark3labs/mcp-go v0.29.0
github.com/modelcontextprotocol/go-sdk v1.2.0
github.com/pgvector/pgvector-go v0.3.0
github.com/weaviate/weaviate v1.30.0
github.com/weaviate/weaviate-go-client/v5 v5.1.0
Expand All @@ -50,7 +50,6 @@ require (
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/mod v0.25.0 // indirect
Expand All @@ -59,6 +58,7 @@ require (

require (
cloud.google.com/go/alloydb v1.16.1 // indirect
github.com/google/jsonschema-go v0.3.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfU
github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/go-jose/go-jose/v4 v4.1.0 h1:cYSYxd3pw5zd2FSXk2vGdn9igQU2PS8MuxrCOCl0FdY=
github.com/go-jose/go-jose/v4 v4.1.0/go.mod h1:GG/vqmYm3Von2nYiB2vGTXzdoNKE5tix5tuc6iAd+sw=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -179,6 +177,8 @@ github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7Lk
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
Expand Down Expand Up @@ -215,6 +215,8 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIygDg+Q=
github.com/google/jsonschema-go v0.3.0/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc=
github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0=
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
Expand Down Expand Up @@ -289,8 +291,6 @@ github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/mark3labs/mcp-go v0.29.0 h1:sH1NBcumKskhxqYzhXfGc201D7P76TVXiT0fGVhabeI=
github.com/mark3labs/mcp-go v0.29.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/mbleigh/raymond v0.0.0-20250414171441-6b3a58ab9e0a h1:v2cBA3xWKv2cIOVhnzX/gNgkNXqiHfUgJtA3r61Hf7A=
Expand All @@ -302,6 +302,8 @@ github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modelcontextprotocol/go-sdk v1.2.0 h1:Y23co09300CEk8iZ/tMxIX1dVmKZkzoSBZOpJwUnc/s=
github.com/modelcontextprotocol/go-sdk v1.2.0/go.mod h1:6fM3LCm3yV7pAs8isnKLn07oKtB0MP9LHd3DfAcKw10=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
Expand Down Expand Up @@ -333,8 +335,6 @@ github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWN
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spiffe/go-spiffe/v2 v2.5.0 h1:N2I01KCUkv1FAjZXJMwh95KK1ZIQLYbPfhaxw8WS0hE=
Expand Down
146 changes: 74 additions & 72 deletions go/plugins/mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func main() {
g := genkit.Init(ctx)

// Connect to the MCP everything server
client, err := mcp.NewGenkitMCPClient(mcp.MCPClientOptions{
// NewClient uses the context to manage the connection lifecycle.
client, err := mcp.NewClient(ctx, mcp.MCPClientOptions{
Name: "everything-server",
Stdio: &mcp.StdioConfig{
Command: "npx",
Expand All @@ -49,7 +50,9 @@ func main() {
}
```

## GenkitMCPManager - Multiple Server Management
> **Note:** `NewGenkitMCPClient` is deprecated in favor of `NewClient`, which supports context propagation.

## MCPHost - Multiple Server Management

Manage connections to multiple MCP servers:

Expand All @@ -66,24 +69,28 @@ import (

func main() {
ctx := context.Background()
g, _ := genkit.Init(ctx)
g := genkit.Init(ctx)

// Create manager with multiple servers
manager, err := mcp.NewMCPManager(mcp.MCPManagerOptions{
// Create host with multiple servers
host, err := mcp.NewMCPHost(g, mcp.MCPHostOptions{
Name: "my-app",
MCPServers: map[string]mcp.MCPClientOptions{
"everything": {
Name: "everything-server",
Stdio: &mcp.StdioConfig{
Command: "npx",
Args: []string{"-y", "@modelcontextprotocol/server-everything"},
MCPServers: []mcp.MCPServerConfig{
{
Name: "everything",
Config: mcp.MCPClientOptions{
Stdio: &mcp.StdioConfig{
Command: "npx",
Args: []string{"-y", "@modelcontextprotocol/server-everything"},
},
},
},
"filesystem": {
Name: "fs-server",
Stdio: &mcp.StdioConfig{
Command: "npx",
Args: []string{"@modelcontextprotocol/server-filesystem", "/tmp"},
{
Name: "filesystem",
Config: mcp.MCPClientOptions{
Stdio: &mcp.StdioConfig{
Command: "npx",
Args: []string{"@modelcontextprotocol/server-filesystem", "/tmp"},
},
},
},
},
Expand All @@ -93,7 +100,7 @@ func main() {
}

// Connect to new server at runtime
err = manager.ConnectServer(ctx, "weather", mcp.MCPClientOptions{
err = host.Connect(ctx, g, "weather", mcp.MCPClientOptions{
Name: "weather-server",
Stdio: &mcp.StdioConfig{
Command: "python",
Expand All @@ -105,14 +112,10 @@ func main() {
}

// Temporarily disable/enable servers
manager.DisableServer("filesystem")
manager.EnableServer("filesystem")

// Disconnect server
manager.DisconnectServer("weather")
host.Disconnect(ctx, "weather")

// Get tools from all active servers
tools, err := manager.GetActiveTools(ctx, g)
tools, err := host.GetActiveTools(ctx, g)
if err != nil {
log.Fatal(err)
}
Expand All @@ -121,7 +124,7 @@ func main() {

## GenkitMCPServer - Expose Genkit Tools

Turn your Genkit app into an MCP server:
Turn your Genkit app into an MCP server that others can connect to:

```go
package main
Expand All @@ -130,69 +133,67 @@ import (
"context"
"log"

"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/mcp"
)

func main() {
ctx := context.Background()
g := genkit.Init(ctx)
g := genkit.Init(context.Background())

// Create a host with multiple servers
host, err := mcp.NewMCPHost(g, mcp.MCPHostOptions{
Name: "my-app",
MCPServers: []mcp.MCPServerConfig{
{
Name: "everything-server",
Config: mcp.MCPClientOptions{
Name: "everything-server",
Stdio: &mcp.StdioConfig{
Command: "npx",
Args: []string{"-y", "@modelcontextprotocol/server-everything"},
},
},
},
{
Name: "fs-server",
Config: mcp.MCPClientOptions{
Name: "fs-server",
Stdio: &mcp.StdioConfig{
Command: "npx",
Args: []string{"@modelcontextprotocol/server-filesystem", "/tmp"},
},
},
},
},
// Define tools and resources you want to expose
genkit.DefineTool(g, "hello", "says hello", func(ctx *ai.ToolContext, input any) (string, error) {
return "Hello from Genkit!", nil
})
if err != nil {
log.Fatal(err)
}

// Connect to new server at runtime
err = host.Connect(ctx, g, "weather", mcp.MCPClientOptions{
Name: "weather-server",
Stdio: &mcp.StdioConfig{
Command: "python",
Args: []string{"weather_server.py"},
},
// Create the MCP server
server := mcp.NewMCPServer(g, mcp.MCPServerOptions{
Name: "my-genkit-server",
Version: "1.0.0",
})
if err != nil {

// Start serving over Stdio
// Use ServeStdioWithContext(ctx) for graceful shutdown support.
if err := server.ServeStdio(); err != nil {
log.Fatal(err)
}
}
```

// Reconnect server
host.Reconnect(ctx, "fs-server")
### Exposing as an HTTP Server (SSE)

// Disconnect server
host.Disconnect(ctx, "weather")
You can also expose your Genkit tools over HTTP using Server-Sent Events (SSE):

// Get tools from all active servers
tools, err := host.GetActiveTools(ctx, g)
if err != nil {
log.Fatal(err)
}
}
```go
package main

import (
"context"
"log"
"net/http"

"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/mcp"
)

func main() {
g := genkit.Init(context.Background())

// Define tools...

server := mcp.NewMCPServer(g, mcp.MCPServerOptions{
Name: "my-genkit-http-server",
})

handler, err := server.HTTPHandler()
if err != nil {
log.Fatal(err)
}

http.Handle("/mcp", handler)
log.Printf("MCP server listening on http://localhost:8080/mcp")
log.Fatal(http.ListenAndServe(":8080", nil))
}
```

## Testing Your Server
Expand Down Expand Up @@ -222,5 +223,6 @@ Stdio: &mcp.StdioConfig{
```go
SSE: &mcp.SSEConfig{
BaseURL: "http://localhost:3000/sse",
Headers: map[string]string{"Authorization": "Bearer token"},
}
```
Loading
Loading