mcphub
AGENTS.md2 starsChanged 11 months agoMITView on GitHub
Server mode (mh serve -c config.json): Starts an MCP hub server that aggregates multiple backend servers. AI clients connect to the hub. CLI mode (mh list, mh inspect, mh invoke, mh exec): Interact with MCP servers directly from terminal. Flags come after the subcommand: -c for config file, -u for remote URL, or --stdio for subprocess. Skill mode: Two workflows for extending agent capabilities: Server and CLI modes share connection logic in internal/cli/ (config_client, remote, stdio_client). Server mode flow: CLI…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,337 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
We split this AGENTS.md into the rules it gives an agent
10 rules. About 0 are common, 0 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 42
Generate skills: Use mcp-skill-gen workflow to create skill files from MCP servers.
- Very specific: line 53
Start MCP server on stdio/http/sse, expose aggregated tools → internal/server/
- Very specific: line 59
Create appropriate client → internal/cli/{config_client,remote,stdio_client}.go
- Very specific: line 67
Tool namespacing: All backend tools are prefixed with server name in camelCase to avoid conflicts (githubSearch not search)
- Very specific: line 75
All non-main packages live in internal/ (not importable externally)
- Very specific: line 76
Every package should have *_test.go files with meaningful coverage
- Very specific: line 77
Use structured logging via internal/logging - no fmt.Println for runtime messages
- Very specific: line 93
Adding a new CLI command: Create file in internal/cli/, register in main.go
- Very specific: line 95
Adding a built-in tool: Add to internal/tools/builtin.go, implement handler, add tests
- Very specific: line 99
Modifying config schema: Update structs in internal/config/config.go, add validation, update tests
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MCP Hub Agent Instructions
Naming Convention
- Product name: MCP Hub (for docs and display)
- CLI command:
mh(following theghpattern) - Go module:
mcphub
Commands
mise run build # Build binary to bin/mh
mise run test # Run all tests with coverage
mise run run # Build and run with example config
mise run format # Format code (go fmt, go mod tidy)Project Structure
main.go # CLI entry point (cobra)
internal/
├── cli/ # Subcommands: serve, list, inspect, invoke, exec, update
├── server/ # MCP hub server - aggregates tools, handles requests
├── client/ # Remote MCP client manager - connections, reconnection logic
├── config/ # Configuration loading and validation
├── tools/ # Built-in tools: search, execute, refreshTools
├── js/ # Goja JavaScript runtime for execute tool
├── transport/ # Transport factory: stdio, http, sse
└── logging/ # Structured logging with zapThree Modes
Server mode (mh serve -c config.json): Starts an MCP hub server that aggregates multiple backend servers. AI clients connect to the hub.
CLI mode (mh list, mh inspect, mh invoke, mh exec): Interact with MCP servers directly from terminal. Flags come after the subcommand: -c for config file, -u for remote URL, or --stdio for subprocess.
Skill mode: Two workflows for extending agent capabilities:
- Discover skills:
mh skills find/addto browse and install from skills.sh - Generate skills: Use
mcp-skill-genworkflow to create skill files from MCP servers. AI agents read the skill, then usemhCLI to discover/invoke tools on-demand. Keeps context small while accessing hundreds of tools.
Server and CLI modes share connection logic in internal/cli/ (config_client, remote, stdio_client).
Architecture Overview
Server mode flow:
- Load and validate config →
internal/config/ - Connect to each MCP server (stdio subprocess or http/sse client) →
internal/client/+internal/transport/ - Discover tools from each server, namespace them (camelCase:
serverNameToolName) - Start MCP server on stdio/http/sse, expose aggregated tools →
internal/server/ - Route incoming tool calls to appropriate backend, return results
CLI mode flow:
- Parse connection source (config/url/stdio) →
internal/cli/helpers.go - Create appropriate client →
internal/cli/{config_client,remote,stdio_client}.go - Execute command (list/inspect/invoke) using
internal/tools/core functions - Format and print output
Built-in tools (search, execute, refreshTools) are registered in internal/tools/ and don't go through backends.
Key Design Decisions
- Tool namespacing: All backend tools are prefixed with server name in camelCase to avoid conflicts (
githubSearchnotsearch) - Sync-only JS: The
executetool blocks async to prevent complexity and security issues (no Promises, no setTimeout) - Transport abstraction:
internal/transport/provides unified interface for stdio/http/sse so client code doesn't care about transport type - Fail-open by default: Servers with
required: false(default) won't block hub startup if they fail to connect
Code Style
- Go 1.23+, standard gofmt formatting
- All non-main packages live in
internal/(not importable externally) - Every package should have
*_test.gofiles with meaningful coverage - Use structured logging via
internal/logging- nofmt.Printlnfor runtime messages - Error messages should be lowercase, no trailing punctuation
- Context should flow through all blocking operations
Testing
go test ./... # Run all tests
go test -cover ./... # With coverage
go test -v ./internal/js # Verbose, specific packageFor integration tests, see docs/testing.md which documents the built-in test server.
Common Tasks
Adding a new CLI command: Create file in internal/cli/, register in main.go
Adding a built-in tool: Add to internal/tools/builtin.go, implement handler, add tests
Supporting new transport: Implement Transport interface in internal/transport/, register in factory
Modifying config schema: Update structs in internal/config/config.go, add validation, update tests
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

