Skip to content

Move network diagnostics from MCP tools to /debug REST endpoints + sam-node debug CLI - #330

Merged
aojea merged 1 commit into
google:mainfrom
kaisoz:kaisoz/move-network-admin-mcp-tools-to-admin-rest-endpo
Sep 1, 2026
Merged

Move network diagnostics from MCP tools to /debug REST endpoints + sam-node debug CLI#330
aojea merged 1 commit into
google:mainfrom
kaisoz:kaisoz/move-network-admin-mcp-tools-to-admin-rest-endpo

Conversation

@kaisoz

@kaisoz kaisoz commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Fixes #318.

The node's MCP server exposed 16 tools to every connected agent, five of which are operator diagnostics, not mesh usage. This PR removes those five from the agent-facing tool list and re-exposes them as REST endpoints under /debug on the sidecar mux (following the /debug naming discussed in the issue), plus a sam-node debug command group that reaches them over the node's Unix socket.

Endpoints

Endpoint Replaces MCP tool CLI subcommand What it touches Network I/O Behavior while disconnected from the mesh
GET /debug/mesh-info (none — get_mesh_info stays an MCP tool; this is the operator's view of the same data) sam-node debug mesh-info Host.Network().Peers() (in-memory connection table), DHT.RoutingTable().Size(), RouterPeerID, BoundSocketPath none Works; honestly reports 0 connected peers
GET /debug/connectivity[?peer_id=…] check_connectivity sam-node debug connectivity [peer-id] Dials the SAM router (or the given peer) via Host.Connect and measures latency one bounded dial Works; this is exactly the state it exists to diagnose (router_error_msg, ping_latency_ms)
GET /debug/network-info get_network_info sam-node debug network-info Host.Network().ListenAddresses(), Host.Addrs() none Works; purely local address lists
GET /debug/token-info get_token_info sam-node debug token-info Store.LoadIdentity() / LoadIdentityExpiration() (local store) none Works; answers "am I disconnected because my token expired?"
GET /debug/logs get_recent_logs sam-node debug logs In-process log ring buffer none Works; purely local
POST /debug/connect-peer connect_peer sam-node debug connect-peer <multiaddr> Host.Connect to the given multiaddr; revoked-peer and banned-peer checks kept from the tool handler one outbound dial Works; it is the manual recovery action for a node that lost its router — a direct dial to an explicit address needs no router

Auth and gating

  • All six endpoints sit behind withAuth(token, allowAuthorizationFallback=true, …)
  • They deliberately do not get withMeshConnection: four endpoints are pure local reads, and the two that dial take a concrete address and do one bounded attempt whose error is the diagnostic output. Gating them 503s exactly when an operator needs them.
  • Previously the five tools were behind withMeshConnection only incidentally, because all MCP traffic shares the "/" route on the sidecar mux — diagnostics were unusable on a disconnected node. Moving them to /debug makes that gating decision explicit.

CLI

sam-node debug <subcommand> talks HTTP over the Unix socket (--socket-path, defaulting to <data-dir>/sam.sock like run), so the socket's 0600 permissions are the credential and no token appears anywhere. Output is the endpoint's raw JSON, so it composes with jq. Root help grows by one entry regardless of how many diagnostics are added later.

$ sam-node debug connectivity
{"connected_peers":3,"router_error":false,"router_latency_ms":2,"total_known_peers":14}
$ sam-node debug connect-peer /ip4/10.0.0.5/tcp/5002/p2p/12D3Koo...
{"status":"connected"}

@kaisoz
kaisoz requested a review from aojea August 31, 2026 15:18

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates operator diagnostics and debug utilities (such as mesh info, connectivity stats, token info, network info, and peer connection) from MCP tools to dedicated HTTP endpoints served over a Unix socket. The corresponding MCP tools have been removed, and integration tests have been updated to use the new REST endpoints. The review feedback highlights several potential nil pointer dereference panics across the new debug handler methods (meshInfo, connectivityStats, tokenInfo, networkInfo, and connectPeer) where n.Host, n.DHT, or n.Store are accessed without prior nil checks.

Comment thread internal/node/debug_handlers.go
Comment thread internal/node/debug_handlers.go
Comment thread internal/node/debug_handlers.go
Comment thread internal/node/debug_handlers.go
Comment thread internal/node/debug_handlers.go
@kaisoz
kaisoz force-pushed the kaisoz/move-network-admin-mcp-tools-to-admin-rest-endpo branch from 2de3a7c to d53f636 Compare August 31, 2026 15:52
@aojea

aojea commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request moves operator diagnostics (such as mesh-info, connectivity, network-info, token-info, and logs) from MCP tools to dedicated /debug HTTP endpoints served over a Unix socket, making them invisible to agents and accessible even when the mesh is unreachable. Feedback focuses on adding defensive checks across the new debug handler methods to prevent potential nil pointer dereferences on uninitialized fields (such as Host, DHT, or Store). Additionally, it is recommended to enforce timeouts on connection contexts to prevent indefinite blocking and to validate that the socket path is not empty before dialing.

Comment thread internal/node/debug_handlers.go
Comment thread internal/node/debug_handlers.go
Comment thread internal/node/debug_handlers.go
Comment thread internal/node/debug_handlers.go
Comment thread internal/node/debug_handlers.go
Comment thread cmd/sam-node/debug.go
@aojea

aojea commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

it needs rebase

Comment thread internal/node/mcp.go
@kaisoz
kaisoz force-pushed the kaisoz/move-network-admin-mcp-tools-to-admin-rest-endpo branch from d53f636 to e35a905 Compare September 1, 2026 06:01
@kaisoz

kaisoz commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@kaisoz
kaisoz force-pushed the kaisoz/move-network-admin-mcp-tools-to-admin-rest-endpo branch from e35a905 to 42da772 Compare September 1, 2026 06:10

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request moves operator diagnostics (such as logs, connectivity, network/token info, and peer connections) out of the Model Context Protocol (MCP) tools list and into dedicated /debug/ REST endpoints. This prevents agents from seeing these diagnostic tools in their tool list. A new sam-node debug CLI command has been introduced to interact with these endpoints, and tests and documentation have been updated accordingly. Feedback includes pre-allocating the connectedPeers slice in debug_handlers.go to avoid serializing to null when empty, and using a lightweight curlimages/curl container instead of python:3.12 in E2E tests to improve execution speed.

Comment thread internal/node/debug_handlers.go Outdated
Comment thread tests/e2e/lib/container_mesh.bash
Remove the five operator-diagnostic MCP tools (connect_peer,
check_connectivity, get_network_info, get_token_info, get_recent_logs)
from the agent-facing MCP server and re-expose them as /debug REST
endpoints on the sidecar mux, behind withAuth but not withMeshConnection
so they keep answering while the mesh is unreachable. get_mesh_info
stays as an MCP tool and gains GET /debug/mesh-info for operators.

Add a 'sam-node debug' command group with one subcommand per endpoint,
talking to the node over its Unix socket so no token is needed.

Fixes google#318
@kaisoz
kaisoz force-pushed the kaisoz/move-network-admin-mcp-tools-to-admin-rest-endpo branch from 42da772 to 1f984a0 Compare September 1, 2026 06:15
@aojea
aojea merged commit 6666ce3 into google:main Sep 1, 2026
20 checks passed
@aojea

aojea commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

now A2A and we are moving to beta , go go go 💪

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.

Move network/admin MCP tools to /admin REST endpoints + sam-node admin CLI

2 participants