Skip to content

MCP: gateway-driven port coordination#6007

Merged
Grantim merged 2 commits intomasterfrom
mcp-port-coordination
Apr 29, 2026
Merged

MCP: gateway-driven port coordination#6007
Grantim merged 2 commits intomasterfrom
mcp-port-coordination

Conversation

@Grantim
Copy link
Copy Markdown
Contributor

@Grantim Grantim commented Apr 29, 2026

Summary

  • Gateway forwards -mcpPort N to spawned MI (configurable via --mcp-port, default 7887). When --target-url is omitted, the gateway's probe URL derives from the same port — so --mcp-port 8888 is enough to move the whole loop off 7887.
  • MI parses -mcpPort early in setupMcp (new Mcp::parseCmdLineOverrides helper), forces the server port + auto-start, and shows the port read-only in Settings → MCP with a tooltip explaining why.
  • -mcpDumpFile now suppresses server start so the gateway's cache-prime spawn never briefly binds the port (would collide with a live backend).
  • Drops Server::processCmdArgs (only called from setupMcp).

Test plan

  • Manual prime: MeshInspector.exe -mcpDumpFile out.json -noEventLoop -hidden → 30 tools written, no MCP server started log line.
  • Manual launch: MeshInspector.exe -mcpPort 9999 -noEventLoop -tryHidden → log shows MCP server started on port 9999.
  • End-to-end gateway: MRMCPGateway --mcp-port 8888 --launch-cmd MeshInspector.exe primes the cache by spawning MI with -mcpPort 8888 -mcpDumpFile <cache>. Then tools/call launch spawns MI on 8888; Settings → MCP shows port 8888 read-only with tooltip Port forced by -mcpPort command-line flag.
  • No-flag launch: MeshInspector.exe — config-driven path unchanged.

🤖 Generated with Claude Code

Gateway now forwards -mcpPort N to spawned MI (configurable via --mcp-port,
default 7887). MI's setupMcp parses the flag, forces the server port and
auto-start (overriding the mcp.enableByDefault config), and shows the port
read-only in Settings. -mcpDumpFile additionally suppresses server start so
the gateway's cache-prime spawn never briefly binds the port.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread source/MRMcp/MRMcp.h Outdated
[[nodiscard]] MRMCP_API Server& getDefaultServer();

/// Overrides parsed from the application's command-line arguments. Sentinel values
/// (`port <= 0`, empty `dumpFilePath`) mean "no override".
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.

Let's move this to MRMcpSettings. See my next comment for more details.

return false;
#endif
}

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.

Put parseCmdLineOverrides in this file, hidden in the .cpp (don't expose to the header).

Make getPort() respect the override, and make setPort() do nothing if the override exists.

Maybe add another function here from the dump file path (not sure if it should be in this file or elsewhere).


// Push the effective port (CLI override beats config).
Mcp::Server::Params params = server.getParams();
params.port = overrides.port > 0 ? overrides.port : McpSettings::getPort();
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.

This logic should be in McpSettings::getPort() IMO.

Pure code motion — colocates CLI-flag parsing with the settings layer
(its only consumer). MRMcp public surface stays focused on the Server.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Grantim Grantim merged commit 79e77ff into master Apr 29, 2026
35 checks passed
@Grantim Grantim deleted the mcp-port-coordination branch April 29, 2026 13:40
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.

3 participants