8gent Code
Guides

What is MCP?

The Model Context Protocol (MCP) is a standard for connecting AI agents to external tools and data sources. 8gent includes a built-in MCP client that can connect to any MCP-compatible server, giving the agent access to tools like GitHub, databases, file systems, and more.

Configuration

MCP servers are configured in .8gent/mcp.json in your project root:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your-token-here"
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
    },
    "sqlite": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-sqlite", "--db-path", "./data.db"]
    }
  }
}

Each server entry specifies the command to launch the server process, its arguments, and any required environment variables.

Available MCP Servers

The MCP ecosystem includes servers for many common tools. Here are some useful ones for coding workflows:

ServerPackagePurpose
GitHub@modelcontextprotocol/server-githubIssues, PRs, repos, code search
Filesystem@modelcontextprotocol/server-filesystemSandboxed file access
SQLite@modelcontextprotocol/server-sqliteDatabase queries
Postgres@modelcontextprotocol/server-postgresPostgreSQL access
Brave Search@modelcontextprotocol/server-brave-searchWeb search

Using MCP Tools

Once configured, MCP tools become available to the agent through the toolshed. The agent discovers MCP capabilities dynamically - it does not load all tools into its prompt. Instead, it queries by capability when needed.

Slash Commands

CommandDescription
/mcp listList connected MCP servers and their tools
/mcp connect <server>Manually connect to a server

How It Works Internally

8gent's MCP client (packages/mcp/) handles the connection lifecycle:

  1. Server launch - Spawns the MCP server process using the configured command
  2. Capability discovery - Queries the server for available tools
  3. Tool registration - Registers discovered tools in the toolshed
  4. Execution - Routes tool calls through the MCP protocol
  5. Cleanup - Shuts down server processes when the session ends

The MCP tools integrate with 8gent's permission system. Commands that could modify state require the appropriate permissions (e.g., write:fs, net:fetch).

Example: GitHub Integration

Set up the GitHub MCP server to let 8gent work with GitHub issues and pull requests:

  1. Create a GitHub personal access token at github.com/settings/tokens

  2. Add the server to .8gent/mcp.json:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_your_token_here"
      }
    }
  }
}
  1. Now you can ask 8gent to interact with GitHub:
> List the open issues on 8gi-foundation/8gent-code
> Create a PR for my current branch
> What are the failing checks on PR #42?

Writing Custom MCP Servers

Any process that speaks the MCP protocol can serve as a tool provider. The @modelcontextprotocol/sdk package provides TypeScript utilities for building servers:

npm install @modelcontextprotocol/sdk

Your server exposes tools with input schemas, and 8gent's client discovers and calls them automatically. See the MCP specification for the full protocol documentation.