Add MCP server endpoint at /mcp with JWT auth#75
Draft
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/mcpso LLM agents can query fetch-api's GraphQL surface via the standard MCP transport./mcpreuses the same middleware chain as/query(PanicRecovery → Logger → RequestTimeout → CheckJWT → AddClaimHandler), so authorization + DID scoping are identical.@mcpTooland surfaced via server-garage'smcpgencodegen:fetch_get_latest_index,fetch_list_indexes,fetch_get_latest_cloud_event,fetch_list_cloud_events,fetch_list_available_event_types.Why draft
Depends on server-garage v0.1.0 (DIMO-Network/server-garage#31). Once that tag lands, this PR needs:
replace github.com/DIMO-Network/server-garage => /Users/zer0stars/workspace/server-garagefromgo.modgithub.com/DIMO-Network/server-garage v0.1.0go mod tidyNotable changes
schema/mcp.graphqls— new: defines@mcpTool/@mcpExample/@mcpHidedirectives.schema/base.graphqls— annotate read queries with@mcpTool.internal/graph/mcp_tools_gen.go— generated bymcpgen; exportsMCPTools+CondensedSchema.internal/graph/resolver.go—//go:generaterunsmcpgen.internal/app/app.go— buildsMCPHandlerusingmcpserver.New(…, NewGQLGenExecutor(es), …)with the same auth chain; shares the gqlgenExecutableSchemawith/query.cmd/fetch-api/main.go—mux.Handle("/mcp", application.MCPHandler).internal/graph/base.resolvers.go— implement newRaweventidresolver stub emitted after gqlgen bump (non-pointer Go field, nullable schema field).gqlgen.yml—mcpTool/mcpExamplemarkedskip_runtime.Test plan
go build ./...go test ./...go mod tidyclean; CI green (generate/lint/tests/install-tools)POST /mcptools/listreturns 5 tools;tools/call fetch_get_latest_indexwith a valid vehicle JWT returns a CloudEventIndex; unauthenticated request returns 401https://fetch-api.dev.dimo.zone/mcpwithtools/list