Skip to content

Brassin/opsMateAgent

Repository files navigation

OpsMateAgent

OpsMateAgent is a FastAPI-based microservice with an embedded MCP agent. The agent communicates with its MCP server over stdio for extra security.


✨ Features

  • FastAPI endpoints for chat and agent interaction (/chat, /docs)
  • Agent initialization at startup with secrets injected via YAML
  • MCP server vendored as a local module (mcp_server_brassin)
  • Dockerized deployment, optimized for Fly.io

🏗️ Architecture

FastAPI (api/main.py)  <--->  MCP Agent  <--->  MCP Server (mcp_server_brassin)
  • FastAPI exposes REST endpoints and orchestrates requests.
  • MCP Agent manages lifecycle and interaction with the MCP server.
  • MCP Server (mcp_server_brassin) is installed as a vendored tool and runs under the agent’s supervision.

🚀 Getting Started

Make sure you are in the project root directory i.e. OpsMateAgent. You should see folders like configs/, tests/ and files like .python-version, README.md when running ls (mac/Linux) or dir (Windows).


🔧 Local Setup with UV

# Create virtual environment
uv venv

# Activate virtual environment
source .venv/bin/activate  # Linux/macOS
.venv\Scripts\activate     # Windows

# Install dependencies
uv sync

Install MCP server as a CLI tool for the agent

uv tool install --from ./mcp_server_brassin mcp-server-brassin

# Verify installation
mcp-server-brassin

🔑 Configure Agent Secrets

Create a YAML file in the configs/ folder and name it: mcp_agent.secrets.yaml.

Example: mcp_agent.secrets.yaml
openai:
  api_key: "sk-your-openai-key"

# anthropic:
#   api_key: "sk-your-anthropic-key"

# Optional: Azure OpenAI
# azure:
#   api_key: "..."
#   endpoint: "https://<your-endpoint>.openai.azure.com"

# Optional: Google
# google:
#   api_key: "..."
#   vertexai: true
#   project: your-gcp-project-id
#   location: us-central1

# Optional: AWS / Bedrock
# bedrock:
#   aws_access_key_id: "..."
#   aws_secret_access_key: "..."
#   aws_region: "us-east-1"

▶️ Running OpsMateAgent

uv run main.py

Access the API at:


🔄 Re-running Agent with Updated MCP Server

If you make changes to mcp_server_brassin:

# Uninstall old version
uv tool uninstall mcp-server-brassin  

# Install updated version
uv tool install --from ./mcp_server_brassin mcp-server-brassin

# Verify
uv tool list

# Run agent again
uv run main.py

🐳 Running with Docker

Build and run locally:

# Build image
docker build -t opsmate-agent .

# Run container (map host port 9000 to container port 9000)
docker run -d -p 9000:9000 --env-file .env opsmate-agent

Access the app at:


☁️ Deploying on Fly.io

  1. Install Fly.io CLI

    curl -L https://fly.io/install.sh | sh
  2. Initialize app

    flyctl launch
    • Choose Docker deployment
    • Set internal port to 9000
  3. Check fly.toml

    [http_service]
      internal_port = 9000
      force_https = true
      auto_stop_machines = true
      auto_start_machines = true
      min_machines_running = 0  #set to 1 or higher if you are on paid version
  4. Deploy

    flyctl deploy --remote-only
  5. Access Your app will be available at:

    https://<your-app-name>.fly.dev/docs
    

📝 Notes

  • Ensure the app always binds to 0.0.0.0:9000 inside Docker/Fly.io.
  • Cold starts may add latency if auto_stop_machines = true. Use min_machines_running = 1 to keep one warm instance.
  • MCP server must be reinstalled (uv tool install) after updates.