MCP Security Gateway
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
MCP Security Gateway β Stage 1: Basic MCP Server
This is Stage 1 of building an MCP Security Gateway from scratch. In this stage, a basic Model Context Protocol (MCP) server is built using Python to expose local file operation tools directly to an MCP client.
π Project Structure
mcp-security-gateway/
βββ server/
β βββ server.py # Main MCP Server exposing local file tools
βββ test_data/
β βββ hello.txt # Test directory containing sample files
βββ verify_server.py # Automated verification script to test tools over stdio
βββ requirements.txt # Dependencies (Official MCP Python SDK)Related MCP server: Files MCP Server
βοΈ Requirements & Installation
Python: Python 3.10 or higher (Tested with Python 3.14)
Official MCP SDK:
mcppackage
Installation Step:
pip install -r requirements.txtπ How to Run the MCP Server
The MCP server uses standard input/output (stdio) transport. You can run the server directly using:
python server/server.pyNote: Since the server communicates via JSON-RPC messages over standard I/O streams (stdin/stdout), running it directly in a terminal will wait for incoming JSON-RPC stdin input.
π οΈ Exposed Tools
The server registers three tools with the MCP runtime:
list_files()Description: Lists all filenames present in
test_data/.Parameters: None.
read_file(filename)Description: Reads and returns text content from a file inside
test_data/.Parameters:
filename(string).Security: Resolves the path relative to
test_data/and blocks path traversal (../).
write_file(filename, content)Description: Creates or overwrites a file inside
test_data/.Parameters:
filename(string),content(string).Security: Blocks path traversal (
../).
π§ͺ Verification & Testing
To verify that the MCP server runs correctly and that all 3 tools are exposed and functional:
Run the automated client verification script:
python verify_server.pyExpected Output:
Connecting to MCP Server via stdio transport...
Session initialized successfully.
[TOOLS DISCOVERED] (3 tools found):
- list_files: List the names of all files inside the test_data directory.
- read_file: Read and return the text contents of a specified file inside test_data.
- write_file: Create or overwrite a file inside test_data with the provided content.
[TEST 1] Calling list_files()...
Result: hello.txt
[TEST 2] Calling read_file('hello.txt')...
Result:
Hello from MCP Server!
[TEST 3] Calling write_file('test_output.txt', '...')
Result: Success: File 'test_output.txt' successfully written to test_data.
[TEST 4] Testing path traversal prevention with '../server/server.py'...
Result: Security Error: Access Denied: Path traversal detected for '../server/server.py'...π§ Internal Mechanics of the MCP Server
1. Transport Layer (stdio)
The server uses stdio (standard input/output) as its communication transport. The client spawns the server script as a child process and sends JSON-RPC 2.0 messages over standard input (stdin), while reading response messages from standard output (stdout).
2. Protocol Handshake & Tool Discovery
When a client connects:
Initialize Request: The client sends an
initializerequest to negotiate protocol capability versions.List Tools Request: The client sends a
tools/listrequest. The MCP SDK inspects all functions decorated with@mcp.tool(), extracts their function signatures, type hints, and docstrings, and converts them into standard JSON schema tool definitions.
3. Tool Execution (tools/call)
When an AI agent/client invokes a tool:
The client sends a
tools/callJSON-RPC message containing the toolnameandarguments.The MCP SDK routes the request to the matching Python function (
list_files,read_file, orwrite_file).The result (or error message) is serialized into an MCP
TextContentpayload and sent back overstdout.
4. Path Traversal Defense
Each file tool utilizes get_safe_path() using Python's pathlib.Path:
Canonical resolution:
.resolve()resolves relative parts (..) and symlinks.Scope containment:
.is_relative_to(BASE_DIR)checks if the resolved path stays insidetest_data/. Any attempt to escape raises a security exception.
π― Current Stage Architecture
MCP Client (verify_server.py)
β (JSON-RPC over stdio)
βΌ
MCP Server (server/server.py)
β (pathlib validation)
βΌ
Local Files (test_data/)In future stages, a Security Gateway will be interposed between the Client and Server to enforce authorization, auditing, and policy checks.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
Related MCP Connectors
Ovanek MCP: Model Context Protocol server for Ovanek platform tools; writes are dry-run by default.
Security research canary remote MCP server for owned-account testing.
MCP server for Superserve sandboxes: create, exec, and manage Firecracker microVMs
MCP compatibility and transport verification server.
Related MCP Servers
- AlicenseAqualityAmaintenanceFilesystem MCP server for AI assistants. Search, read, edit, and manage local files in directories you choose.6141,447 npm34MIT
- AlicenseNot gradedqualityDmaintenanceStdio MCP server for sandboxed file access β read files, search content, safely edit with checksums, and manage file structure.MIT
- AlicenseNot gradedqualityBmaintenanceA small filesystem MCP server that reads and writes files under one confined root over stdio, with paginated tools and strict change-detection. It enables safe, deterministic file access for agentic runtimes and MCP clients.28 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients to list recorded runs and read declared plan artifacts β plans, journals, and outputs β from a local runs directory over stdio, with traversal and undeclared-file protections.Apache 2.0