Skip to content

feat(mcp): mesh_publish tool — surface publish_to / publish_to_direct (#56) - #57

Merged
hartsock merged 1 commit into
mainfrom
feat/mesh-publish-tool
Jul 12, 2026
Merged

feat(mcp): mesh_publish tool — surface publish_to / publish_to_direct (#56)#57
hartsock merged 1 commit into
mainfrom
feat/mesh-publish-tool

Conversation

@hartsock

Copy link
Copy Markdown
Member

What this PR does

Surfaces the bus's fire-and-forget pub/sub primitives (Bus::publish_to /
Bus::publish_to_direct) through amesh mcp — previously reachable only
from the Python bindings. Follow-up to #52's out-of-scope note; closes #56.

  • New mesh_publish tool — publish a body to a peer on a topic,
    fire-and-forget (no reply). The peer's bus fans it out to its topic
    subscribers. Same dual-mode peer naming as mesh_request: peer (resolve
    over mDNS → publish_to) OR addr+pubkey (direct dial →
    publish_to_direct, no discovery).
  • Refactor: the peer-naming resolution (peer xor addr+pubkey + its
    validation) and topic/body extraction are factored out of tool_request
    into shared peer_route / topic_and_body helpers (with a small
    McpPeerRoute enum), so mesh_request and mesh_publish name peers
    identically and can't drift.

amesh listen is not a bus subscriber (raw Endpoint::accept, bypassing the
inbox), so there is no CLI publish verb — the coherent surface is the tool.

Test plan

Local: just check + just cov-ci (75% floor) green on Windows.

  • New mcp_server_direct_addr_publishes_to_subscriber
    (agent-mesh-cli/tests/mcp_stdio.rs) — real amesh mcp subprocess
    publishes to an in-process quiet-bound subscriber Bus by explicit
    addr+pubkey over loopback QUIC (no multicast); the subscriber's
    topic broadcast::Receiver receives the body. Subscribe-before-publish
    makes it deterministic; ran 5× back to back, ~0.3s each.
  • New mcp.rs unit tests: mesh_publish rejects neither-peer-nor-addr
    and half-specified direct args (confirms it routes through the shared
    helper). Existing mesh_request validation tests still pass unchanged.
  • Updated tools/list assertions (4 tools now) in mcp.rs + mcp_stdio.rs.
  • cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --all -- --check — all clean.

Out of scope

  • An MCP mesh_subscribe (streaming server→client notifications) — a
    larger, separate feature.
  • A CLI amesh publish verb (no CLI subscriber exists to receive it).
  • Any change to the resolve/discovery path.

Refs #56, #52.

…r direct dial (#56)

Surfaces the bus's `publish_to` / `publish_to_direct` primitives through
`amesh mcp` (they were reachable only from the Python bindings). Follow-up
to #52's out-of-scope note.

- New `mesh_publish` tool: publish a body to a peer on a topic,
  fire-and-forget (no reply awaited). The peer's bus fans it out to its
  topic subscribers. Same dual-mode peer naming as `mesh_request` — `peer`
  (resolve over mDNS → `publish_to`) or `addr`+`pubkey` (direct dial →
  `publish_to_direct`, no discovery).
- Factors the peer-naming resolution (`peer` xor `addr`+`pubkey`, plus its
  validation) and the topic/body extraction out of `tool_request` into
  shared `peer_route` / `topic_and_body` helpers, so `mesh_request` and
  `mesh_publish` name peers identically and their rules can't drift. A small
  `McpPeerRoute` enum carries the resolved route.

Tests (all deterministic, no multicast):

- New `mcp_server_direct_addr_publishes_to_subscriber`
  (`agent-mesh-cli/tests/mcp_stdio.rs`) — real `amesh mcp` subprocess
  publishes to an in-process quiet-bound subscriber `Bus` by explicit
  `addr`+`pubkey` over loopback QUIC; the subscriber's topic
  `broadcast::Receiver` receives the body. Ran 5× back to back, ~0.3s each.
- New `mcp.rs` unit tests: `mesh_publish` rejects neither-peer-nor-addr and
  half-specified direct args (confirming it routes through the shared
  helper).
- Updated the `tools/list` assertions (now 4 tools) in `mcp.rs` and
  `mcp_stdio.rs`.

Closes #56.

Co-authored-by: Claude Opus 4.8 <[email protected]>
@hartsock
hartsock merged commit 237aa1d into main Jul 12, 2026
6 checks passed
@hartsock
hartsock deleted the feat/mesh-publish-tool branch July 12, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mcp): mesh_publish tool — surface publish_to / publish_to_direct (fire-and-forget pub/sub)

1 participant