MCP service for future ai interfacing

Proposal: a Merge MCP service

I’d like us to add a standalone Go service under service/mcp that exposes selected portal operations through the Model Context Protocol (MCP). It would call the existing portal gRPC API, so we keep the current policy checks, audit events, and backend workflows. For the first version, I’d require authentication to discover and run tools, with public documentation explaining what’s available and how to connect.

What MCP gives us

MCP lets an agent application list the operations a service offers and call them in a standard way. An MCP tool is a named operation with a description and JSON Schema for its arguments. The application gets these definitions through tools/list, presents them to its language model, and runs selected operations through tools/call. For example, asking an agent to inspect an experiment can lead to a typed call to a Merge status tool. The application handles the model interaction and any user approval prompts; our Go service implements the tool handlers. See the MCP tools specification.

We can use the official Go SDK with Streamable HTTP. Clients send JSON-RPC messages to an HTTPS /mcp endpoint and receive JSON or Server-Sent Events responses. We’ll document the protocol versions our SDK supports and test them with the clients we intend to use.

Architecture

Agent application / MCP client
             |
       HTTPS /mcp
             |
    Ingress -> service/mcp
             |
   gRPC with user's portal credential
             |
      service/apiserver
             |
 Existing storage and backend services

service/mcp handles the protocol, tool definitions, response formatting, and MCP authentication. It uses generated clients from gitlab.com/mergetb/api to call the API server through its gRPC interceptors and handlers. That gives us the existing caller lookup, request validation, portal policy, and maintenance-mode checks, along with each operation’s logging, hooks, and audit behavior. Portal storage and reconciliation stay behind that API.

We can package this through the existing build and container machinery and add a Kubernetes Deployment, Service, and ingress route. The service needs a public URL, the portal gRPC endpoint, authentication settings, and health probes. We’ll route /mcp to its own handler and configure TLS, protocol headers, Origin validation, and streaming support at the HTTP boundary.

Discovery and execution

Here’s how access would work in the first version:

Surface Access Content or behavior
Public documentation Anonymous Supported workflows, examples, endpoint address, and connection instructions.
OAuth discovery metadata Anonymous The authorization server and information the client needs to authenticate.
MCP tool discovery (tools/list) Authenticated Tool descriptions and schemas allowed by the client’s MCP grant.
Portal reads (tools/call) Authenticated and authorized Project data, experiment state, deployment status, and live inventory under portal policy.
Portal mutations (tools/call) Authenticated and authorized Operations allowed by both the MCP grant and portal policy.

If we later want agents to inspect tools before signing in, we can expose a public catalog from the same tool definitions. Protocol discovery requests and tools/list would become publicly accessible. Every portal tool call would still require authentication and authorization, including reads. The public catalog would explain what Merge can do; authenticated tools would return live resource data. We’d test that clients can move from anonymous discovery to login when they try to run a tool.

MCP methods share /mcp, so we’d handle that distinction inside the MCP service, checking access separately for listing and running tools. The specification allows the tool list to vary with the authorization on each request. A connector or plugin can set up the endpoint and manage login; our service checks the resulting credentials on protected requests.

Kratos and OAuth

Kratos manages portal identities and login sessions. Today, our HTTP gateway checks a Kratos session cookie. The gRPC API accepts a Kratos session token in its bearer metadata and checks it with Kratos to identify the caller. See Kratos session management.

OAuth lets a user grant an application access to a service with a defined scope. For remote MCP, we’d use an OAuth authorization server integrated with portal login. Our MCP service would act as the resource server, checking the access token’s issuer, intended audience, expiry, and scopes. Public protected-resource metadata and HTTP authentication challenges tell clients where to sign in. The MCP authorization specification defines this exchange.

To use the existing gRPC authentication path, we’d need two credentials: an OAuth token issued for MCP and a user-authorized Kratos session for portal calls. We’d link the verified OAuth issuer and subject to the verified Kratos identity, keep the portal credential in protected server-side storage, and use it for outgoing gRPC calls. Users would sign in and grant access through the application’s browser authentication flow. This follows MCP’s token audience guidance.

We should prove the authentication path first: authenticate an MCP client, link the user’s Kratos session, and make one portal call as that user. We still need to choose the OAuth provider and work out how the user grants that session, how we store it, and how expiry, revocation, and reconnection work. We’ll also need to check credential lifetime through asynchronous deployment stages. That linking is new work; the API already handles session validation and portal authorization. Each tool call must fit both the application’s OAuth scopes and the user’s current portal permissions.

What to build first

I’d start with tools to inspect projects and experiments and check realization, materialization, and deployment status. Each tool should take explicit identifiers and return bounded, structured results with useful error details. We can then add deployment creation and teardown through the existing Deploy API, which coordinates model, experiment, realization, materialization, and XDC operations. Each tool’s description should explain what it changes.

For long-running operations, the tool should return resource identifiers and report that the request was accepted. The client can then check progress, completion, or failure through status tools backed by the existing API. Before retrying a mutation, it should use those identifiers to check what already happened.

The implementation sequence would be:

  1. Prove authentication and account linking with one read tool and a target MCP client.
  2. Add the initial inspection tools and Kubernetes integration, then verify user isolation, policy enforcement, credential expiry, and API error handling.
  3. Add lifecycle tools and verify mutation permissions, asynchronous status reporting, and retry behavior.

i fully expect to revise this later, but any comments are welcome