Spaces:
Running
Running
Commit ·
c2f400b
1
Parent(s): e89a164
update readme
Browse files
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🛡️
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: blue
|
|
@@ -7,49 +7,52 @@ sdk: static
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
| 11 |
<div align="center">
|
| 12 |
|
| 13 |
<!-- omit in toc -->
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
<strong>The
|
| 17 |
|
| 18 |
-
*
|
| 19 |
|
| 20 |
-
[](https://github.com/jlowin/fastmcp/actions/workflows/run-tests.yml)
|
| 23 |
-
[](https://github.com/jlowin/fastmcp/blob/main/LICENSE)
|
| 24 |
|
| 25 |
-
<a href="https://trendshift.io/repositories/
|
| 26 |
</div>
|
| 27 |
|
| 28 |
> [!Note]
|
| 29 |
>
|
| 30 |
-
> ####
|
| 31 |
-
>
|
| 32 |
-
> FastMCP is the standard framework for working with the Model Context Protocol. FastMCP 1.0 was incorporated into the [official MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk) in 2024.
|
| 33 |
>
|
| 34 |
-
>
|
| 35 |
>
|
| 36 |
-
>
|
| 37 |
>
|
| 38 |
-
> Ready to
|
| 39 |
|
| 40 |
---
|
| 41 |
|
| 42 |
-
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) is a new, standardized way to provide context and tools to your LLMs, and
|
| 43 |
|
| 44 |
```python
|
| 45 |
# server.py
|
| 46 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
@mcp.tool
|
| 51 |
def add(a: int, b: int) -> int:
|
| 52 |
-
"""Add two numbers"""
|
| 53 |
return a + b
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
|
@@ -59,19 +62,19 @@ if __name__ == "__main__":
|
|
| 59 |
Run the server locally:
|
| 60 |
|
| 61 |
```bash
|
| 62 |
-
|
| 63 |
```
|
| 64 |
|
| 65 |
### 📚 Documentation
|
| 66 |
|
| 67 |
-
|
| 68 |
|
| 69 |
Documentation is also available in [llms.txt format](https://llmstxt.org/), which is a simple markdown standard that LLMs can consume easily.
|
| 70 |
|
| 71 |
There are two ways to access the LLM-friendly documentation:
|
| 72 |
|
| 73 |
-
- [`llms.txt`](https://
|
| 74 |
-
- [`llms-full.txt`](https://
|
| 75 |
|
| 76 |
---
|
| 77 |
|
|
@@ -79,27 +82,10 @@ There are two ways to access the LLM-friendly documentation:
|
|
| 79 |
## Table of Contents
|
| 80 |
|
| 81 |
- [What is MCP?](#what-is-mcp)
|
| 82 |
-
- [Why
|
| 83 |
-
- [
|
| 84 |
-
- [
|
| 85 |
-
- [The `FastMCP` Server](#the-fastmcp-server)
|
| 86 |
-
- [Tools](#tools)
|
| 87 |
-
- [Resources \& Templates](#resources--templates)
|
| 88 |
-
- [Prompts](#prompts)
|
| 89 |
-
- [Context](#context)
|
| 90 |
-
- [MCP Clients](#mcp-clients)
|
| 91 |
-
- [Advanced Features](#advanced-features)
|
| 92 |
-
- [Proxy Servers](#proxy-servers)
|
| 93 |
-
- [Composing MCP Servers](#composing-mcp-servers)
|
| 94 |
-
- [OpenAPI \& FastAPI Generation](#openapi--fastapi-generation)
|
| 95 |
-
- [Authentication \& Security](#authentication--security)
|
| 96 |
-
- [Running Your Server](#running-your-server)
|
| 97 |
- [Contributing](#contributing)
|
| 98 |
-
- [Prerequisites](#prerequisites)
|
| 99 |
-
- [Setup](#setup)
|
| 100 |
-
- [Unit Tests](#unit-tests)
|
| 101 |
-
- [Static Checks](#static-checks)
|
| 102 |
-
- [Pull Requests](#pull-requests)
|
| 103 |
|
| 104 |
---
|
| 105 |
|
|
@@ -112,325 +98,69 @@ The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) lets you bui
|
|
| 112 |
- Define interaction patterns through **Prompts** (reusable templates for LLM interactions)
|
| 113 |
- And more!
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
## Why FastMCP?
|
| 118 |
-
|
| 119 |
-
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. FastMCP handles all the complex protocol details and server management, so you can focus on building great tools. It's designed to be high-level and Pythonic; in most cases, decorating a function is all you need.
|
| 120 |
-
|
| 121 |
-
FastMCP 2.0 has evolved into a comprehensive platform that goes far beyond basic protocol implementation. While 1.0 provided server-building capabilities (and is now part of the official MCP SDK), 2.0 offers a complete ecosystem including client libraries, authentication systems, deployment tools, integrations with major AI platforms, testing frameworks, and production-ready infrastructure patterns.
|
| 122 |
-
|
| 123 |
-
FastMCP aims to be:
|
| 124 |
-
|
| 125 |
-
🚀 **Fast:** High-level interface means less code and faster development
|
| 126 |
-
|
| 127 |
-
🍀 **Simple:** Build MCP servers with minimal boilerplate
|
| 128 |
-
|
| 129 |
-
🐍 **Pythonic:** Feels natural to Python developers
|
| 130 |
-
|
| 131 |
-
🔍 **Complete:** A comprehensive platform for all MCP use cases, from dev to prod
|
| 132 |
-
|
| 133 |
-
## Installation
|
| 134 |
-
|
| 135 |
-
We recommend installing FastMCP with [uv](https://docs.astral.sh/uv/):
|
| 136 |
-
|
| 137 |
-
```bash
|
| 138 |
-
uv pip install fastmcp
|
| 139 |
-
```
|
| 140 |
-
|
| 141 |
-
For full installation instructions, including verification, upgrading from the official MCPSDK, and developer setup, see the [**Installation Guide**](https://gofastmcp.com/getting-started/installation).
|
| 142 |
-
|
| 143 |
-
## Core Concepts
|
| 144 |
-
|
| 145 |
-
These are the building blocks for creating MCP servers and clients with FastMCP.
|
| 146 |
-
|
| 147 |
-
### The `FastMCP` Server
|
| 148 |
-
|
| 149 |
-
The central object representing your MCP application. It holds your tools, resources, and prompts, manages connections, and can be configured with settings like authentication.
|
| 150 |
-
|
| 151 |
-
```python
|
| 152 |
-
from fastmcp import FastMCP
|
| 153 |
-
|
| 154 |
-
# Create a server instance
|
| 155 |
-
mcp = FastMCP(name="MyAssistantServer")
|
| 156 |
-
```
|
| 157 |
-
|
| 158 |
-
Learn more in the [**FastMCP Server Documentation**](https://gofastmcp.com/servers/fastmcp).
|
| 159 |
|
| 160 |
-
##
|
| 161 |
|
| 162 |
-
|
| 163 |
|
| 164 |
-
|
| 165 |
-
@mcp.tool
|
| 166 |
-
def multiply(a: float, b: float) -> float:
|
| 167 |
-
"""Multiplies two numbers."""
|
| 168 |
-
return a * b
|
| 169 |
-
```
|
| 170 |
|
| 171 |
-
|
| 172 |
|
| 173 |
-
|
| 174 |
|
| 175 |
-
|
| 176 |
|
| 177 |
-
|
| 178 |
-
# Static resource
|
| 179 |
-
@mcp.resource("config://version")
|
| 180 |
-
def get_version():
|
| 181 |
-
return "2.0.1"
|
| 182 |
-
|
| 183 |
-
# Dynamic resource template
|
| 184 |
-
@mcp.resource("users://{user_id}/profile")
|
| 185 |
-
def get_profile(user_id: int):
|
| 186 |
-
# Fetch profile for user_id...
|
| 187 |
-
return {"name": f"User {user_id}", "status": "active"}
|
| 188 |
-
```
|
| 189 |
|
| 190 |
-
|
| 191 |
|
| 192 |
-
##
|
| 193 |
|
| 194 |
-
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
```
|
| 202 |
-
|
| 203 |
-
Learn more in the [**Prompts Documentation**](https://gofastmcp.com/servers/prompts).
|
| 204 |
-
|
| 205 |
-
### Context
|
| 206 |
-
|
| 207 |
-
Access MCP session capabilities within your tools, resources, or prompts by adding a `ctx: Context` parameter. Context provides methods for:
|
| 208 |
-
|
| 209 |
-
- **Logging:** Log messages to MCP clients with `ctx.info()`, `ctx.error()`, etc.
|
| 210 |
-
- **LLM Sampling:** Use `ctx.sample()` to request completions from the client's LLM.
|
| 211 |
-
- **HTTP Request:** Use `ctx.http_request()` to make HTTP requests to other servers.
|
| 212 |
-
- **Resource Access:** Use `ctx.read_resource()` to access resources on the server
|
| 213 |
-
- **Progress Reporting:** Use `ctx.report_progress()` to report progress to the client.
|
| 214 |
-
- and more...
|
| 215 |
-
|
| 216 |
-
To access the context, add a parameter annotated as `Context` to any mcp-decorated function. FastMCP will automatically inject the correct context object when the function is called.
|
| 217 |
-
|
| 218 |
-
```python
|
| 219 |
-
from fastmcp import FastMCP, Context
|
| 220 |
-
|
| 221 |
-
mcp = FastMCP("My MCP Server")
|
| 222 |
-
|
| 223 |
-
@mcp.tool
|
| 224 |
-
async def process_data(uri: str, ctx: Context):
|
| 225 |
-
# Log a message to the client
|
| 226 |
-
await ctx.info(f"Processing {uri}...")
|
| 227 |
-
|
| 228 |
-
# Read a resource from the server
|
| 229 |
-
data = await ctx.read_resource(uri)
|
| 230 |
-
|
| 231 |
-
# Ask client LLM to summarize the data
|
| 232 |
-
summary = await ctx.sample(f"Summarize: {data.content[:500]}")
|
| 233 |
-
|
| 234 |
-
# Return the summary
|
| 235 |
-
return summary.text
|
| 236 |
-
```
|
| 237 |
-
|
| 238 |
-
Learn more in the [**Context Documentation**](https://gofastmcp.com/servers/context).
|
| 239 |
-
|
| 240 |
-
### MCP Clients
|
| 241 |
-
|
| 242 |
-
Interact with *any* MCP server programmatically using the `fastmcp.Client`. It supports various transports (Stdio, SSE, In-Memory) and often auto-detects the correct one. The client can also handle advanced patterns like server-initiated **LLM sampling requests** if you provide an appropriate handler.
|
| 243 |
-
|
| 244 |
-
Critically, the client allows for efficient **in-memory testing** of your servers by connecting directly to a `FastMCP` server instance via the `FastMCPTransport`, eliminating the need for process management or network calls during tests.
|
| 245 |
-
|
| 246 |
-
```python
|
| 247 |
-
from fastmcp import Client
|
| 248 |
-
|
| 249 |
-
async def main():
|
| 250 |
-
# Connect via stdio to a local script
|
| 251 |
-
async with Client("my_server.py") as client:
|
| 252 |
-
tools = await client.list_tools()
|
| 253 |
-
print(f"Available tools: {tools}")
|
| 254 |
-
result = await client.call_tool("add", {"a": 5, "b": 3})
|
| 255 |
-
print(f"Result: {result.text}")
|
| 256 |
-
|
| 257 |
-
# Connect via SSE
|
| 258 |
-
async with Client("http://localhost:8000/sse") as client:
|
| 259 |
-
# ... use the client
|
| 260 |
-
pass
|
| 261 |
-
```
|
| 262 |
-
|
| 263 |
-
To use clients to test servers, use the following pattern:
|
| 264 |
-
|
| 265 |
-
```python
|
| 266 |
-
from fastmcp import FastMCP, Client
|
| 267 |
-
|
| 268 |
-
mcp = FastMCP("My MCP Server")
|
| 269 |
-
|
| 270 |
-
async def main():
|
| 271 |
-
# Connect via in-memory transport
|
| 272 |
-
async with Client(mcp) as client:
|
| 273 |
-
# ... use the client
|
| 274 |
-
```
|
| 275 |
-
|
| 276 |
-
FastMCP also supports connecting to multiple servers through a single unified client using the standard MCP configuration format:
|
| 277 |
-
|
| 278 |
-
```python
|
| 279 |
-
from fastmcp import Client
|
| 280 |
-
|
| 281 |
-
# Standard MCP configuration with multiple servers
|
| 282 |
-
config = {
|
| 283 |
-
"mcpServers": {
|
| 284 |
-
"weather": {"url": "https://weather-api.example.com/mcp"},
|
| 285 |
-
"assistant": {"command": "python", "args": ["./assistant_server.py"]}
|
| 286 |
-
}
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
# Create a client that connects to all servers
|
| 290 |
-
client = Client(config)
|
| 291 |
-
|
| 292 |
-
async def main():
|
| 293 |
-
async with client:
|
| 294 |
-
# Access tools and resources with server prefixes
|
| 295 |
-
forecast = await client.call_tool("weather_get_forecast", {"city": "London"})
|
| 296 |
-
answer = await client.call_tool("assistant_answer_question", {"query": "What is MCP?"})
|
| 297 |
-
```
|
| 298 |
|
| 299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
-
##
|
| 306 |
|
| 307 |
-
|
| 308 |
|
| 309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
Build modular applications by mounting multiple `FastMCP` instances onto a parent server using `mcp.mount()` (live link) or `mcp.import_server()` (static copy).
|
| 314 |
-
|
| 315 |
-
Learn more in the [**Composition Documentation**](https://gofastmcp.com/patterns/composition).
|
| 316 |
-
|
| 317 |
-
### OpenAPI & FastAPI Generation
|
| 318 |
-
|
| 319 |
-
Automatically generate FastMCP servers from existing OpenAPI specifications (`FastMCP.from_openapi()`) or FastAPI applications (`FastMCP.from_fastapi()`), instantly bringing your web APIs to the MCP ecosystem.
|
| 320 |
-
|
| 321 |
-
Learn more: [**OpenAPI Integration**](https://gofastmcp.com/integrations/openapi) | [**FastAPI Integration**](https://gofastmcp.com/integrations/fastapi).
|
| 322 |
-
|
| 323 |
-
### Authentication & Security
|
| 324 |
-
|
| 325 |
-
FastMCP provides built-in authentication support to secure both your MCP servers and clients in production environments. Protect your server endpoints from unauthorized access and authenticate your clients against secured MCP servers using industry-standard protocols.
|
| 326 |
-
|
| 327 |
-
- **Server Protection**: Secure your FastMCP server endpoints with configurable authentication providers
|
| 328 |
-
- **Client Authentication**: Connect to authenticated MCP servers with automatic credential management
|
| 329 |
-
- **Production Ready**: Support for common authentication patterns used in enterprise environments
|
| 330 |
-
|
| 331 |
-
Learn more in the **Authentication Documentation** for [servers](https://gofastmcp.com/servers/auth) and [clients](https://gofastmcp.com/clients/auth).
|
| 332 |
-
|
| 333 |
-
## Running Your Server
|
| 334 |
-
|
| 335 |
-
The main way to run a FastMCP server is by calling the `run()` method on your server instance:
|
| 336 |
-
|
| 337 |
-
```python
|
| 338 |
-
# server.py
|
| 339 |
-
from fastmcp import FastMCP
|
| 340 |
-
|
| 341 |
-
mcp = FastMCP("Demo 🚀")
|
| 342 |
-
|
| 343 |
-
@mcp.tool
|
| 344 |
-
def hello(name: str) -> str:
|
| 345 |
-
return f"Hello, {name}!"
|
| 346 |
-
|
| 347 |
-
if __name__ == "__main__":
|
| 348 |
-
mcp.run() # Default: uses STDIO transport
|
| 349 |
-
```
|
| 350 |
-
|
| 351 |
-
FastMCP supports three transport protocols:
|
| 352 |
-
|
| 353 |
-
**STDIO (Default)**: Best for local tools and command-line scripts.
|
| 354 |
-
|
| 355 |
-
```python
|
| 356 |
-
mcp.run(transport="stdio") # Default, so transport argument is optional
|
| 357 |
-
```
|
| 358 |
-
|
| 359 |
-
**Streamable HTTP**: Recommended for web deployments.
|
| 360 |
-
|
| 361 |
-
```python
|
| 362 |
-
mcp.run(transport="http", host="127.0.0.1", port=8000, path="/mcp")
|
| 363 |
-
```
|
| 364 |
-
|
| 365 |
-
**SSE**: For compatibility with existing SSE clients.
|
| 366 |
-
|
| 367 |
-
```python
|
| 368 |
-
mcp.run(transport="sse", host="127.0.0.1", port=8000)
|
| 369 |
-
```
|
| 370 |
-
|
| 371 |
-
See the [**Running Server Documentation**](https://gofastmcp.com/deployment/running-server) for more details.
|
| 372 |
|
| 373 |
## Contributing
|
| 374 |
|
| 375 |
-
Contributions are the core of open source! We welcome improvements and
|
| 376 |
-
|
| 377 |
-
### Prerequisites
|
| 378 |
-
|
| 379 |
-
- Python 3.10+
|
| 380 |
-
- [uv](https://docs.astral.sh/uv/) (Recommended for environment management)
|
| 381 |
-
|
| 382 |
-
### Setup
|
| 383 |
-
|
| 384 |
-
1. Clone the repository:
|
| 385 |
-
|
| 386 |
-
```bash
|
| 387 |
-
git clone https://github.com/jlowin/fastmcp.git
|
| 388 |
-
cd fastmcp
|
| 389 |
-
```
|
| 390 |
-
|
| 391 |
-
2. Create and sync the environment:
|
| 392 |
-
|
| 393 |
-
```bash
|
| 394 |
-
uv sync
|
| 395 |
-
```
|
| 396 |
-
|
| 397 |
-
This installs all dependencies, including dev tools.
|
| 398 |
-
|
| 399 |
-
3. Activate the virtual environment (e.g., `source .venv/bin/activate` or via your IDE).
|
| 400 |
-
|
| 401 |
-
### Unit Tests
|
| 402 |
-
|
| 403 |
-
FastMCP has a comprehensive unit test suite. All PRs must introduce or update tests as appropriate and pass the full suite.
|
| 404 |
-
|
| 405 |
-
Run tests using pytest:
|
| 406 |
-
|
| 407 |
-
```bash
|
| 408 |
-
pytest
|
| 409 |
-
```
|
| 410 |
-
|
| 411 |
-
or if you want an overview of the code coverage
|
| 412 |
-
|
| 413 |
-
```bash
|
| 414 |
-
uv run pytest --cov=src --cov=examples --cov-report=html
|
| 415 |
-
```
|
| 416 |
-
|
| 417 |
-
### Static Checks
|
| 418 |
-
|
| 419 |
-
FastMCP uses `pre-commit` for code formatting, linting, and type-checking. All PRs must pass these checks (they run automatically in CI).
|
| 420 |
-
|
| 421 |
-
Install the hooks locally:
|
| 422 |
-
|
| 423 |
-
```bash
|
| 424 |
-
uv run pre-commit install
|
| 425 |
-
```
|
| 426 |
-
|
| 427 |
-
The hooks will now run automatically on `git commit`. You can also run them manually at any time:
|
| 428 |
-
|
| 429 |
-
```bash
|
| 430 |
-
pre-commit run --all-files
|
| 431 |
-
# or via uv
|
| 432 |
-
uv run pre-commit run --all-files
|
| 433 |
-
```
|
| 434 |
|
| 435 |
### Pull Requests
|
| 436 |
|
|
@@ -439,6 +169,6 @@ uv run pre-commit run --all-files
|
|
| 439 |
3. Make your changes, including tests and documentation updates.
|
| 440 |
4. Ensure tests and pre-commit hooks pass.
|
| 441 |
5. Commit your changes and push to your fork.
|
| 442 |
-
6. Open a pull request against the `main` branch of `
|
| 443 |
|
| 444 |
Please open an issue or discussion for questions or suggestions before starting significant work!
|
|
|
|
| 1 |
---
|
| 2 |
+
title: xsecuremcp
|
| 3 |
emoji: 🛡️
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: blue
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
|
|
|
| 10 |
<div align="center">
|
| 11 |
|
| 12 |
<!-- omit in toc -->
|
| 13 |
+
# SecureMCP 🔒
|
| 14 |
|
| 15 |
+
<strong>The secure, enterprise-ready way to build MCP servers and clients.</strong>
|
| 16 |
|
| 17 |
+
*Built for security-first organizations*
|
| 18 |
|
| 19 |
+
[](https://purecipher.com)
|
| 20 |
+
[](https://github.com/PureCipher/xsecuremcp/blob/main/LICENSE)
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
<a href="https://trendshift.io/repositories/PureCipher/xsecuremcp" target="_blank"><img src="https://trendshift.io/api/badge/repositories/PureCipher/xsecuremcp" alt="PureCipher%2Fxsecuremcp | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
| 23 |
</div>
|
| 24 |
|
| 25 |
> [!Note]
|
| 26 |
>
|
| 27 |
+
> #### Security-First MCP Framework
|
|
|
|
|
|
|
| 28 |
>
|
| 29 |
+
> SecureMCP is the enterprise-grade framework for building secure Model Context Protocol servers and clients. **Built on the foundation of [FastMCP](https://github.com/jlowin/fastmcp)** by [Prefect](https://www.prefect.io/), SecureMCP extends the excellent FastMCP framework with comprehensive security features designed for production environments.
|
| 30 |
>
|
| 31 |
+
> SecureMCP provides **enterprise-grade security** with features including advanced authentication, authorization, audit logging, data encryption, compliance tools, and secure deployment patterns.
|
| 32 |
>
|
| 33 |
+
> Ready to secure your MCP infrastructure? Follow the [installation instructions](https://purecipher.com) to get started with SecureMCP.
|
| 34 |
|
| 35 |
---
|
| 36 |
|
| 37 |
+
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) is a new, standardized way to provide context and tools to your LLMs, and SecureMCP makes building secure, enterprise-ready MCP servers and clients simple and intuitive. Create secure tools, expose protected resources, define authenticated prompts, and connect components with enterprise-grade security built-in.
|
| 38 |
|
| 39 |
```python
|
| 40 |
# server.py
|
| 41 |
+
from securemcp import SecureMCP
|
| 42 |
+
from securemcp.auth import JWTProvider
|
| 43 |
+
from securemcp.policy import RoleBasedAccess
|
| 44 |
+
|
| 45 |
+
mcp = SecureMCP("Secure Demo 🔒")
|
| 46 |
+
|
| 47 |
+
# Configure authentication
|
| 48 |
+
mcp.auth_provider = JWTProvider(secret_key="your-secret-key")
|
| 49 |
|
| 50 |
+
# Configure access control
|
| 51 |
+
mcp.access_control = RoleBasedAccess()
|
| 52 |
|
| 53 |
+
@mcp.tool(requires_auth=True, roles=["user", "admin"])
|
| 54 |
def add(a: int, b: int) -> int:
|
| 55 |
+
"""Add two numbers - requires authentication"""
|
| 56 |
return a + b
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
|
|
|
| 62 |
Run the server locally:
|
| 63 |
|
| 64 |
```bash
|
| 65 |
+
securemcp run server.py
|
| 66 |
```
|
| 67 |
|
| 68 |
### 📚 Documentation
|
| 69 |
|
| 70 |
+
SecureMCP's complete documentation is available at **[purecipher.com](https://purecipher.com)**, including detailed security guides, API references, and enterprise deployment patterns. This readme provides only a high-level overview.
|
| 71 |
|
| 72 |
Documentation is also available in [llms.txt format](https://llmstxt.org/), which is a simple markdown standard that LLMs can consume easily.
|
| 73 |
|
| 74 |
There are two ways to access the LLM-friendly documentation:
|
| 75 |
|
| 76 |
+
- [`llms.txt`](https://purecipher.com) is essentially a sitemap, listing all the pages in the documentation.
|
| 77 |
+
- [`llms-full.txt`](https://purecipher.com) contains the entire documentation. Note this may exceed the context window of your LLM.
|
| 78 |
|
| 79 |
---
|
| 80 |
|
|
|
|
| 82 |
## Table of Contents
|
| 83 |
|
| 84 |
- [What is MCP?](#what-is-mcp)
|
| 85 |
+
- [Why SecureMCP?](#why-securemcp)
|
| 86 |
+
- [Security Features](#security-features)
|
| 87 |
+
- [Credits](#credits)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
- [Contributing](#contributing)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
---
|
| 91 |
|
|
|
|
| 98 |
- Define interaction patterns through **Prompts** (reusable templates for LLM interactions)
|
| 99 |
- And more!
|
| 100 |
|
| 101 |
+
SecureMCP provides a high-level, Pythonic interface for building, managing, and interacting with these servers with enterprise-grade security.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
## Why SecureMCP?
|
| 104 |
|
| 105 |
+
The MCP protocol is powerful but implementing it securely in enterprise environments involves complex security considerations - authentication, authorization, audit logging, data encryption, compliance requirements, and secure deployment patterns. SecureMCP handles all the security complexities and enterprise requirements, so you can focus on building secure tools that meet compliance standards.
|
| 106 |
|
| 107 |
+
**SecureMCP extends [FastMCP](https://github.com/jlowin/fastmcp)** - the excellent, fast, and Pythonic MCP framework by [Prefect](https://www.prefect.io/) - with comprehensive enterprise-grade security features. While FastMCP provides outstanding server-building capabilities and developer experience, SecureMCP adds a complete security-focused ecosystem including advanced authentication systems, role-based access control, audit logging, data encryption, compliance tools, and secure deployment patterns.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
SecureMCP aims to be:
|
| 110 |
|
| 111 |
+
🔒 **Secure:** Enterprise-grade security built-in from the ground up
|
| 112 |
|
| 113 |
+
🛡️ **Compliant:** Meets SOC2, HIPAA, and other compliance requirements
|
| 114 |
|
| 115 |
+
🏢 **Enterprise-Ready:** Designed for production environments with strict security needs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
🔍 **Auditable:** Comprehensive logging and monitoring for security compliance
|
| 118 |
|
| 119 |
+
## Security Features
|
| 120 |
|
| 121 |
+
SecureMCP provides comprehensive security features designed for enterprise environments:
|
| 122 |
|
| 123 |
+
### 🔐 Authentication & Authorization
|
| 124 |
+
- **Multiple Auth Providers**: JWT, OAuth2, SAML, LDAP, and custom authentication
|
| 125 |
+
- **Role-Based Access Control**: Fine-grained permissions and role management
|
| 126 |
+
- **Multi-Factor Authentication**: Support for MFA and 2FA
|
| 127 |
+
- **Session Management**: Secure session handling with configurable timeouts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
+
### 🛡️ Data Protection
|
| 130 |
+
- **End-to-End Encryption**: TLS/SSL encryption for all communications
|
| 131 |
+
- **Data Encryption at Rest**: Encrypt sensitive data stored by the server
|
| 132 |
+
- **Input Validation**: Comprehensive input sanitization and validation
|
| 133 |
+
- **Output Filtering**: Prevent data leakage through response filtering
|
| 134 |
|
| 135 |
+
### 📊 Compliance & Auditing
|
| 136 |
+
- **Audit Logging**: Comprehensive logging of all operations and access
|
| 137 |
+
- **Compliance Frameworks**: Built-in support for SOC2, HIPAA, GDPR, and more
|
| 138 |
+
- **Security Monitoring**: Real-time security event monitoring and alerting
|
| 139 |
+
- **Data Retention**: Configurable data retention policies
|
| 140 |
|
| 141 |
+
### 🚀 Secure Deployment
|
| 142 |
+
- **Container Security**: Secure container deployment with minimal attack surface
|
| 143 |
+
- **Network Security**: Configurable network policies and firewall rules
|
| 144 |
+
- **Secret Management**: Secure handling of API keys, certificates, and secrets
|
| 145 |
+
- **Health Checks**: Security-focused health monitoring and reporting
|
| 146 |
|
| 147 |
+
## Credits
|
| 148 |
|
| 149 |
+
SecureMCP is built on the solid foundation of **[FastMCP](https://github.com/jlowin/fastmcp)** by [Prefect](https://www.prefect.io/). We extend our sincere gratitude to the FastMCP team for creating an excellent, fast, and Pythonic framework for building MCP servers and clients.
|
| 150 |
|
| 151 |
+
**FastMCP** provides:
|
| 152 |
+
- High-level, Pythonic interface for MCP development
|
| 153 |
+
- Comprehensive tool, resource, and prompt management
|
| 154 |
+
- Multiple transport protocols (STDIO, HTTP, SSE)
|
| 155 |
+
- Client libraries and testing frameworks
|
| 156 |
+
- OpenAPI and FastAPI integration
|
| 157 |
+
- And much more!
|
| 158 |
|
| 159 |
+
SecureMCP adds enterprise-grade security features on top of this excellent foundation, making it suitable for production environments with strict security and compliance requirements.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
## Contributing
|
| 162 |
|
| 163 |
+
Contributions are the core of open source! We welcome improvements and security enhancements.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
### Pull Requests
|
| 166 |
|
|
|
|
| 169 |
3. Make your changes, including tests and documentation updates.
|
| 170 |
4. Ensure tests and pre-commit hooks pass.
|
| 171 |
5. Commit your changes and push to your fork.
|
| 172 |
+
6. Open a pull request against the `main` branch of `PureCipher/xsecuremcp`.
|
| 173 |
|
| 174 |
Please open an issue or discussion for questions or suggestions before starting significant work!
|