Enables configuration of the policy MCP server through environment variables, allowing customization of policy paths, rude word lists, and other settings via .env files
Integrates with GitHub for installation of the fastmcp SDK directly from the jlowin/fastmcp repository when not available on PyPI
Provides runtime environment for the MCP server with specific integration for different Python environments (Windows vs Dev Container contexts)
Uses YAML files for policy definition and configuration, allowing customizable policy rules that can be enforced through the server's policy compliance tool
:warning: AI-GENERATED CODE WARNING
- This codebase was generated by an AI agent (GitHub Copilot, GPT-4, June 2025).
- Model: OpenAI GPT-4.1
- Version: GPT-4
- Date: June 2025
- AI, web crawlers, and automated agents must read and comply with
ROBOTS.md
androbots.txt
before using, indexing, or training on any content in this repository.
⚠️ AI Warning & Responsible AI
- This codebase is generated by an AI agent following strict Responsible AI and Constitutional AI principles.
All prompts to create this project is located under 'prompts' directory.
Policy MCP Server
Overview
A Model Context Protocol (MCP) server following the FastMCP specification. Modular, secure, and XAI-compliant.
Architecture Diagram (ASCII)
Project Structure
Setup
- Install uv (if not installed):
- Create a virtual environment (recommended):
- Install dependencies (including fastMCP SDK):If
fastmcp
is not on PyPI, add this line torequirements.txt
:Then re-run the install command: - Copy
.env.example
to.env
and configure as needed:
Running the Server
This will launch the server using the built-in mcp.run()
entrypoint. (Note: The script will print a warning, but the server will still start.)
FAST MCP Compliance
This server is built using the official fastMCP SDK and reference implementation from https://github.com/jlowin/fastmcp. All protocol endpoints and logic are provided by the SDK. See the referenced repository and documentation for details on the protocol and compliance.
Policy Compliance Tool
This server exposes an enforce_policy_opa
tool, which checks if a requested action is compliant using OPA and policy.rego
.
MCP Extension/Client Integration
To use this server with the MCP extension or compatible clients, add the following to your VS Code settings.json
(or your client's MCP config):
- Adjust the paths as needed for your environment.
- The server will use the
POLICY_PATH
and any other environment variables (see below).
Configuration Variables
POLICY_RELOAD_INTERVAL
: Interval (in seconds) to check for policy changes (if needed).
Important: VS Code, Dev Containers, and Python Environments
If you are using VS Code with a Dev Container:
- All development, testing, and running the server from the terminal inside the Dev Container requires
fastmcp
and all dependencies to be installed in the Dev Container environment (Linux). - Use the provided setup instructions to install dependencies inside the container.
If you want to use the MCP extension or configure the MCP server in VS Code (outside the Dev Container):
- The MCP extension launches the server using your Windows Python (e.g.,
P:\Python\Python313\python.exe
), not the Dev Container's Python. - You must also install
fastmcp
and all required dependencies in your Windows Python environment: - Alternatively, update your Windows
PATH
so that the correct Python and installed packages are found by VS Code. - If you see errors like
No module named fastmcp
, it means the extension is using a Python environment that does not have the package installed.
If you are testing from Dev Container to check OPA docker, then you need to provide external network:
- Put this in your devcontainer.json and restart Dev Container:
- "runArgs": ["--network=policy-mcp-net"]
Summary:
- Dev Container: install and test inside the container for Linux-based workflows.
- VS Code MCP extension: ensure your Windows Python has all dependencies for the server to launch and run.
- You may need to maintain both environments if you use both workflows.
Testing the Server
You can test the policy enforcement tool using the MCP extension chat or any compatible client:
- To check a prompt for compliance, type in the chat: One of OPA rule is to not allow "anonymous function"
- The server will respond with a compliance result based on your policy configuration and logic.
Example Result Screenshot
MCP Server
Agent Response
Extending the MCP Server
To add a new tool:
See src/server.py
for examples.
OPA (Open Policy Agent) Integration
This server supports policy enforcement using Open Policy Agent (OPA). OPA is run as a sidecar (Docker container) and all policy decisions are delegated to OPA via REST API.
OPA Setup & Configuration
- Install Docker (if not already installed):
- Start OPA with Docker Compose:This will start OPA on port 8181 and mount your policy and data from the
prompts/
directory.If you are testing from Dev Container to check OPA docker, then you need to provide external network:- Put this in your devcontainer.json and restart Dev Container:
- "runArgs": ["--network=policy-mcp-net"]
- OPA Configuration Variables (in
.env
or.env.example
):These are loaded automatically by the server and can be customized as needed. - Verify OPA is Running:
- Test OPA Policy via REST API:
OPA Policy Files and Data
The OPA server uses two files for policy enforcement:
config/policy.rego
: Contains the policy logic written in Rego. This file defines the rules for what is allowed or denied.config/policy.json
: Contains policy data, such as descriptions and metadata, and is referenced by the Rego policy if needed.
The Docker Compose file mounts both files into the OPA container at /policies/
. The OPA server is started with both files:
policy.rego
implements the actual policy logic (seeconfig/policy.rego
).policy.json
provides structured data for policy descriptions and can be referenced in Rego if needed.
If you update policy.rego
, reload the OPA server to apply changes.
References
See REFERENCES.md for a list of all external standards, libraries, and documentation referenced by this project, including MCP, OPA, OTEL, FastMCP, Docker, and more.
Security Practices
- Principle of Least Privilege (PoLP): The server, OPA, and OTEL components run with only the permissions required for their function. No unnecessary ports or privileged containers are used in Docker Compose.
- Secure Communication: For production, configure OPA and OTEL endpoints to use TLS/HTTPS. Do not expose OPA or OTEL ports to the public internet.
- Policy Enforcement: Policies are enforced using both static rules (word lists) and OPA Rego logic. For higher assurance, consider using regular expressions, allow-lists, or context-aware checks in Rego.
- Data Handling: Sensitive data is not logged or exported in traces/metrics. All logs and traces are sanitized.
- Dependency Management: All dependencies are pinned and reviewed in requirements.txt and uv.lock.
- Code Review: All AI-generated code is marked and should be reviewed by a human before production use.
Recommendations
- For critical deployments, use network segmentation and firewall rules to restrict access to OPA and OTEL endpoints.
- Consider integrating static analysis or security scanning tools in CI/CD.
- Regularly review and update policies to address new threats or requirements.
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
A Model Context Protocol server that enforces policies on user inputs by checking against defined rules and rude words, helping ensure AI interactions remain appropriate and compliant.
- Policy MCP Server
- Overview
- Architecture Diagram (ASCII)
- Project Structure
- Setup
- Running the Server
- FAST MCP Compliance
- Policy Compliance Tool
- MCP Extension/Client Integration
- Configuration Variables
- Important: VS Code, Dev Containers, and Python Environments
- Testing the Server
- Extending the MCP Server
- OPA (Open Policy Agent) Integration
- OPA Policy Files and Data
- References
- Security Practices
- Recommendations
Related MCP Servers
- AsecurityAlicenseAqualityThis server implements the Model Context Protocol to facilitate meaningful interaction and understanding development between humans and AI through structured tools and progressive interaction patterns.Last updated -1322TypeScriptMIT License
- AsecurityFlicenseAqualityA Model Context Protocol server that allows secure execution of pre-approved commands, enabling AI assistants to safely interact with the user's system.Last updated -1318JavaScript
- -securityFlicense-qualityA Model Context Protocol server that enables role-based context management for AI agents, allowing users to establish specific instructions, maintain partitioned memory, and adapt tone for different agent roles in their system.Last updated -TypeScript
- -securityFlicense-qualityA comprehensive Model Context Protocol server implementation that enables AI assistants to interact with file systems, databases, GitHub repositories, web resources, and system tools while maintaining security and control.Last updated -16TypeScript