MCP Integration

Markdown
Build typed MCP servers and clients from Goa designs, with authorization, user input, durable jobs, Apps, and Skills.

Goa-AI supports both creating MCP servers and consuming external MCP tools. Add MCP declarations to a Goa service to expose methods as tools, publish resources, and provide prompt templates. The generator produces JSON-RPC protocol handling and service adapters. Hosting an MCP server does not require running a Goa-AI agent.

The HTTP and stdio callers send self-contained requests with protocol metadata. There is no initialization handshake or protocol session. Their Caller interface invokes tools; their Listen methods receive change notifications. Generated Goa JSON-RPC clients also expose the resource, prompt, discovery, and completion operations declared by the service.

Generated HTTP servers also accept basic MCP 2025-11-25 clients on the same POST URL. Regenerate the server; no service interface or constructor changes are needed. initialize replies with 2025-11-25, then calls carry MCP-Protocol-Version: 2025-11-25 without a session ID. Tools, resources, prompts and argument completion keep the same authentication, authorization, middleware and typed validation. For statically declared tools, object results keep their shape; scalar, array and untagged-union results use {"value": ...} and a matching object schema. Structured results are also included as text content. This older path does not offer Tasks, change subscriptions or requests for additional client input. Built-in callers continue to use 2026-07-28.

One design supplies the tool schema, typed decoding, validation, server adapters and client bindings. Your configured Goa endpoints keep authentication, authorization, middleware and application behavior. Developers and coding agents edit that contract and application code; goa gen keeps the derived interfaces in agreement. Generated MCP servers run over HTTP (New and Mount) or stdio (ServeStdio).

Use the Quickstart module setup to install the v0.89.0 Goa-AI release and its matching Goa dependency before generating an HTTP server. Generating a stdio server (ServeStdio) requires goa.design/goa-ai v0.90.1-0.20261111075239-0114fb9d40d3 (go get goa.design/goa-ai@0114fb9d40d3d0bf607459a9006a34ff601c83ea) and running the module-pinned generator (go run goa.design/goa/v3/cmd/goa gen <design-package>).

What you needDeclare or compose
Tools, resources, prompts and suggestionsTool, Resource, ResourceReader, Prompt, PromptCompletion, ResourceCompletion
Tools defined at runtimeDynamicTools inside MCP; implement generated ToolsList and ToolsCall
Authenticated catalogs and change notificationsToolCatalog, PromptCatalog, ResourceCatalog, ResourceTemplateCatalog, SubscriptionSource
User forms or consent to open a URLInputExchange on an existing Goa method
Asynchronous jobs and later host answersTaskExchange with existing create, read, answer and cancel methods
Browser interfaces inside an MCP hostToolUI, ToolVisibility and ToolMetadata with ordinary resources
Instructions and supporting filesSkillCatalog, SkillLookup, optional ResourceDirectory, and host-owned loading

Start with the server below, then add the capabilities your application needs.

Overview

MCP integration follows this workflow:

  1. Service design: Declare the MCP server via Goa’s MCP DSL
  2. Agent design: Reference that suite via a toolset declared with FromMCP(...) or FromExternalMCP(...)
  3. Code generation: Produces the MCP JSON-RPC server (when Goa-backed) plus runtime registration helpers and toolset-owned specs/codecs for the suite
  4. Runtime wiring: Instantiate an HTTP or stdio mcpruntime.Caller. The HTTP caller accepts either a JSON response or an HTTP event stream. Generated helpers register the toolset and adapt JSON-RPC errors into planner.ToolFailure values
  5. Planner execution: Planners construct calls with generated typed tool descriptors; the runtime forwards canonical JSON to the MCP caller, records results, and surfaces structured telemetry

Declaring MCP Toolsets

In Service Design

First, declare the MCP server in your Goa service design:

package design

import (
    . "goa.design/goa/v3/dsl"
    . "goa.design/goa-ai/dsl"
)