ahmad-act/MCP-Server-with-Authentication-and-Testing-with-Inspector
If you are the rightful owner of MCP-Server-with-Authentication-and-Testing-with-Inspector and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This project implements a Model Context Protocol (MCP) server with authentication mechanisms and testing capabilities using the MCP Inspector.
The MCP Server with Authentication and Testing with Inspector is a robust framework designed to handle authenticated requests using two primary authentication methods: API Key Authentication and JWT Authentication. It is tailored for developers seeking a secure, scalable, and extensible server environment with comprehensive error handling and logging. The server supports various tools such as `echo`, `login`, `secure_action`, and `admin_action`, with authentication enforced where necessary. The integration with MCP Inspector allows for efficient testing and debugging, making it suitable for production environments. The server is built to be compatible with multiple operating systems, including Windows, macOS, and Linux, and requires Python 3.13 or higher, along with Node.js and NPM for running the MCP Inspector.
Features
- API Key Authentication: Validates requests using predefined API keys, supporting key extraction from arguments, metadata, or environment variables.
- JWT Authentication: Provides user authentication via username/password to generate JWT tokens, enforcing permission-based access control.
- Robust Error Handling: Utilizes custom McpError for consistent error responses and detailed logging of errors and server events.
- Logging: Configurable logging to both console and rotating log files, with automatic cleanup of old log files.
- MCP Inspector Integration: Compatible with MCP Inspector for testing and debugging, supporting debugging via a --debug flag.
Tools
echo
A simple tool for demonstrating basic functionality.
login
Allows users to authenticate and obtain a JWT token.
secure_action
Performs actions requiring authentication.
admin_action
Performs administrative actions requiring elevated permissions.