Policy MCP Server
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.
README
<!-- File name: README.md File description: Project overview and instructions. Author: AI Generated Date created: 2025-06-02 Last modified date: 2025-06-02 Version number: 1.0 AI WARNING: This file is generated with AI assistance. Please review and verify the content before use. -->
Policy MCP Server
AI WARNING: This content includes AI-generated code. Verify for accuracy and security before use.
All prompts to create this project is located under 'prompts' directory.
Overview
A Model Context Protocol (MCP) server following the FAST MCP specification. Modular, secure, XAI-compliant, and fully tested.
Architecture Diagram (ASCII)
+-------------------+
| Client/Consumer |
+--------+----------+
|
v
+--------+----------+
| MCP Server API |
+--------+----------+
|
v
+--------+----------+
| Core Logic |
+--------+----------+
|
v
+--------+----------+
| Storage/Config |
+-------------------+
Project Structure
policy-mcp-server/
src/
tests/
config/
logs/
README.md
.env.example
pyproject.toml
Setup
-
Install uv (if not installed):
pip install uv -
Create a virtual environment (recommended):
uv venv .venv source .venv/bin/activate -
Install dependencies (including fastMCP SDK):
uv pip install -r requirements.txtIf
fastmcpis not on PyPI, add this line torequirements.txt:fastmcp @ git+https://github.com/jlowin/fastmcp.gitThen re-run the install command:
uv pip install -r requirements.txt -
Copy
.env.exampleto.envand configure as needed:cp .env.example .env # Then edit .env to set POLICY_PATH, RUDE_WORDS, etc. as needed
Running the Server
python src/server.py
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 tool, which checks if a requested action is compliant with the policies defined in prompts/policy.prompt.yaml.
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):
"mcp": {
"servers": {
"policy-mcp-server": {
"command": "python",
"args": [
"P:\\mcp-servers\\policy-mcp-server\\src\\server.py"
],
"env": {
"POLICY_PATH": "P:\\mcp-servers\\policy-mcp-server\\prompts\\policy.prompt.yaml"
}
}
}
}
- Adjust the paths as needed for your environment.
- The server will use the
POLICY_PATHand any other environment variables (see below).
Configuration Variables
POLICY_PATH: Path to the policy YAML file. Defaults to./prompts/policy.prompt.yamlbut can be overridden in your.envfile or MCP config.RUDE_WORDS: Comma-separated list of rude/abusive words for policy enforcement. Set in.envor MCP config.
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
fastmcpand 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
fastmcpand all required dependencies in your Windows Python environment:P:\Python\Python313\python.exe -m pip install fastmcp - Alternatively, update your Windows
PATHso 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.
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:
#enforce_policy I think you suck #enforce_policy Where is Waldo? #enforce_policy Hello, world! - 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:
@mcp.tool()
def my_tool(...):
...
See src/server.py for examples.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。