Metadata-Version: 2.3
Name: policygate
Version: 0.1.2
Summary: MCP server gateway for task-specific AI rules and scripts stored in GitHub
Keywords: mcp,policy,gateway,ai,github,automation
Author: Sergei Konovalov
License: MIT License
         
         Copyright (c) 2025 Sergei Konovalov
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: pydantic-settings>=2.0.0
Requires-Dist: structlog>=25.1.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: fastmcp>=2.0.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: pyyaml>=6.0.0
Maintainer: Sergei Konovalov
Requires-Python: >=3.11
Project-URL: Homepage, https://github.com/l0kifs/policygate
Project-URL: Repository, https://github.com/l0kifs/policygate
Project-URL: Issues, https://github.com/l0kifs/policygate/issues
Description-Content-Type: text/markdown

<p align="center">
    <img src="https://capsule-render.vercel.app/api?type=waving&color=0:4F46E5,100:06B6D4&height=200&section=header&text=policygate&fontSize=56&fontColor=ffffff&animation=fadeIn&fontAlignY=38&desc=MCP%20server%20gateway%20for%20task-specific%20AI%20rules%20and%20scripts&descAlignY=58&descSize=16" alt="policygate banner" />
</p>

<p align="center">
    <a href="https://github.com/l0kifs/policygate/actions/workflows/publish-to-pypi.yml"><img src="https://img.shields.io/github/actions/workflow/status/l0kifs/policygate/publish-to-pypi.yml?branch=main&label=publish" alt="Publish workflow" /></a>
    <a href="https://pypi.org/project/policygate/"><img src="https://img.shields.io/pypi/v/policygate" alt="PyPI version" /></a>
    <a href="https://pypi.org/project/policygate/"><img src="https://img.shields.io/pypi/pyversions/policygate" alt="Python versions" /></a>
    <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT license" /></a>
</p>

# policygate

Policygate is an MCP server gateway for task-specific AI rules and scripts stored in a GitHub repository.

## Features

- Syncs repository content into a local cache at `~/.policygate/repo_data`
- Parses and validates `router.yaml`
- Exposes MCP tools:
    - `sync_repository`
    - `outline_router`
    - `read_rules`
    - `copy_scripts`

Detailed usage reference: [docs/REFERENCE.md](docs/REFERENCE.md)

## Required repository structure

```text
rules/
scripts/
router.yaml
```

`router.yaml` structure:

```yaml
tasks:
    task1:
        description: "Short description of task 1"
        rules:
            - rule1
        scripts:
            - script1

rules:
    rule1:
        path: rules/rule1.md
        description: "Short description of rule 1"

scripts:
    script1:
        path: scripts/script1.py
        description: "Short description of script 1"
```

## Configuration

Set environment variables:

- `POLICYGATE__GITHUB_REPOSITORY_URL`
- `POLICYGATE__GITHUB_ACCESS_TOKEN`
- `POLICYGATE__LOCAL_REPO_DATA_DIR` (optional, default `~/.policygate/repo_data`)
- `POLICYGATE__REPOSITORY_REFRESH_INTERVAL_SECONDS` (optional, default `1800`)

## Run MCP server

Run with:

```bash
uv run policygate-mcp
```

VS Code workspace MCP config example (`.vscode/mcp.json`):

```json
{
    "inputs": [
        {
            "id": "POLICYGATE__GITHUB_REPOSITORY_URL",
            "type": "promptString",
            "description": "GitHub repository URL",
            "password": false
        },
        {
            "id": "POLICYGATE__GITHUB_ACCESS_TOKEN",
            "type": "promptString",
            "description": "GitHub access token",
            "password": true
        }
    ],
    "servers": {
        "policygate": {
            "type": "stdio",
            "command": "uvx",
            "args": ["--from", "policygate@latest", "policygate-mcp"],
            "env": {
                "POLICYGATE__GITHUB_REPOSITORY_URL": "${input:POLICYGATE__GITHUB_REPOSITORY_URL}",
                "POLICYGATE__GITHUB_ACCESS_TOKEN": "${input:POLICYGATE__GITHUB_ACCESS_TOKEN}"
            },
        }
    }
}
```

For local testing from the current workspace (after `uv sync --all-groups`):

```json
{
    "inputs": [
        {
            "id": "POLICYGATE__GITHUB_REPOSITORY_URL",
            "type": "promptString",
            "description": "GitHub repository URL",
            "password": false
        },
        {
            "id": "POLICYGATE__GITHUB_ACCESS_TOKEN",
            "type": "promptString",
            "description": "GitHub access token",
            "password": true
        }
    ],
    "servers": {
        "policygate-local": {
            "type": "stdio",
            "command": "uv",
            "args": ["run", "policygate-mcp"],
            "env": {
                "POLICYGATE__GITHUB_REPOSITORY_URL": "${input:POLICYGATE__GITHUB_REPOSITORY_URL}",
                "POLICYGATE__GITHUB_ACCESS_TOKEN": "${input:POLICYGATE__GITHUB_ACCESS_TOKEN}"
            },
            "cwd": "${workspaceFolder}"
        }
    }
}
```

## Testing

Run feature-organized end-to-end suites:

```bash
uv run pytest --maxfail=1 --tb=short
```
