home / mcp / open policy agent rest api mcp server

Open Policy Agent REST API MCP Server

Provides a dedicated MCP server for the Open Policy Agent REST API, loading policy definitions from a given OpenAPI URL and exposing a protocol-driven interface.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "ag2-mcp-servers-open-policy-agent-opa-rest-api": {
      "url": "https://api.apis.guru/v2/specs/openpolicy.local/0.28.0/openapi.json",
      "headers": {
        "CONFIG": "{\"transport\":\"stdio\"}",
        "SECURITY": "YOUR_API_KEY",
        "CONFIG_PATH": "mcp_server/mcp_config.json"
      }
    }
  }
}

You run an MCP Server that serves as a bridge between a given OpenAPI spec and MCP clients, enabling you to interact with the Open Policy Agent workflow through standardized MCP messages. This server lets you start locally, connect through various transports, and configure security and runtime options for testing, development, or production use.

How to use

You interact with the MCP server from an MCP client by starting the server in one of the supported transports and then issuing MCP requests through the chosen channel. The server exposes the configured API surface described by the OpenAPI URL and handles requests in a way that remains compatible with MCP tooling. You can run in a local, synchronous, or streaming mode depending on your client needs. Start the server once, then point your client at the provided transport and, if needed, adjust environment configuration to enable authentication and routing through the specified channel.

How to install

Prerequisites include Python 3.9 or newer, and you should have a Python package manager available (pip). A live runtime utility like uv is also supported for development workflows.

# Step 1: Clone the project
git clone <repository-url>
cd mcp-server

# Step 2: Install development dependencies
pip install -e ".[dev]"
# Alternative using uv (for editable installs)
uv pip install --editable ".[dev]"

To run the server in stdio mode directly from the source, use the following command. This starts the MCP server locally and exposes standard input/output for interaction.

python mcp_server/main.py stdio

Additional configuration and notes

Configure runtime behavior and security through environment variables. The server accepts the following environment variables to influence behavior and security checks: CONFIG_PATH, CONFIG, and SECURITY. These allow you to point to a JSON configuration file, specify a configuration string, and supply security-related parameters respectively.

# Example of providing a JSON config path
export CONFIG_PATH=/path/to/mcp_config.json

# Example of inline JSON config string
export CONFIG='{"name":"opa_rest_server","transport":"stdio"}'

# Example security parameter (placeholder)
export SECURITY='YOUR_API_KEY'

Troubleshooting and tips

If the server fails to start, verify that Python 3.9+ is installed and that your environment variables are set correctly. Check for port/file permission issues if you switch transports or run in environments with restricted I/O. For testing and CI, you can drive the server from scripts that start the stdio transport and capture stdout/stderr for assertions.