agentleFS
28672032962867203296/hermes-agent/skills/mcp/native-mcp/SKILL.md

native-mcp

Skill0 starsChanged 3 months agoMITView on GitHub

MCP client: connect servers, register tools (stdio/HTTP).

  • Reads credentials
  • Installs packages

12 other projects use a version of this, 11 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use songwriting-and-ai-music.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Tommy-ywSkill

    songwriting-and-ai-music

    Songwriting craft, AI music generation prompts (Suno focus), parody/adaptation techniques, phonetic tricks, and lessons learned. These are tools and ideas, not rules. Break any of them when the art calls for it.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. 8 are common, 1 is distinctive, and 7 are very specific to this project.

  • 8

    Common

    Most of the 12 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Common:

    Use this whenever you want to:

    line 20
  2. Common:

    Add external capabilities (filesystem access, GitHub, databases, APIs) via MCP

    line 22
  3. Common:

    Run local stdio-based MCP servers (npx, uvx, or any command)

    line 23
  4. Very specific:

    Add MCP servers to ~/.hermes/config.yaml under the mcp_servers key:

    line 45
  5. Very specific:

    When Hermes Agent starts, discover_mcp_tools() is called during tool initialization:

    line 109
  6. Very specific:

    After discovery, MCP tools are automatically injected into all hermes-* platform toolsets (CLI, Discord, Telegram, etc.).

    line 133
  7. Common:

    If a connection drops, automatic reconnection with exponential backoff kicks in (up to 5 retries, max 60s backoff)

    line 139
  8. Very specific:

    If HTTP support is not available in your installed mcp version, the server will fail with an ImportError and other servers will continue …

    line 173
  9. Very specific:

    All other environment variables (API keys, tokens, secrets) are excluded unless you explicitly add them via the env config key.

    line 184
  10. Common:

    If an MCP tool call fails, any credential-like patterns in the error message are automatically redacted before being shown to the LLM.

    line 198
  11. Very specific:

    Check that the server is listed under mcp_servers (not mcp or servers)

    line 237
  12. Common:

    Ensure the YAML indentation is correct

    line 238
  13. Common:

    Look at Hermes Agent startup logs for connection messages

    line 239
  14. Distinctive:

    After restart, the startup probe has enough headroom.

    line 273
  15. Very specific:

    Workaround: When using auth: header, hardcode the actual API key directly in config.yaml rather than using ${VAR} placeholders.

    line 282
  16. Common:

    All tools from all servers are registered and available simultaneously.

    line 388

“Common” is measured: kept by at least 6 in 10 of the 12 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Native MCP Client

Hermes Agent has a built-in MCP client that connects to MCP servers at startup, discovers their tools, and makes them available as first-class tools the agent can call directly. No bridge CLI needed -- tools from MCP servers appear alongside built-in tools like terminal, read_file, etc.

When to Use

Use this whenever you want to:

  • Connect to MCP servers and use their tools from within Hermes Agent
  • Add external capabilities (filesystem access, GitHub, databases, APIs) via MCP
  • Run local stdio-based MCP servers (npx, uvx, or any command)
  • Connect to remote HTTP/StreamableHTTP MCP servers
  • Have MCP tools auto-discovered and available in every conversation

For ad-hoc, one-off MCP tool calls from the terminal without configuring anything, see the mcporter skill instead.

Prerequisites

  • mcp Python package -- optional dependency; install with pip install mcp. If not installed, MCP support is silently disabled.
  • Node.js -- required for npx-based MCP servers (most community servers)
  • uv -- required for uvx-based MCP servers (Python-based servers)

Install the MCP SDK:

pip install mcp
# or, if using uv:
uv pip install mcp

Quick Start

Add MCP servers to ~/.hermes/config.yaml under the mcp_servers key:

mcp_servers:
  time:
    command: "uvx"
    args: ["mcp-server-time"]

Restart Hermes Agent. On startup it will:

  1. Connect to the server
  2. Discover available tools
  3. Register them with the prefix mcp_time_*
  4. Inject them into all platform toolsets

You can then use the tools naturally -- just ask the agent to get the current time.

Configuration Reference

Each entry under mcp_servers is a server name mapped to its config. There are two transport types: stdio (command-based) and HTTP (url-based).

Stdio Transport (command + args)

mcp_servers:
  server_name:
    command: "npx"             # (required) executable to run
    args: ["-y", "pkg-name"]   # (optional) command arguments, default: []
    env:                       # (optional) environment variables for the subprocess
      SOME_API_KEY: "value"
    timeout: 120               # (optional) per-tool-call timeout in seconds, default: 120
    connect_timeout: 60        # (optional) initial connection timeout in seconds, default: 60

HTTP Transport (url)

mcp_servers:
  server_name:
    url: "https://my-server.example.com/mcp"   # (required) server URL
    headers:                                     # (optional) HTTP headers
      Authorization: "Bearer sk-..."
    timeout: 180               # (optional) per-tool-call timeout in seconds, default: 120
    connect_timeout: 60        # (optional) initial connection timeout in seconds, default: 60

All Config Options

OptionTypeDefaultDescription
commandstring--Executable to run (stdio transport, required)
argslist[]Arguments passed to the command
envdict{}Extra environment variables for the subprocess
urlstring--Server URL (HTTP transport, required)
headersdict{}HTTP headers sent with every request
timeoutint120Per-tool-call timeout in seconds
connect_timeoutint60Timeout for initial connection and discovery

Note: A server config must have either command (stdio) or url (HTTP), not both.

How It Works

Startup Discovery

When Hermes Agent starts, discover_mcp_tools() is called during tool initialization:

  1. Reads mcp_servers from ~/.hermes/config.yaml
  2. For each server, spawns a connection in a dedicated background event loop
  3. Initializes the MCP session and calls list_tools() to discover available tools
  4. Registers each tool in the Hermes tool registry

Tool Naming Convention

MCP tools are registered with the naming pattern:

mcp_{server_name}_{tool_name}

Hyphens and dots in names are replaced with underscores for LLM API compatibility.

Examples:

  • Server filesystem, tool read_file → mcp_filesystem_read_file
  • Server github, tool list-issues → mcp_github_list_issues
  • Server my-api, tool fetch.data → mcp_my_api_fetch_data

Auto-Injection

After discovery, MCP tools are automatically injected into all hermes-* platform toolsets (CLI, Discord, Telegram, etc.). This means MCP tools are available in every conversation without any additional configuration.

Connection Lifecycle

  • Each server runs as a long-lived asyncio Task in a background daemon thread
  • Connections persist for the lifetime of the agent process
  • If a connection drops, automatic reconnection with exponential backoff kicks in (up to 5 retries, max 60s backoff)
  • On agent shutdown, all connections are gracefully closed

Idempotency

discover_mcp_tools() is idempotent -- calling it multiple times only connects to servers that aren't already connected. Failed servers are retried on subsequent calls.

Transport Types

Stdio Transport

The most common transport. Hermes launches the MCP server as a subprocess and communicates over stdin/stdout.

mcp_servers:
  filesystem:
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"]

The subprocess inherits a filtered environment (see Security section below) plus any variables you specify in env.

HTTP / StreamableHTTP Transport

For remote or shared MCP servers. Requires the mcp package to include HTTP client support (mcp.client.streamable_http).

mcp_servers:
  remote_api:
    url: "https://mcp.example.com/mcp"
    headers:
      Authorization: "Bearer sk-..."

If HTTP support is not available in your installed mcp version, the server will fail with an ImportError and other servers will continue normally.

Security

Environment Variable Filtering

For stdio servers, Hermes does NOT pass your full shell environment to MCP subprocesses. Only safe baseline variables are inherited:

  • PATH, HOME, USER, LANG, LC_ALL, TERM, SHELL, TMPDIR
  • Any XDG_* variables

All other environment variables (API keys, tokens, secrets) are excluded unless you explicitly add them via the env config key. This prevents accidental credential leakage to untrusted MCP servers.

mcp_servers:
  github:
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-github"]
    env:
      # Only this token is passed to the subprocess
      GITHUB_PERSONAL_ACCESS_TOKEN: "ghp_..."

Credential Stripping in Error Messages

If an MCP tool call fails, any credential-like patterns in the error message are automatically redacted before being shown to the LLM. This covers:

  • GitHub PATs (ghp_...)
  • OpenAI-style keys (sk-...)
  • Bearer tokens
  • Generic token=, key=, API_KEY=, password=, secret= patterns

Troubleshooting

"MCP SDK not available -- skipping MCP tool discovery"

The mcp Python package is not installed. Install it:

pip install mcp

"No MCP servers configured"

No mcp_servers key in ~/.hermes/config.yaml, or it's empty. Add at least one server.

"Failed to connect to MCP server 'X'"

Common causes:

  • Command not found: The command binary isn't on PATH. Ensure npx, uvx, or the relevant command is installed.
  • Package not found: For npx servers, the npm package may not exist or may need -y in args to auto-install.
  • Timeout: The server took too long to start. Increase connect_timeout.
  • Port conflict: For HTTP servers, the URL may be unreachable.

"MCP server 'X' requires HTTP transport but mcp.client.streamable_http is not available"

Your mcp package version doesn't include HTTP client support. Upgrade:

pip install --upgrade mcp

Tools not appearing

  • Check that the server is listed under mcp_servers (not mcp or servers)
  • Ensure the YAML indentation is correct
  • Look at Hermes Agent startup logs for connection messages
  • Tool names are prefixed with mcp_{server}_{tool} -- look for that pattern

Connection keeps dropping

The client retries up to 5 times with exponential backoff (1s, 2s, 4s, 8s, 16s, capped at 60s). If the server is fundamentally unreachable, it gives up after 5 attempts. Check the server process and network connectivity.

OAuth-based servers showing "fail" status

HTTP MCP servers using OAuth 2.1 PKCE (Linear, n8n, etc.) have expiring tokens. When the token expires, hermes mcp list shows "fail" and tools stop working. Two fixes: hermes mcp login <name> for a quick re-auth, or switch to PAT/API key header auth for a permanent fix. See references/oauth-mcp-troubleshooting.md for step-by-step instructions.

Slow HTTP servers showing intermittent "fail" on startup

Servers like Linear MCP (https://mcp.linear.app/mcp) can take 10-15s for the initial HTTP handshake. During startup, Hermes' concurrent MCP probe may timeout before the connection completes, showing transient "fail" status even though the server is healthy. Fix: increase connect_timeout to 90s:

mcp_servers:
  linear:
    url: https://mcp.linear.app/mcp
    connect_timeout: 90

The default is 60s; bumping to 90s eliminates false "fail" on slow-starting servers. After config change, reconnect with /reload-mcp.

HTTP MCP showing "failed" at startup but fine after reload

Some HTTP MCP servers (notably Linear) have slow initial handshakes — hermes mcp test shows 10-20s connect times. The startup probe may show "failed" in hermes mcp list or the TUI dashboard even though the connection is actually healthy. hermes mcp test passes and tools work fine.

Fix: bump connect_timeout to 90s for the slow server:

hermes config set mcp_servers.<name>.connect_timeout 90

After restart, the startup probe has enough headroom. If you still see "failed" transiently, wait 10-20s — the background reconnection with exponential backoff auto-recovers.

CLI vs Agent: ${VAR} Interpolation Gap ⚠️

There is a known difference in how ${VAR} placeholders in mcp_servers config are resolved:

  • Agent runtime (_load_mcp_config() in tools/mcp_tool.py): DOES interpolate ${MCP_SERVER_API_KEY} from os.environ (loaded from .env). Tools work in conversation.
  • CLI commands (hermes mcp test, hermes mcp add via _get_mcp_servers() in hermes_cli/mcp_config.py): Does NOT interpolate ${VAR}. Headers with ${...} are sent literally, causing 401.

Workaround: When using auth: header, hardcode the actual API key directly in config.yaml rather than using ${VAR} placeholders. The .env file can still hold the key for the agent path, but the CLI path needs the literal value.

How to set without truncation: Using hermes config set from the terminal may redact or truncate the value. Use execute_code with subprocess.run(['hermes', 'config', 'set', 'mcp_servers.X.headers.Authorization', 'Bearer <token>']) to pass the full token reliably.

Linear MCP: PAT (Personal Access Token) Setup

Linear's MCP server supports both OAuth (default) and PAT-based auth via Authorization: Bearer <token> header. PAT is recommended for reliability (no token expiry).

# 1. Create PAT at https://linear.app/settings/api
# 2. Remove old OAuth config
hermes mcp remove linear

# 3. Set env var (for agent runtime)
echo 'MCP_LINEAR_API_KEY=*** >> ~/.hermes/.env

# 4. Add config with hardcoded token (see interpolation gap above)
hermes config set mcp_servers.linear.url https://mcp.linear.app/mcp
hermes config set mcp_servers.linear.auth header
hermes config set mcp_servers.linear.enabled true
# IMPORTANT: Set the actual token, not ${MCP_LINEAR_API_KEY}
hermes config set mcp_servers.linear.headers.Authorization 'Bearer lin_api_...'

# 5. Reload MCP tools in session
/reload-mcp

Note: Linear MCP requires Accept: application/json, text/event-stream header. Hermes's MCP SDK may add this automatically; if you get 406, add it explicitly via config.

Examples

Time Server (uvx)

mcp_servers:
  time:
    command: "uvx"
    args: ["mcp-server-time"]

Registers tools like mcp_time_get_current_time.

Filesystem Server (npx)

mcp_servers:
  filesystem:
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/documents"]
    timeout: 30

Registers tools like mcp_filesystem_read_file, mcp_filesystem_write_file, mcp_filesystem_list_directory.

GitHub Server with Authentication

mcp_servers:
  github:
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-github"]
    env:
      GITHUB_PERSONAL_ACCESS_TOKEN: "ghp_xxxxxxxxxxxxxxxxxxxx"
    timeout: 60

Registers tools like mcp_github_list_issues, mcp_github_create_pull_request, etc.

Remote HTTP Server

mcp_servers:
  company_api:
    url: "https://mcp.mycompany.com/v1/mcp"
    headers:
      Authorization: "Bearer sk-xxxxxxxxxxxxxxxxxxxx"
      X-Team-Id: "engineering"
    timeout: 180
    connect_timeout: 30

Multiple Servers

mcp_servers:
  time:
    command: "uvx"
    args: ["mcp-server-time"]

  filesystem:
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]

  github:
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-github"]
    env:
      GITHUB_PERSONAL_ACCESS_TOKEN: "ghp_xxxxxxxxxxxxxxxxxxxx"

  company_api:
    url: "https://mcp.internal.company.com/mcp"
    headers:
      Authorization: "Bearer sk-xxxxxxxxxxxxxxxxxxxx"
    timeout: 300

All tools from all servers are registered and available simultaneously. Each server's tools are prefixed with its name to avoid collisions.

Sampling (Server-Initiated LLM Requests)

Hermes supports MCP's sampling/createMessage capability — MCP servers can request LLM completions through the agent during tool execution. This enables agent-in-the-loop workflows (data analysis, content generation, decision-making).

Sampling is enabled by default. Configure per server:

mcp_servers:
  my_server:
    command: "npx"
    args: ["-y", "my-mcp-server"]
    sampling:
      enabled: true           # default: true
      model: "gemini-3-flash" # model override (optional)
      max_tokens_cap: 4096    # max tokens per request
      timeout: 30             # LLM call timeout (seconds)
      max_rpm: 10             # max requests per minute
      allowed_models: []      # model whitelist (empty = all)
      max_tool_rounds: 5      # tool loop limit (0 = disable)
      log_level: "info"       # audit verbosity

Servers can also include tools in sampling requests for multi-turn tool-augmented workflows. The max_tool_rounds config prevents infinite tool loops. Per-server audit metrics (requests, errors, tokens, tool use count) are tracked via get_mcp_status().

Disable sampling for untrusted servers with sampling: { enabled: false }.

Notes

  • MCP tools are called synchronously from the agent's perspective but run asynchronously on a dedicated background event loop
  • Tool results are returned as JSON with either {"result": "..."} or {"error": "..."}
  • The native MCP client is independent of mcporter -- you can use both simultaneously
  • Server connections are persistent and shared across all conversations in the same agent process
  • Adding or removing servers requires restarting the agent (no hot-reload currently)

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.