Sidecar Integration¶
This document explains how a runtime can integrate MGP through a sidecar rather than a native SDK.
What a Sidecar Means Here¶
An MGP sidecar is a companion process that sits next to the runtime and handles:
- request shaping
- policy context injection
- gateway forwarding
- audit forwarding support
The runtime talks to the sidecar with a simpler local contract, and the sidecar speaks full MGP to the gateway.
This page describes the generic sidecar pattern, not a standardized sidecar wire protocol. For the concrete repository reference path, inspect integrations/nanobot/README.md.
When to Use a Sidecar¶
Use a sidecar when:
- the runtime is hard to modify internally
- you want a low-risk rollout path
- multiple runtimes should share one MGP integration layer
- you want policy context enrichment outside the runtime codebase
Use a native SDK when:
- you control the runtime internals
- you want full request lifecycle visibility inside the runtime
- you want fewer moving parts
Fastest Concrete Path¶
If you want to connect a real runtime with the least ambiguity:
- Read this page for the generic sidecar responsibilities and rollout model.
- Start the reference gateway with
make serve. - Run
make test-integrationsto validate the sidecar-facing tests in this repository. - Use
integrations/nanobot/README.mdfor the concrete harness, demo, and external-runtime validation flow.
Sidecar Responsibilities¶
- inject
policy_context - generate
request_id - forward requests to the MGP gateway
- normalize errors back to the runtime
- optionally forward audit metadata or runtime correlation IDs
- support staged rollout modes such as
off,shadow, andprimary
Architecture¶
graph TD
subgraph runtime [Runtime]
AgentLoop[AgentLoop]
LocalClient[LocalClient]
end
subgraph sidecar [MGP Sidecar]
ContextInject[ContextInject]
RequestMap[RequestMap]
AuditForward[AuditForward]
end
subgraph gateway [MGP Gateway]
HttpApi[HttpApi]
end
AgentLoop --> LocalClient
LocalClient --> ContextInject
ContextInject --> RequestMap
RequestMap --> HttpApi
RequestMap --> AuditForward
Policy Context Injection¶
The sidecar should enrich requests with:
actor_agentacting_for_subjecttenant_idtask_idtask_typerisk_level
Mapping note:
- use
task_idfor runtime workflow or execution correlation - do not confuse it with the protocol async task object used by
/mgp/tasks/getand/mgp/tasks/cancel - keep
session_idfor conversation identity when the runtime has both concepts
Possible sources:
- runtime process metadata
- session store
- request headers from an upstream application
- local config
Rollout Modes¶
Sidecar adoption should be staged instead of immediate cutover.
off: do not call MGP; preserve runtime behavior exactlyshadow: call MGP, but do not feed recall into the prompt or runtime decision pathprimary: call MGP and allow usable recall to influence prompt construction
Recommended rollout order:
- sidecar-only validation
- runtime proof of concept on a minimal entrypoint such as
integrations/minimal_runtime/ shadowmode in a real sessionprimarymode after quality and latency checks
Related repository paths:
integrations/nanobot/for the concrete sidecar reference pathintegrations/minimal_runtime/for the smallest copyable runtime bridgeintegrations/langgraph/for a mainstream framework-shaped state integration sketch
Fail-Open Requirement¶
For early integrations, the sidecar should fail open:
SearchMemoryfailure should not block the user replyWriteMemoryfailure should not break turn persistence- sidecar unavailability should fall back to the runtime's native memory path
Audit Forwarding¶
The runtime may emit its own trace or correlation identifiers that are useful to preserve.
The sidecar can:
- add those identifiers to
request_id - inject them into sidecar-local logs
- associate them with gateway audit output
Recommended Request Flow¶
- Runtime sends a local memory intent to the sidecar.
- Sidecar resolves runtime state into
policy_context. - Sidecar builds a valid MGP request envelope.
- Sidecar forwards the request to the MGP gateway.
- Sidecar translates the response into a runtime-friendly local result.
Non-Goals¶
This document does not define:
- a sidecar wire protocol
- service mesh integration
- sidecar deployment tooling