项目文件夹

文件
Asim Aslam 96280678ee Expose framework primitives via API gateway and MCP with auth control (#2925)
* feat: expose framework primitives via API gateway and MCP

Add registry, store, and broker as both HTTP routes and MCP tools
so AI agents and HTTP clients can inspect and operate the framework.

API gateway (/micro/* namespace):
  GET  /micro/registry         List registered services
  GET  /micro/registry/{name}  Describe a service
  GET  /micro/store            List store keys
  GET  /micro/store/{key}      Read a record
  POST /micro/store/{key}      Write a record
  POST /micro/broker/{topic}   Publish a message

MCP gateway (micro_* tool prefix):
  micro_registry_list    List services
  micro_registry_get     Describe a service
  micro_store_list       List keys
  micro_store_read       Read a record
  micro_store_write      Write a record
  micro_broker_publish   Publish a message

Framework tools use a Handler field on the MCP Tool struct for
direct dispatch (no RPC). Service tools continue to use RPC.
Rate limiters and circuit breakers are applied to framework
tools the same as service tools.

* fix: make framework internals opt-in on API and MCP gateways

Framework primitives (registry, broker, store) are now only
exposed when explicitly enabled:

API gateway:  micro api --internal
MCP gateway:  Options{Internal: true}

Off by default — user services are always exposed, framework
internals require the flag. Banner output only shows framework
routes when enabled.

* fix: always expose framework internals, gate by auth in production

Revert the --internal flag approach. Framework primitives (registry,
broker, store) are now always exposed:

- micro api: /micro/* routes always available (dev tool)
- MCP gateway: micro_* tools always registered. When Auth is
  configured (production), they require micro:admin scope.
  Without Auth (dev), they're open — same as all other tools.

This follows the existing pattern: micro run/api = dev (open),
micro server = production (auth + scopes). Framework internals
follow the same security model as user services.

Remove the Internal option from MCP Options. Remove --internal
flag from micro api.

Note: scope persistence depends on the store backend. The default
in-memory store does not survive restarts. Use MICRO_STORE=file
for persistent scopes in production.

* fix: correct DefaultStore comment — it's file-backed, not memory

* fix(server): don't recreate deleted admin user on restart

When the default admin account is deleted via the dashboard, set
a marker key (auth/.admin-deleted) in the store. On startup, skip
admin creation if the marker exists. This prevents the default
admin/micro credentials from reappearing after restart when the
user has intentionally removed them.

* fix: improve agent playground first-run UX and fix doc 404s

Agent playground:
- Add setup hint in empty state explaining how to get started
  (click Settings, enter API key, type a prompt)
- Hide hint automatically when API key is already configured
- Add all 7 providers to dropdown (was only OpenAI + Anthropic)
- Include CLI fallback suggestion (micro chat)

Docs:
- Fix .md links to .html across all doc pages — Jekyll serves
  .html files, not .md. Fixes 404s including the micro run guide.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-03 11:05:51 +01:00

3.4 KiB

layout
layout
default

Plugins

Plugins are scoped under each interface directory within this repository. To use a plugin, import it directly from the corresponding interface subpackage and pass it to your service via options.

Common interfaces and locations:

  • Registry: go-micro.dev/v5/registry/* (e.g. consul, etcd, nats, mdns)
  • Broker: go-micro.dev/v5/broker/* (e.g. nats, rabbitmq, http, memory)
  • Transport: go-micro.dev/v5/transport/* (e.g. nats, default http)
  • Server: go-micro.dev/v5/server/* (e.g. grpc for native gRPC compatibility)
  • Client: go-micro.dev/v5/client/* (e.g. grpc for native gRPC compatibility)
  • Store: go-micro.dev/v5/store/* (e.g. postgres, mysql, nats-js-kv, memory)
  • Auth, Cache, etc. follow the same pattern under their respective directories.

Registry Examples

Consul:

import (
    "go-micro.dev/v5"
    "go-micro.dev/v5/registry/consul"
)

func main() {
    reg := consul.NewConsulRegistry()
    svc := micro.NewService(
        micro.Registry(reg),
    )
    svc.Init()
    svc.Run()
}

Etcd:

import (
    "go-micro.dev/v5"
    "go-micro.dev/v5/registry/etcd"
)

func main() {
    reg := etcd.NewRegistry()
    svc := micro.NewService(micro.Registry(reg))
    svc.Init()
    svc.Run()
}

Broker Examples

NATS:

import (
    "go-micro.dev/v5"
    bnats "go-micro.dev/v5/broker/nats"
)

func main() {
    b := bnats.NewNatsBroker()
    svc := micro.NewService(micro.Broker(b))
    svc.Init()
    svc.Run()
}

RabbitMQ:

import (
    "go-micro.dev/v5"
    "go-micro.dev/v5/broker/rabbitmq"
)

func main() {
    b := rabbitmq.NewBroker()
    svc := micro.NewService(micro.Broker(b))
    svc.Init()
    svc.Run()
}

Transport Example (NATS)

import (
    "go-micro.dev/v5"
    tnats "go-micro.dev/v5/transport/nats"
)

func main() {
    t := tnats.NewTransport()
    svc := micro.NewService(micro.Transport(t))
    svc.Init()
    svc.Run()
}

gRPC Server/Client (Native gRPC Compatibility)

For native gRPC compatibility (required for grpcurl, polyglot gRPC clients, etc.), use the gRPC server and client plugins. Note: This is different from the gRPC transport.

import (
    "go-micro.dev/v5"
    grpcServer "go-micro.dev/v5/server/grpc"
    grpcClient "go-micro.dev/v5/client/grpc"
)

func main() {
    svc := micro.NewService(
        micro.Server(grpcServer.NewServer()),
        micro.Client(grpcClient.NewClient()),
    )
    svc.Init()
    svc.Run()
}

See Native gRPC Compatibility for a complete guide.

Store Examples

Postgres:

import (
    "go-micro.dev/v5"
    postgres "go-micro.dev/v5/store/postgres"
)

func main() {
    st := postgres.NewStore()
    svc := micro.NewService(micro.Store(st))
    svc.Init()
    svc.Run()
}

NATS JetStream KV:

import (
    "go-micro.dev/v5"
    natsjskv "go-micro.dev/v5/store/nats-js-kv"
)

func main() {
    st := natsjskv.NewStore()
    svc := micro.NewService(micro.Store(st))
    svc.Init()
    svc.Run()
}

Notes

  • Defaults: If you don’t set an implementation, Go Micro uses sensible in-memory or local defaults (e.g., mDNS for registry, HTTP transport, memory broker/store).
  • Options: Each plugin exposes constructor options to configure addresses, credentials, TLS, etc.
  • Imports: Only import the plugin you need; this keeps binaries small and dependencies explicit.