safe-code-mcp
Click on "Install 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., "@safe-code-mcpshow me the contents of package.json"
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.
safe-code-mcp
safe-code-mcp is a local Model Context Protocol (MCP) server that gives Codex or another MCP client controlled access to a repository. It exposes a small set of repository tools, checks every requested path against policy.yml, redacts obvious secrets from returned content, and writes an audit event for each tool call.
The goal is not to make the MCP protocol itself complicated. The goal is to create a narrow, reviewable access layer between an AI coding agent and project files.
Architecture
flowchart TD
Client["Codex CLI or MCP client"]
Transport["stdio transport"]
Server["safe-code-mcp<br/>NestJS + MCP SDK"]
Tools["MCP tools<br/>policy/list/read/search/propose"]
Policy["policy.yml<br/>allow + deny rules"]
Guard["path validation<br/>repo boundary check"]
Redact["redaction scanner"]
Audit["audit.log"]
Repo["repository files"]
Client --> Transport
Transport --> Server
Server --> Tools
Tools --> Policy
Policy --> Guard
Guard --> Repo
Repo --> Redact
Redact --> Client
Tools --> AuditRelated MCP server: Waymark
Available Tools
Tool | Purpose | Inputs |
| Lists files visible under the configured policy. | none |
| Returns the active allow/deny policy, read limits, and audit path. | none |
| Lists immediate visible children under a directory without returning file contents. |
|
| Returns metadata for an allowed file without reading its contents. |
|
| Reads a bounded line range from an allowed file and redacts obvious secrets. |
|
| Reads a redacted context window around a target line. |
|
| Searches allowed files for a literal query and redacts matching lines. |
|
| Accepts a patch proposal, scans it for secrets, and returns it for manual review. |
|
read_file requires startLine >= 1 and endLine >= 1. The server also caps reads using maxReadLines from policy.yml.
Policy Model
Access is controlled by policy.yml.
flowchart LR
Request["tool request<br/>file path"]
Normalize["normalize path"]
Escape{"escapes<br/>repo root?"}
Deny{"matches<br/>deny rule?"}
Allow{"matches<br/>allow rule?"}
Use["allow tool operation"]
Reject["reject request"]
Request --> Normalize
Normalize --> Escape
Escape -- yes --> Reject
Escape -- no --> Deny
Deny -- yes --> Reject
Deny -- no --> Allow
Allow -- yes --> Use
Allow -- no --> RejectThe current policy allows common source, test, documentation, and project metadata paths, including:
src/**tests/**,test/**,__tests__/**docs/**,adr/**,openapi/**,api/**package.json,package-lock.json,tsconfig*.json,nest-cli.json,README.mddeployment templates such as
docker-compose*.yml,k8s/**,helm/**, and selected Terraform templates
The current policy denies sensitive or noisy paths, including:
.env*and nested environment filesprivate keys, certificates, keystores, GPG files, and credential paths
.git/**,node_modules/**,dist/**, build output, caches, and coverageOS metadata files such as
.DS_StoreandThumbs.dblogs, audit evidence, database dumps, backups, exports, spreadsheets, SQL files, and data files
production configuration paths
customer, card, payment, and regulated sample data directories
If a file matches both allow and deny rules, the deny rule wins.
Redaction
Returned content is passed through a lightweight redaction scanner. It currently detects common patterns such as:
OpenAI-style
sk-...tokensAWS access key IDs
private key blocks
common database connection URLs
bearer tokens
assignments containing names like
api_key,secret,token, orpassword
This redaction layer is a safety net, not a replacement for the policy. Sensitive paths should still be denied in policy.yml.
Audit Log
Every tool call writes an append-only JSON event to the configured audit log:
auditLog: "./audit.log"The audit events include details such as the tool name, file path, line range, search match counts, and redaction counts. Treat this file as operational evidence. The default policy denies *.log files, so the MCP tools should not expose audit.log.
Run Locally
Install dependencies:
npm installBuild the project:
npm run buildRun the compiled stdio MCP server:
node dist/server.jsFor development, run the TypeScript entrypoint through tsx:
npx tsx src/server.tsInspect The Server
Use the MCP Inspector to test the local server:
npx @modelcontextprotocol/inspector node dist/server.jsCodex Configuration
Add a server entry like this to ~/.codex/config.toml:
[mcp.servers.safe-code]
command = "npx"
args = ["tsx", "src/server.ts"]
cwd = "/Volumes/Projects/ERP-Hub Inc/storeVein/erp-mcp-starter"After restarting Codex, the MCP client should be able to call the safe-code-mcp tools.
Example Tool Calls
List files visible through the policy:
{
"name": "list_allowed_files",
"arguments": {}
}Read the first 25 lines of a source file:
{
"name": "read_file",
"arguments": {
"filePath": "src/main.ts",
"startLine": 1,
"endLine": 25
}
}Read context around a specific line:
{
"name": "read_file_context",
"arguments": {
"filePath": "src/mcp.service.ts",
"line": 120,
"contextLines": 20
}
}Get file metadata without reading content:
{
"name": "file_info",
"arguments": {
"filePath": "src/mcp.service.ts"
}
}Search allowed files:
{
"name": "search_code",
"arguments": {
"query": "McpService"
}
}Submit a patch proposal for review:
{
"name": "propose_patch",
"arguments": {
"filePath": "src/main.ts",
"diff": "--- a/src/main.ts\n+++ b/src/main.ts\n..."
}
}Security Notes
This project is useful as a policy gate, but it is not a complete security boundary by itself.
For stronger protection:
Run the AI agent in a sandbox where the real repository is not directly mounted.
Give the agent access only to this MCP server.
Keep
.env, keys, production config, database dumps, logs, exports, and regulated sample data denied.Prefer read-only tools unless write access is explicitly needed.
Review
audit.logregularly.Use dedicated secret scanners such as Gitleaks or TruffleHog in CI.
The hardest part is preventing bypasses. If the agent can read the repository directly through the filesystem, it can bypass MCP policy. For real enforcement, the MCP server should be the only process with direct access to protected files.
Project Structure
src/
audit.ts append-only audit logging
main.ts Nest application bootstrap
mcp.service.ts MCP server and tool registration
policy.ts policy loading and path checks
redact.ts secret redaction patterns
server.ts stdio server entrypoint
stderr-logger.ts logger that avoids stdout protocol noise
policy.yml repository allow/deny policy
audit.log local audit outputRoadmap Ideas
Add
apply_patch_after_scanwith stronger validation and explicit approval.Add semantic code search over allowed files.
Add policy tests for allow/deny edge cases.
Add external secret scanning before returning or applying patches.
Add per-project policy profiles.
Add structured audit rotation and retention.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Flicense-qualityDmaintenanceA self-hosted GitHub MCP server with per-repository guardrails for AI agents, enabling fine-grained access control and audit trails.Last updated
- Alicense-qualityAmaintenanceMCP server that intercepts and controls AI agent actions in your codebase by enforcing policies on file operations and commands, with logging, approval workflows, and rollback capabilities.Last updated1MIT
- Alicense-qualityBmaintenanceAn MCP server that provides AI coding agents with AST-accurate, context-budget-aware codebase querying, safety gates, and team policy integration via structured tools and a local plugin layer.Last updated5404MIT
- Flicense-qualityCmaintenanceA local MCP server that turns AI clients into power users of local git repositories, enabling clone, browse, search, and inspect code without burning API tokens.Last updated
Related MCP Connectors
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
An MCP server that gives your AI access to the source code and docs of all public github repos
An MCP server for Arcjet - the runtime security platform that ships with your AI code.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/marcojourney/safe-code-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server