Spaces:
Running
Running
Merge pull request #975 from tommitt/tommitt/eunomia-middleware
Browse files- docs/docs.json +1 -0
- docs/integrations/eunomia-authorization.mdx +108 -0
docs/docs.json
CHANGED
|
@@ -141,6 +141,7 @@
|
|
| 141 |
"integrations/claude-desktop",
|
| 142 |
"integrations/gemini",
|
| 143 |
"integrations/openai",
|
|
|
|
| 144 |
"integrations/contrib"
|
| 145 |
]
|
| 146 |
},
|
|
|
|
| 141 |
"integrations/claude-desktop",
|
| 142 |
"integrations/gemini",
|
| 143 |
"integrations/openai",
|
| 144 |
+
"integrations/eunomia-authorization",
|
| 145 |
"integrations/contrib"
|
| 146 |
]
|
| 147 |
},
|
docs/integrations/eunomia-authorization.mdx
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Eunomia Authorization + FastMCP
|
| 3 |
+
sidebarTitle: Eunomia Authorization
|
| 4 |
+
description: Add policy-based authorization to your FastMCP servers
|
| 5 |
+
icon: layer-group
|
| 6 |
+
tag: NEW
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
Add **policy-based authorization** to your FastMCP servers with minimal code changes using Eunomia authorization middleware.
|
| 10 |
+
|
| 11 |
+
Control which actions MCP clients can perform on your server by restricting how the agent can access resources, tools and prompts by using JSON-based policies, while obtaining a comprehensive audit log of all access attempts and violations.
|
| 12 |
+
|
| 13 |
+
## Eunomia Authorization Middleware
|
| 14 |
+
|
| 15 |
+
The middleware intercepts all MCP requests to your server and automatically maps MCP methods to authorization checks.
|
| 16 |
+
|
| 17 |
+
```mermaid
|
| 18 |
+
sequenceDiagram
|
| 19 |
+
participant MCPClient as MCP Client
|
| 20 |
+
participant EunomiaMiddleware as Eunomia Middleware
|
| 21 |
+
participant MCPServer as FastMCP Server
|
| 22 |
+
participant EunomiaServer as Eunomia Server
|
| 23 |
+
|
| 24 |
+
MCPClient->>EunomiaMiddleware: MCP Request
|
| 25 |
+
Note over MCPClient, EunomiaMiddleware: Middleware intercepts request to server
|
| 26 |
+
EunomiaMiddleware->>EunomiaServer: Authorization Check
|
| 27 |
+
EunomiaServer->>EunomiaMiddleware: Authorization Decision (allow/deny)
|
| 28 |
+
EunomiaMiddleware-->>MCPClient: MCP Unauthorized Error (if denied)
|
| 29 |
+
EunomiaMiddleware->>MCPServer: MCP Request (if allowed)
|
| 30 |
+
MCPServer-->>MCPClient: MCP Response (if allowed)
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
<Note>
|
| 34 |
+
Eunomia is an AI-specific standalone authorization server that handles policy decisions. You must have an Eunomia server running alongside your FastMCP server for the middleware to function.
|
| 35 |
+
|
| 36 |
+
Run it in the background with Docker:
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
docker run -d -p 8000:8000 ttommitt/eunomia-server:latest
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
</Note>
|
| 43 |
+
|
| 44 |
+
### Create a Server with Authorization
|
| 45 |
+
|
| 46 |
+
First, install the `eunomia-mcp` package:
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
pip install eunomia-mcp
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
Then create a FastMCP server and add the Eunomia middleware with a few lines of code:
|
| 53 |
+
|
| 54 |
+
```python server.py
|
| 55 |
+
from fastmcp import FastMCP
|
| 56 |
+
from eunomia_mcp import create_eunomia_middleware
|
| 57 |
+
|
| 58 |
+
mcp = FastMCP("Secure FastMCP Server 🔒")
|
| 59 |
+
|
| 60 |
+
@mcp.tool()
|
| 61 |
+
def add(a: int, b: int) -> int:
|
| 62 |
+
"""Add two numbers"""
|
| 63 |
+
return a + b
|
| 64 |
+
|
| 65 |
+
middleware = [create_eunomia_middleware()]
|
| 66 |
+
app = mcp.http_app(middleware=middleware)
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
import uvicorn
|
| 70 |
+
uvicorn.run(app, host="0.0.0.0", port=8080)
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
### Configure Access Policies
|
| 74 |
+
|
| 75 |
+
Use the `eunomia-mcp` CLI in your terminal to manage your authorization policies:
|
| 76 |
+
|
| 77 |
+
```bash
|
| 78 |
+
# Create a default policy configuration file
|
| 79 |
+
eunomia-mcp init
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
This creates a policy file you can customize to control access to your MCP tools and resources.
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
# Once ready, validate your policy
|
| 86 |
+
eunomia-mcp validate mcp_policies.json
|
| 87 |
+
|
| 88 |
+
# And push it to the Eunomia server
|
| 89 |
+
eunomia-mcp push mcp_policies.json
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
### Run the Server
|
| 93 |
+
|
| 94 |
+
Start your FastMCP server normally:
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
python server.py
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
The middleware will now intercept all MCP requests and check them against your policies. Requests include agent identification through headers like `X-Agent-ID`, `X-User-ID`, or `Authorization` and an automatic mapping of MCP methods to authorization resources and actions.
|
| 101 |
+
|
| 102 |
+
<Tip>
|
| 103 |
+
For detailed policy configuration, custom authentication, and advanced
|
| 104 |
+
deployment patterns, visit the [Eunomia MCP Middleware
|
| 105 |
+
repository][eunomia-github].
|
| 106 |
+
</Tip>
|
| 107 |
+
|
| 108 |
+
[eunomia-github]: https://github.com/whataboutyou-ai/eunomia/tree/main/pkgs/extensions/mcp
|