Skip to content

Re-land MCP server library and codegen tool#31

Merged
zer0stars merged 4 commits into
mainfrom
feat/mcpserver-reland
Apr 20, 2026
Merged

Re-land MCP server library and codegen tool#31
zer0stars merged 4 commits into
mainfrom
feat/mcpserver-reland

Conversation

@zer0stars

Copy link
Copy Markdown
Member

Summary

Re-lands pkg/mcpserver + cmd/mcpgen. The original PR #25 was merged on 2026-03-26 but main was subsequently force-reset back to dc13a15 — the merge commit 1419fc7 is not in main's history, so the code is effectively absent.

This PR ports the richer version (SDK v1.4.1, condensed SDL codegen, full option set, complete test coverage) rather than the slimmed-down 96a839c that was briefly on main.

What's included

  • pkg/mcpserver/ — MCP-over-HTTP wrapper around gqlgen executors
    • New(ctx, exec, name, version, prefix, opts...) with functional options
    • Built-in {prefix}_get_schema + {prefix}_query tools
    • Pre-warmed schema introspection cache
    • Optional bearer token auth (WithTokenVerifier)
    • Prometheus metrics: mcp_tool_calls_total, mcp_tool_duration_seconds
    • Full tool annotations (readOnly/destructive hints)
    • Dual logging (zerolog + slog)
  • cmd/mcpgen/ — reads @mcpTool directives from .graphqls, emits Go tool definitions + condensed SDL

Consumer wiring (downstream PRs)

h, err := mcpserver.New(ctx, mcpserver.NewGQLGenExecutor(es),
    "DIMO <name>", version, prefix,
    mcpserver.WithTools(graph.MCPTools),
    mcpserver.WithCondensedSchema(graph.CondensedSchema))

Downstream PRs already in flight:

  • identity-api#177 (open, will re-pin to this version)
  • telemetry-api#277 (open, will re-pin to this version)
  • fetch-api (new PR forthcoming)

Test plan

  • go build ./... clean
  • go test ./... green (mcpserver + mcpgen)
  • Tag v0.1.0 after merge
  • Downstream PRs re-pinned and green

Adds pkg/mcpserver (MCP-over-HTTP wrapper around gqlgen executors) and
cmd/mcpgen (code generator that reads @mcptool directives from GraphQL
schemas and emits Go tool definitions).

Features:
- Context + version propagation through New()
- WithTools / WithCondensedSchema / WithStateless / WithMaxQuerySize /
  WithTokenVerifier / WithLogger options
- Built-in {prefix}_get_schema + {prefix}_query tools per service
- Pre-warmed schema introspection cache
- Bearer token auth middleware (opt-in)
- Prometheus metrics: mcp_tool_calls_total, mcp_tool_duration_seconds
- Condensed SDL generation for LLM-friendly schema summaries
- Full tool annotations (readOnly, destructive hints)
- Dual logging: zerolog (infra) + slog (MCP SDK convention)

Consumer integration pattern:
  h, err := mcpserver.New(ctx, mcpserver.NewGQLGenExecutor(es),
      "DIMO <name>", version, prefix,
      mcpserver.WithTools(graph.MCPTools),
      mcpserver.WithCondensedSchema(graph.CondensedSchema))

Downstream PRs wire this into identity-api, telemetry-api, fetch-api.
cloudevent v1.0.x predates v0.2.x chronologically (v0.2.7 released
2026-04-13 vs v1.0.4 on 2026-03-10). Go's MVS selects the higher
semver, which pulls in the older API without RawEventID, breaking
downstream consumers (fetch-api) that rely on the field. Pin here
so MVS consistently picks v0.2.7.
Fix CI lint failures: check json.Unmarshal return, wrap resp.Body.Close
in deferred func to ignore error explicitly, and drop a staticcheck
SA9003 empty-branch in condensed_sdl paragraph loop.
mcpgen: stronger self-evident filtering (drop-entirely vs strip-only prefixes, morphological stems), global + per-category legend-fold on signal table, scalar description trim.

mcpserver: remove dead introspection loadSchema path. WithCondensedSchema is now required; New() no longer takes a ctx arg. Shrinks downstream LLM context by ~18%.
@zer0stars
zer0stars merged commit 605db7c into main Apr 20, 2026
4 checks passed
@zer0stars
zer0stars deleted the feat/mcpserver-reland branch April 20, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant