Skip to content

agentbeats/mcpcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCPCP

Overview

MCPCP consists of multiple MCP servers and a central proxy server that provides authentication, access control, and unified access to distributed tools and resources.

Architecture

┌─────────────────┐    ┌─────────────────┐
│   Client Apps   │───▶│  Proxy Server   │
└─────────────────┘    │ (port 9080/9081)│
                       └─────────┬───────┘
                                 │
                    ┌────────────┼─────────────┐
                    │            │             │
              ┌─────▼─────┐ ┌────▼──────┐ ┌────▼──────┐
              │  MCP1     │ │  MCP2     │ │  MCP3     │
              │(port 9010)│ │(port 9011)│ │(port 9012)│
              └───────────┘ └───────────┘ └───────────┘

Components

MCP Servers

  • mcp1.py (port 9010): Battle process logging and result reporting
  • mcp2.py (port 9011): Docker command execution
  • mcp3.py (port 9012): Python code execution

Proxy Server

  • mcpcp.py (port 9080/9081): Authentication, access control, and request routing

Quick Start

1. Setup Environment

# Install dependencies
pip install -r requirements.txt

2. Generate Authentication Keys

(This is for PoC only. You can skip this part as the keys are already generated.)

python mcp_auth/generate_keys.py

This creates:

  • mcp_auth/private.pem - Private key for signing tokens
  • mcp_auth/public.pem - Public key for verifying tokens

3. Launch All Servers

python mcp_servers/mcp1.py
python mcp_servers/mcp2.py
python mcp_servers/mcp3.py
python mcpcp.py

This will:

  1. Start all 3 MCP servers (ports 9010-9012)
  2. Start the proxy server (port 9080/9081)

4. Stop Servers

Press Ctrl+C to gracefully shutdown all servers.

5. Run the test client

python test_mcpcp.py

This will register agents and mcp servers and show how each different agent with a different token can access a different subset of allowed tool list.

Expected results
🚀 MCPCP Comprehensive Test Script
This script will test the complete MCPCP workflow

============================================================
STEP 1: Register 3 agents
============================================================
Registering agent: agent1
✅ Agent 'agent1' registered with ID: b4eeed54-1d5b-4f6c-accb-aac72d6fb9b5
Registering agent: agent2
✅ Agent 'agent2' registered with ID: 8c4bebce-236e-41c3-ab1d-5ffe01b778bd
Registering agent: agent3
✅ Agent 'agent3' registered with ID: 85487d41-545b-4a0c-aba2-f1c27c7a7ece
✅ Successfully registered 3 agents

============================================================
STEP 2: Use agent1 to register 3 MCP servers
============================================================
Registering MCP server 'mcp1' using agent 'agent1'
✅ MCP server 'mcp1' registered with ID: c01d7a01-91b8-4593-bea6-4d823b1c64b5
Registering MCP server 'mcp2' using agent 'agent1'
✅ MCP server 'mcp2' registered with ID: 4b1922d1-1501-4bfa-b0c4-39a0259165f4
Registering MCP server 'mcp3' using agent 'agent1'
✅ MCP server 'mcp3' registered with ID: 6308b7d3-b888-494d-bf17-6396a0381557
✅ Successfully registered 3 MCP servers

============================================================
STEP 3: View initial access control for agent1
============================================================
Viewing access control using agent 'agent1'
✅ Access control retrieved:
   Owned servers: ['6308b7d3-b888-494d-bf17-6396a0381557', 'c01d7a01-91b8-4593-bea6-4d823b1c64b5', '4b1922d1-1501-4bfa-b0c4-39a0259165f4']
   Access control: {}

============================================================
STEP 4: Update access control rules
============================================================
Updating access control for 'agent2' using agent 'agent1'
✅ Access control updated: Successfully updated access control for agent '8c4bebce-236e-41c3-ab1d-5ffe01b778bd'
Updating access control for 'agent3' using agent 'agent1'
✅ Access control updated: Successfully updated access control for agent '85487d41-545b-4a0c-aba2-f1c27c7a7ece'

============================================================
STEP 5: View updated access control
============================================================
Viewing access control using agent 'agent1'
✅ Access control retrieved:
   Owned servers: ['6308b7d3-b888-494d-bf17-6396a0381557', 'c01d7a01-91b8-4593-bea6-4d823b1c64b5', '4b1922d1-1501-4bfa-b0c4-39a0259165f4']
   Access control: {
  "8c4bebce-236e-41c3-ab1d-5ffe01b778bd": {
    "4b1922d1-1501-4bfa-b0c4-39a0259165f4": "*",
    "6308b7d3-b888-494d-bf17-6396a0381557": [
      "echo",
      "run_python_code"
    ]
  },
  "85487d41-545b-4a0c-aba2-f1c27c7a7ece": {
    "c01d7a01-91b8-4593-bea6-4d823b1c64b5": [
      "echo",
      "update_battle_process"
    ],
    "6308b7d3-b888-494d-bf17-6396a0381557": "*"
  }
}

============================================================
STEP 6: Test MCP client functionality
============================================================

--- Testing agent1 ---
Testing MCP client for agent: agent1
✅ Agent 'agent1' can access 0 tools:

--- Testing agent2 ---
Testing MCP client for agent: agent2
✅ Agent 'agent2' can access 3 tools:
   - echo: None
   - run_docker: None
   - run_python_code: None
✅ Echo tool result: [TextContent(type='text', text='Echo: Hello from agent2!', annotations=None, meta=None)]
✅ Tool 'run_docker' result: [TextContent(type='text', text="Docker: echo 'Docker test from agent2'", annotations=None, meta=None)]
✅ Tool 'run_python_code' result: [TextContent(type='text', text="Python: print('Python test from agent2')", annotations=None, meta=None)]

--- Testing agent3 ---
Testing MCP client for agent: agent3
✅ Agent 'agent3' can access 3 tools:
   - echo: Echo the input message.
   - update_battle_process: Log battle process updates to backend API and console.

This tool records intermediate events and progress during a battle, helping track
what each participant is doing and how the battle is evolving.

Args:
    battle_id (str): Unique identifier for the battle session
    message (str): Simple, human-readable description of what happened
                  Example: "guardrailGenerator defense prompt success" or "red agent launched attack"
    detail (dict): Structured data containing specific details about the event
                  Can include prompts, responses, configurations, or any relevant data
                  Example: {"prompt": "You are a helpful assistant...", "tool": "xxxTool"}
    reported_by (str): The role/agent that triggered this event
                      Example: "guardrailGenerator", "red_agent", "blue_agent", "evaluator"
    markdown_content (str): Optional markdown content for rich text display, and image rendering

Returns:
    str: Status message indicating where the log was recorded

Example usage in TensorTrust game:
    - message: "guardrailGenerator defense prompt success"
    - detail: {"defense_prompt": "Ignore all previous instructions...", "secret_key": "abc123"}
    - reported_by: "guardrailGenerator"
   - run_python_code: None
✅ Echo tool result: [TextContent(type='text', text='Echo: Hello from agent3!', annotations=None, meta=None)]
✅ Tool 'update_battle_process' result: [TextContent(type='text', text='logged locally (network error)', annotations=None, meta=None)]
✅ Tool 'run_python_code' result: [TextContent(type='text', text="Python: print('Python test from agent3')", annotations=None, meta=None)]

============================================================
STEP 7: Test cross-agent access control (should fail)
============================================================
ℹ️  Testing agent2 trying to update access for agent3 (should fail)...
Updating access control for 'agent3' using agent 'agent2'
❌ Failed to update access control: 403 Client Error: Forbidden for url: http://127.0.0.1:9081/update_access_control
✅ Cross-agent access control properly blocked!

📋 Test Data Summary:
Registered agents: ['agent1', 'agent2', 'agent3']
Registered servers: ['mcp1', 'mcp2', 'mcp3']

Development

Project Structure

mcpcp/
├── mcp_servers/          # Individual MCP servers
│   ├── mcp1.py           # Example MCP Server 1
│   ├── mcp2.py           # Example MCP Server 2
│   └── mcp3.py           # Example MCP Server 3
├── mcp_auth/             # Authentication utilities
│   └── generate_keys.py  # RSA key generation
├── mcpcp.py              # Main MCPCP proxy server
├── test_mcpcp.py             # Example client
└── README.md             # This file

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages