micro/go-micro · error

topic is required

Error message

topic is required

What it means

The built-in broker "publish" MCP tool requires a non-empty "topic" parameter specifying where the message is published. An empty or missing topic fails the guard before broker.Connect/Publish is called; the "message" body may be empty.

Source

Thrown at gateway/mcp/mcp.go:545

			return map[string]interface{}{"status": "ok", "key": key}, nil
		},
	})

	addFramework(&Tool{
		Name:        "micro_broker_publish",
		Description: "Publish a message to a broker topic",
		InputSchema: map[string]interface{}{
			"type": "object",
			"properties": map[string]interface{}{
				"topic":   map[string]interface{}{"type": "string", "description": "Topic name"},
				"message": map[string]interface{}{"type": "string", "description": "Message body"},
			},
		},
		Handler: func(input map[string]interface{}) (interface{}, error) {
			topic, _ := input["topic"].(string)
			message, _ := input["message"].(string)
			if topic == "" {
				return nil, fmt.Errorf("topic is required")
			}
			b := broker.DefaultBroker
			if err := b.Connect(); err != nil {
				return nil, err
			}
			if err := b.Publish(topic, &broker.Message{Body: []byte(message)}); err != nil {
				return nil, err
			}
			return map[string]interface{}{"status": "ok", "topic": topic}, nil
		},
	})
}

// watchServices watches for service registry changes via the shared schema
// resolver and rebuilds the tool catalog on each change.
func (s *Server) watchServices() {
	if s.watching {
		return

View on GitHub (pinned to 24529f1404)

Solutions

  1. Pass a non-empty "topic" string: {"topic": "events.user.created", "message": "..."}.
  2. Validate the topic is non-empty in the client (and that it matches broker topic naming rules).
  3. Check that the value feeding the topic variable (config, env) is actually populated.

Example fix

// before
{"arguments": {"message": "hello"}}
// after
{"arguments": {"topic": "events.created", "message": "hello"}}
Defensive patterns

Strategy: validation

Validate before calling

topic, _ := input["topic"].(string)
if topic == "" {
    return errors.New("publish requires a non-empty 'topic' argument")
}

Type guard

func validPublishInput(input map[string]interface{}) (topic, message string, ok bool) {
    t, tOK := input["topic"].(string)
    m, _ := input["message"].(string)
    return t, m, tOK && t != ""
}

Try / catch

_, err := callTool("publish", map[string]interface{}{"topic": topic, "message": msg})
if err != nil {
    if strings.Contains(err.Error(), "topic is required") {
        // supply topic and retry
    }
}

Prevention

When it happens

Trigger: An MCP client calls the publish tool with input {} or {"topic": ""}; the handler returns "topic is required" without touching the broker.

Common situations: LLM omits the topic argument; topic string built from an empty config/env variable; caller mixed up topic and message parameter names.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/c57626de26f90109. Report an issue: GitHub.