mcp-resk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mcp_resk-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ include LICENSE
2
+ include README.md
3
+ include requirements.txt
4
+ include config.yaml.example
5
+ global-exclude __pycache__
6
+ global-exclude *.py[cod]
7
+ global-exclude *.so
8
+ global-exclude .git*
mcp_resk-0.1.0/Notice ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Anthropic, PBC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,339 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-resk
3
+ Version: 0.1.0
4
+ Summary: RESK-MCP is an open-source Python library designed to add a robust security and management layer over the official MCP Library.
5
+ Author-email: RESK Team <your.email@example.com>
6
+ License: MIT License
7
+ Project-URL: Homepage, https://github.com/your-username/mcp-resk
8
+ Project-URL: Bug Tracker, https://github.com/your-username/mcp-resk/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ License-File: Notice
20
+ Requires-Dist: fastapi>=0.115.12
21
+ Requires-Dist: mcp[cli]>=1.9.0
22
+ Requires-Dist: pydantic>=2.11.4
23
+ Requires-Dist: pyjwt[crypto]>=2.10.1
24
+ Requires-Dist: python-dotenv>=1.1.0
25
+ Requires-Dist: pyyaml>=6.0.2
26
+ Requires-Dist: requests>=2.32.3
27
+ Requires-Dist: slowapi>=0.1.9
28
+ Requires-Dist: types-pyyaml>=6.0.12.20250516
29
+ Requires-Dist: uvicorn>=0.34.2
30
+ Dynamic: license-file
31
+
32
+ # RESK-MCP: Secure Model Context Protocol Layer
33
+
34
+ [![PyPI version](https://img.shields.io/pypi/v/mcp-resk.svg)](https://pypi.org/project/mcp-resk/)
35
+ [![Python Versions](https://img.shields.io/pypi/pyversions/mcp-resk.svg)](https://pypi.org/project/mcp-resk/)
36
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
37
+ [![Downloads](https://static.pepy.tech/badge/mcp-resk)](https://pepy.tech/project/mcp-resk)
38
+ [![GitHub issues](https://img.shields.io/github/issues/Resk-Security/mcp-resk.svg)](https://github.com/Resk-Security/mcp-resk/issues)
39
+ [![GitHub Stars](https://img.shields.io/github/stars/Resk-Security/mcp-resk?style=social)](https://github.com/Resk-Security/mcp-resk/stargazers)
40
+ [![GitHub Forks](https://img.shields.io/github/forks/Resk-Security/mcp-resk?style=social)](https://github.com/Resk-Security/mcp-resk/network/members)
41
+ [![Documentation Status](https://readthedocs.org/projects/mcp-resk/badge/?version=latest)](https://mcp-resk.readthedocs.io/en/latest/?badge=latest)
42
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
43
+ [![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
44
+ [![GitHub last commit](https://img.shields.io/github/last-commit/Resk-Security/mcp-resk.svg)](https://github.com/Resk-Security/mcp-resk/commits/main)
45
+ [![PyPI - Implementation](https://img.shields.io/pypi/implementation/mcp-resk.svg)](https://pypi.org/project/mcp-resk/)
46
+ [![LLM Security](https://img.shields.io/badge/LLM%20Security-Enhanced-brightgreen.svg)](https://github.com/Resk-Security/mcp-resk)
47
+
48
+ RESK-MCP is an open-source Python library that adds a robust security and management layer over the official [Model Context Protocol (MCP) Python SDK](https://github.com/modelcontextprotocol/python-sdk). It provides enhanced security features, monitoring capabilities, and tools for managing MCP interactions.
49
+
50
+
51
+ ## Features
52
+
53
+
54
+ - **JWT Authentication**: Secure MCP server endpoints with JSON Web Tokens
55
+ - **Input Validation**: Validate all incoming MCP requests using Pydantic
56
+ - **PII Detection**: Basic detection of Personally Identifiable Information in request parameters
57
+ - **Prompt Injection Protection**: Detection of common prompt injection phrases
58
+ - **Rate Limiting**: Configurable per-user or per-IP rate limits using `slowapi`
59
+ - **Token-Based Context Management**: Limit request size based on estimated token count
60
+ - **Interaction Tracking**: Monitor calls to tools, resources, and prompts
61
+ - **Dashboard**: Web-based visualization of MCP interactions and server configuration
62
+ - **Easy Configuration**: Simple setup using environment variables
63
+ - **HTTPS Support**: Built-in SSL/TLS configuration
64
+
65
+ ## Installation
66
+
67
+ ```bash
68
+ # Clone the repository (if contributing or running from source)
69
+ git clone https://github.com/Resk-Security/mcp-resk.git
70
+ cd mcp-resk
71
+
72
+ # Create and activate virtual environment
73
+ python -m venv venv
74
+
75
+ # On Windows
76
+ # .\venv\Scripts\activate
77
+
78
+ # On macOS/Linux
79
+ # source venv/bin/activate
80
+
81
+ # Install dependencies using uv (recommended)
82
+ uv pip install -r requirements.txt
83
+
84
+ # For development with editable install
85
+ uv pip install -e .
86
+
87
+ # If contributing or running tests
88
+ uv pip install -e ".[dev]"
89
+ ```
90
+
91
+ > **Note**: We use [uv](https://github.com/astral-sh/uv) as the recommended package installer because it's significantly faster than pip and provides better dependency resolution. It's also used in our CI/CD workflow.
92
+
93
+ ## Configuration
94
+
95
+ Create a `.env` file in your project root:
96
+
97
+ ```env
98
+ # Required
99
+ JWT_SECRET="your-super-secure-jwt-secret-key-here"
100
+
101
+ # Optional configurations
102
+ RATE_LIMIT="100/minute" # Format: "count/period" (e.g., "5/second", "1000/hour")
103
+ MAX_TOKEN_PER_REQUEST="4000"
104
+ LOG_LEVEL="INFO"
105
+
106
+ # For HTTPS
107
+ # SSL_KEYFILE="./key.pem"
108
+ # SSL_CERTFILE="./cert.pem"
109
+ ```
110
+
111
+ ### ⚠️ JWT Security Warning
112
+
113
+ The security of your MCP server relies heavily on the strength of your JWT secret:
114
+
115
+ - **NEVER** use simple, predictable, or default JWT secrets in production
116
+ - Use a strong, randomly generated secret with high entropy (at least 32 characters)
117
+ - Do not store JWT secrets in your code or commit them to version control
118
+ - Rotate JWT secrets periodically in production environments
119
+ - Consider using environment-specific secrets for different deployments
120
+ - If you suspect a JWT secret has been compromised, rotate it immediately
121
+
122
+ The `JWT_SECRET` is used to sign and verify all authentication tokens. A compromised secret would allow attackers to forge valid tokens and bypass your authentication system entirely.
123
+
124
+ ## Usage Example
125
+
126
+ ```python
127
+ # main.py
128
+ import os
129
+ from dotenv import load_dotenv
130
+ from resk_mcp import SecureMCPServer, create_jwt_token
131
+
132
+ load_dotenv()
133
+
134
+ # Initialize the secure server
135
+ server = SecureMCPServer(name="MySecureCalculatorApp")
136
+
137
+ # Define a sample tool
138
+ @server.tool(name="calculator/add")
139
+ async def add(a: int, b: int) -> int:
140
+ """Adds two numbers."""
141
+ return a + b
142
+
143
+ @server.resource(path_pattern="info/version")
144
+ async def get_version() -> dict:
145
+ """Returns the application version."""
146
+ return {"version": "1.0-secure"}
147
+
148
+ if __name__ == "__main__":
149
+ # Generate a test token
150
+ jwt_secret = os.getenv("JWT_SECRET")
151
+ if not jwt_secret:
152
+ print("Error: JWT_SECRET not found. Please set it in .env file.")
153
+ exit(1)
154
+
155
+ test_user_id = "user@example.com"
156
+ token = create_jwt_token(user_id=test_user_id, secret_key=jwt_secret)
157
+ print(f"Test Token: Bearer {token}\n")
158
+
159
+ # Start the server
160
+ ssl_key_path = os.getenv("SSL_KEYFILE")
161
+ ssl_cert_path = os.getenv("SSL_CERTFILE")
162
+
163
+ if ssl_key_path and ssl_cert_path:
164
+ server.run_server(port=8001, ssl_keyfile=ssl_key_path, ssl_certfile=ssl_cert_path)
165
+ else:
166
+ server.run_server(port=8001)
167
+ ```
168
+
169
+ ## Troubleshooting
170
+
171
+ ### JWT Authentication: "Signature verification failed"
172
+
173
+ If you encounter `WARNING:resk_mcp.server:Authentication failed for /mcp_secure: Invalid token: Signature verification failed` errors when running test_client.py against example_server.py, it means the JWT (JSON Web Token) sent by the client could not be verified by the server. This almost always indicates a mismatch in the JWT_SECRET used to sign the token (client-side or how the token was originally generated) and the JWT_SECRET used by the server to verify it.
174
+
175
+ #### How JWT Authentication is Setup in this Example:
176
+
177
+ **Server-Side (example_server.py):**
178
+
179
+ - The server relies on a JWT_SECRET for signing and verifying tokens.
180
+ - This secret is primarily configured via a .env file at the root of the project. The resk_mcp/config.py module loads this secret into the application's settings (settings.jwt_secret).
181
+ - When example_server.py starts, it generates a test JWT using this settings.jwt_secret and prints it to the console. This is the token your test_client.py should be using.
182
+
183
+ **Client-Side (test_client.py):**
184
+
185
+ - The test_client.py has a hardcoded AUTH_TOKEN variable.
186
+ - This token is sent in the Authorization header for requests to the secure MCP endpoint.
187
+
188
+ #### The Mismatch:
189
+
190
+ The "Signature verification failed" error occurs if the AUTH_TOKEN in test_client.py was not generated using the exact same JWT_SECRET that example_server.py is currently configured with (via its .env file).
191
+
192
+ #### How to Fix It:
193
+
194
+ **Ensure JWT_SECRET is Configured for the Server:**
195
+
196
+ 1. Create a file named .env in the root directory of this project (e.g., alongside example_server.py).
197
+ 2. Add your desired secret key to it:
198
+ ```
199
+ JWT_SECRET="your_very_strong_and_unique_secret_key_here"
200
+ ```
201
+ 3. Important: If you change this secret, any previously generated tokens (including the one in test_client.py) will become invalid.
202
+
203
+ **Run the Server (example_server.py):**
204
+
205
+ Execute `python example_server.py`.
206
+
207
+ **Copy the Correct Token from Server Logs:**
208
+
209
+ 1. Look for a log message from the server similar to this:
210
+ ```
211
+ INFO:example-server:Token de test généré (utilisant JWT_SECRET du .env): eyJhbGciOiJIUzI1NiI...[long_token_string]...
212
+ ```
213
+ (The message might be slightly different if you changed the log language/format, but it will contain the generated token.)
214
+ 2. Carefully copy the entire token string (it's usually very long).
215
+
216
+ **Update test_client.py:**
217
+
218
+ 1. Open test_client.py.
219
+ 2. Find the line:
220
+ ```python
221
+ AUTH_TOKEN = "some_old_or_incorrect_token_here"
222
+ ```
223
+ 3. Replace the old token string with the new token you just copied from the server logs.
224
+ ```python
225
+ AUTH_TOKEN = "eyJhbGciOiJIUzI1NiI...[the_new_long_token_string_you_copied]..."
226
+ ```
227
+
228
+ **Run the Client (test_client.py):**
229
+
230
+ Now, execute `python test_client.py`.
231
+ The authentication errors should be gone, and your client should be able to communicate with the server successfully.
232
+
233
+ **Key Takeaway:** The AUTH_TOKEN used by the client must be a token that was signed with the exact same JWT_SECRET that the server is currently using for verification. The easiest way to ensure this in this example setup is to always use the token printed by example_server.py on startup.
234
+
235
+ ## Detailed Configuration
236
+
237
+ RESK-MCP uses environment variables for configuration. Create a `.env` file in the root of your project with the following (at a minimum):
238
+
239
+ ```env
240
+ # .env
241
+ JWT_SECRET="your-super-secure-jwt-secret-key-here"
242
+
243
+ # Rate Limiting (default: "100/minute")
244
+ # Examples: "5/second", "1000/hour", "20/day"
245
+ RATE_LIMIT="100/minute"
246
+
247
+ # Optional for HTTPS:
248
+ # SSL_KEYFILE="./key.pem"
249
+ # SSL_CERTFILE="./cert.pem"
250
+
251
+ # Optional for context management and logging:
252
+ # MAX_TOKEN_PER_REQUEST="4000"
253
+ # LOG_LEVEL="INFO"
254
+ ```
255
+
256
+ - **JWT_SECRET**: A strong, random secret key for signing JWT tokens. This is critical for security.
257
+ - **RATE_LIMIT**: Defines the rate limit for requests. The format is count/period (e.g., 100/minute, 5/second). Defaults to 100/minute. Rate limiting is primarily based on the user_id from the JWT, falling back to IP address if the token is invalid or missing.
258
+ - **SSL_KEYFILE**: Path to your SSL private key file (e.g., key.pem).
259
+ - **SSL_CERTFILE**: Path to your SSL certificate file (e.g., cert.pem).
260
+ - **MAX_TOKEN_PER_REQUEST**: Approximate maximum tokens allowed per request (default: 4000).
261
+ - **LOG_LEVEL**: Logging level (e.g., DEBUG, INFO, WARNING, ERROR, CRITICAL, default: INFO).
262
+
263
+ ### Generating SSL Certificates (for HTTPS)
264
+
265
+ For local development, you can generate self-signed certificates using OpenSSL:
266
+
267
+ ```bash
268
+ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 -nodes -subj "/CN=localhost"
269
+ ```
270
+
271
+ For production, obtain certificates from a trusted Certificate Authority (CA) like Let's Encrypt.
272
+
273
+ ## Dashboard
274
+
275
+ Access the analytics dashboard at `http://localhost:8001/dashboard`. It provides:
276
+
277
+ - Real-time visualization of MCP interactions
278
+ - Server configuration details
279
+ - Lists of registered tools, resources, and prompts
280
+
281
+ ![Dashboard Server Info](static/images/dashboard-server-info.png)
282
+
283
+ ## Testing
284
+
285
+ ```bash
286
+ # Run tests
287
+ uv run pytest
288
+
289
+ # Run all checks (linting, type checking, tests)
290
+ python run_checks.py
291
+ ```
292
+
293
+ ## Project Structure
294
+
295
+ ```
296
+ resk-mcp/
297
+ ├── resk_mcp/ # Main library code
298
+ │ ├── server.py # SecureMCPServer implementation
299
+ │ ├── auth.py # JWT authentication
300
+ │ ├── validation.py # Input validation and security
301
+ │ ├── context.py # Context management
302
+ │ └── dashboard.py # Dashboard routes
303
+ ├── static/ # Dashboard UI assets
304
+ ├── tests/ # Test suite
305
+ ├── .env.example # Example configuration
306
+ ├── requirements.txt # Dependencies
307
+ └── README.md
308
+ ```
309
+
310
+ ## CI/CD Workflow
311
+
312
+ This project uses GitHub Actions for continuous integration and deployment:
313
+
314
+ - **Automated Testing**: All pushes and PRs to the `main` branch trigger tests on Python 3.9 and 3.10
315
+ - **Code Quality**: Includes linting with flake8 and type checking with mypy
316
+ - **Package Publishing**: Tagged versions (format `v*`) are automatically published to PyPI
317
+ - **Release Creation**: GitHub Releases are automatically created for each tagged version
318
+
319
+ The workflow configuration is defined in `.github/workflows/python-package.yml`.
320
+
321
+ ## Contributing
322
+
323
+ Contributions are welcome! Please follow these steps:
324
+
325
+ 1. Fork the repository
326
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
327
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
328
+ 4. Push to your branch (`git push origin feature/amazing-feature`)
329
+ 5. Open a Pull Request
330
+
331
+ > **Note**: This project uses `main` as the default branch. All PRs should be made against the `main` branch.
332
+
333
+ ## License
334
+
335
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
336
+
337
+ ## Disclaimer
338
+
339
+ This library provides basic security features. For production systems, ensure comprehensive security audits and consider more advanced techniques for PII and prompt injection detection tailored to your specific use case.