Skip to main content

Overview

Docker container-based MCP servers for maximum isolation.

Usage

from upsonic import Task, Agent

# Docker-based MCP server
class DatabaseMCP:
    command = "docker"
    args = [
        "run",
        "--rm",
        "-i",
        "--network", "host",
        "your-mcp-server-image:latest"
    ]
    env = {
        "DATABASE_URL": "postgresql://localhost/mydb"
    }

# Create task
task = Task(
    description="Connect to the PostgreSQL database container, query the latest 100 transactions, and analyze them for potential anomalies.",
    tools=[DatabaseMCP]
)

# Create agent
agent = Agent(
    name="Database Agent",
    model="openai/gpt-4o"
)

# Execute
result = agent.do(task)
print(result)

Parameters

  • command (str): The command to run (“docker”)
  • args (List[str]): Docker run arguments including image name
  • env (Dict[str, str]): Environment variables to pass to container
  • tool_name_prefix (str): Optional prefix to add to all tool names (prevents collisions)

Using Tool Name Prefix

Add a tool_name_prefix when using multiple Docker-based MCP servers:
class ProductionDB:
    command = "docker"
    args = ["run", "--rm", "-i", "postgres-mcp:latest"]
    env = {"DATABASE_URL": "postgresql://prod-server/db"}
    tool_name_prefix = "prod_db"  # Tools become: prod_db_query, etc.

class StagingDB:
    command = "docker"
    args = ["run", "--rm", "-i", "postgres-mcp:latest"]
    env = {"DATABASE_URL": "postgresql://staging-server/db"}
    tool_name_prefix = "staging_db"  # Tools become: staging_db_query, etc.

Requirements

  • Docker must be installed and running
  • MCP server Docker image must be available

Characteristics

  • Maximum isolation and security
  • Consistent environment across systems
  • Easy deployment and versioning
  • Network and resource control