Skip to content

Commit bf6c9a9

Browse files
authored
Add MCP server endpoint at /mcp with JWT auth (#75)
* Add MCP server endpoint at /mcp with JWT auth Expose an MCP (Model Context Protocol) Streamable HTTP endpoint that lets LLM agents query fetch-api's GraphQL surface via the standard MCP transport. Shares the same JWT + claim-injection middleware chain as /query. - schema/mcp.graphqls: @mcptool / @mcpExample / @mcpHide directives - schema/base.graphqls: annotate the 5 read queries with @mcptool - internal/graph/mcp_tools_gen.go: generated via server-garage mcpgen - internal/app/app.go: build MCPHandler alongside GraphQL handler, share gqlgen.ExecutableSchema between the two - cmd/fetch-api/main.go: mount /mcp on the HTTP mux - go.mod: pull in modelcontextprotocol/go-sdk v1.4.1; bump gqlgen to match server-garage * chore: regenerate gqlgen artifacts gqlgen 0.17.89 auto-maps cloudevent.CloudEventHeader.RawEventID (json:"raweventid") to the schema's nullable raweventid field, so the custom CloudEventHeaderResolver stub is no longer needed. * chore(mcp): adopt mcpserver.New() signature change + condensed schema regen - Drop context.Background() arg from New() call - Regen condensed schema via updated mcpgen (stronger self-evident filter) * chore(deps): bump server-garage to v0.1.0
1 parent 53aef32 commit bf6c9a9

11 files changed

Lines changed: 445 additions & 592 deletions

File tree

cmd/fetch-api/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func main() {
7171
})
7272
mux.Handle("/", app.LoggerMiddleware(app.PanicRecoveryMiddleware(playground.Handler("GraphQL playground", "/query"))))
7373
mux.Handle("/query", application.Handler)
74+
mux.Handle("/mcp", application.MCPHandler)
7475

7576
logger.Info().Msgf("Server started on port: %d", cfg.Port)
7677
runner.RunHandler(runnerCtx, runnerGroup, mux, ":"+strconv.Itoa(cfg.Port))

go.mod

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ module github.com/DIMO-Network/fetch-api
33
go 1.25.0
44

55
require (
6-
github.com/99designs/gqlgen v0.17.86
6+
github.com/99designs/gqlgen v0.17.89
77
github.com/ClickHouse/clickhouse-go/v2 v2.43.0
88
github.com/DIMO-Network/clickhouse-infra v0.0.7
99
github.com/DIMO-Network/cloudevent v0.2.7
10-
github.com/DIMO-Network/server-garage v0.0.7
10+
github.com/DIMO-Network/server-garage v0.1.0
1111
github.com/DIMO-Network/shared v1.1.7
1212
github.com/DIMO-Network/token-exchange-api v0.4.0
1313
github.com/auth0/go-jwt-middleware/v2 v2.2.2
@@ -19,12 +19,13 @@ require (
1919
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
2020
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2
2121
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
22+
github.com/modelcontextprotocol/go-sdk v1.4.1
2223
github.com/rs/zerolog v1.34.0
2324
github.com/stretchr/testify v1.11.1
24-
github.com/vektah/gqlparser/v2 v2.5.31
25+
github.com/vektah/gqlparser/v2 v2.5.32
2526
github.com/volatiletech/sqlboiler/v4 v4.19.1
2627
go.uber.org/mock v0.6.0
27-
golang.org/x/sync v0.19.0
28+
golang.org/x/sync v0.20.0
2829
google.golang.org/grpc v1.79.3
2930
google.golang.org/protobuf v1.36.11
3031
)
@@ -50,6 +51,7 @@ require (
5051
github.com/beorn7/perks v1.0.1 // indirect
5152
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
5253
github.com/cespare/xxhash/v2 v2.3.0 // indirect
54+
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
5355
github.com/containerd/errdefs v1.0.0 // indirect
5456
github.com/containerd/errdefs/pkg v0.3.0 // indirect
5557
github.com/containerd/log v0.1.0 // indirect
@@ -69,20 +71,21 @@ require (
6971
github.com/go-logr/logr v1.4.3 // indirect
7072
github.com/go-logr/stdr v1.2.2 // indirect
7173
github.com/go-ole/go-ole v1.3.0 // indirect
72-
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
74+
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
7375
github.com/goccy/go-yaml v1.19.2 // indirect
7476
github.com/gofiber/fiber/v2 v2.52.12 // indirect
75-
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
77+
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
78+
github.com/google/jsonschema-go v0.4.2 // indirect
7679
github.com/google/uuid v1.6.0 // indirect
7780
github.com/gorilla/websocket v1.5.1 // indirect
7881
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
7982
github.com/holiman/uint256 v1.3.2 // indirect
80-
github.com/klauspost/compress v1.18.4 // indirect
83+
github.com/klauspost/compress v1.18.5 // indirect
8184
github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35 // indirect
8285
github.com/magiconair/properties v1.8.10 // indirect
8386
github.com/mattn/go-colorable v0.1.14 // indirect
8487
github.com/mattn/go-isatty v0.0.20 // indirect
85-
github.com/mattn/go-runewidth v0.0.16 // indirect
88+
github.com/mattn/go-runewidth v0.0.21 // indirect
8689
github.com/mdelapenya/tlscert v0.2.0 // indirect
8790
github.com/mfridman/interpolate v0.0.2 // indirect
8891
github.com/moby/docker-image-spec v1.3.1 // indirect
@@ -105,17 +108,17 @@ require (
105108
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
106109
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
107110
github.com/pressly/goose/v3 v3.27.0 // indirect
108-
github.com/prometheus/client_golang v1.23.0 // indirect
111+
github.com/prometheus/client_golang v1.23.2 // indirect
109112
github.com/prometheus/client_model v0.6.2 // indirect
110-
github.com/prometheus/common v0.65.0 // indirect
111-
github.com/prometheus/procfs v0.19.2 // indirect
112-
github.com/rivo/uniseg v0.4.7 // indirect
113+
github.com/prometheus/common v0.67.5 // indirect
114+
github.com/prometheus/procfs v0.20.1 // indirect
113115
github.com/segmentio/asm v1.2.1 // indirect
116+
github.com/segmentio/encoding v0.5.4 // indirect
114117
github.com/sethvargo/go-retry v0.3.0 // indirect
115118
github.com/shirou/gopsutil/v4 v4.25.6 // indirect
116119
github.com/shopspring/decimal v1.4.0 // indirect
117120
github.com/sirupsen/logrus v1.9.3 // indirect
118-
github.com/sosodev/duration v1.3.1 // indirect
121+
github.com/sosodev/duration v1.4.0 // indirect
119122
github.com/spf13/cast v1.7.0 // indirect
120123
github.com/testcontainers/testcontainers-go v0.40.0 // indirect
121124
github.com/testcontainers/testcontainers-go/modules/clickhouse v0.38.0 // indirect
@@ -125,24 +128,27 @@ require (
125128
github.com/tklauser/go-sysconf v0.3.15 // indirect
126129
github.com/tklauser/numcpus v0.10.0 // indirect
127130
github.com/twpayne/go-geom v1.6.1 // indirect
128-
github.com/urfave/cli/v3 v3.6.1 // indirect
131+
github.com/urfave/cli/v3 v3.7.0 // indirect
129132
github.com/valyala/bytebufferpool v1.0.0 // indirect
130-
github.com/valyala/fasthttp v1.65.0 // indirect
133+
github.com/valyala/fasthttp v1.69.0 // indirect
131134
github.com/volatiletech/inflect v0.0.1 // indirect
132135
github.com/volatiletech/strmangle v0.0.7-0.20240503230658-86517898275a // indirect
136+
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
133137
github.com/yusufpapurcu/wmi v1.2.4 // indirect
134138
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
135139
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0 // indirect
136140
go.opentelemetry.io/otel v1.42.0 // indirect
137141
go.opentelemetry.io/otel/metric v1.42.0 // indirect
138142
go.opentelemetry.io/otel/trace v1.42.0 // indirect
139143
go.uber.org/multierr v1.11.0 // indirect
144+
go.yaml.in/yaml/v2 v2.4.4 // indirect
140145
go.yaml.in/yaml/v3 v3.0.4 // indirect
141-
golang.org/x/crypto v0.48.0 // indirect
146+
golang.org/x/crypto v0.49.0 // indirect
142147
golang.org/x/mod v0.33.0 // indirect
143-
golang.org/x/net v0.50.0 // indirect
144-
golang.org/x/sys v0.41.0 // indirect
145-
golang.org/x/text v0.34.0 // indirect
148+
golang.org/x/net v0.51.0 // indirect
149+
golang.org/x/oauth2 v0.36.0 // indirect
150+
golang.org/x/sys v0.42.0 // indirect
151+
golang.org/x/text v0.35.0 // indirect
146152
golang.org/x/tools v0.42.0 // indirect
147153
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
148154
google.golang.org/genproto/googleapis/api v0.0.0-20251222181119-0a764e51fe1b // indirect

0 commit comments

Comments
 (0)