MCP Security Gateway
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Security Gatewaylist the files in test_data and read hello.txt"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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.
This server cannot be deployed
Maintenance
Related MCP Connectors
Security research canary remote MCP server for owned-account testing.
MCP server for Superserve sandboxes: create, exec, and manage Firecracker microVMs
Read and write shared BitsWeave context, projects, tasks, and work sessions through MCP.
Agent-native MCP server over the public saagarpatel.dev corpus. Read-only, stateless.
Related MCP Servers
- AlicenseAqualityAmaintenanceMCP Server that enables LLMs to interact with the local filesystem.131,086 npm22MIT
- AlicenseNot gradedqualityDmaintenanceStdio MCP server for sandboxed file access โ read files, search content, safely edit with checksums, and manage file structure.4 npmISC
- AlicenseNot gradedqualityCmaintenanceMCP server that exposes file operations (list, read, write, delete, unzip) in a sandbox directory, preventing path traversal.11 npmMIT
- AlicenseNot gradedqualityAmaintenanceA 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.113 npmMIT