Skip to content

Add MCP Environment Validation and Documentation#42

Open
Snider wants to merge 4 commits intodevfrom
feature/mcp-env-validation-1172062881386547126
Open

Add MCP Environment Validation and Documentation#42
Snider wants to merge 4 commits intodevfrom
feature/mcp-env-validation-1172062881386547126

Conversation

@Snider
Copy link
Copy Markdown
Contributor

@Snider Snider commented Feb 4, 2026

This change improves the security and operability of the MCP package by providing a structured configuration system, documenting all relevant environment variables, and adding boot-time validation to warn about insecure configurations in production.

Key improvements:

  1. Centralized Configuration: Created config/mcp.php which maps all MCP-related settings to environment variables.
  2. Environment Documentation: Updated .env.example with a complete list of MCP_* variables and their defaults.
  3. Boot-time Validation: Implemented validateConfig() in src/Mcp/Boot.php to check for security-critical settings (e.g., dedicated DB connection) and log warnings/errors if they are missing or insecure in production.
  4. Publishable Config: Registered the config file for publishing via php artisan vendor:publish --tag=mcp-config.
  5. Updated Documentation: Added configuration tables and security implications to README.md and CLAUDE.md.

Fixes #23


PR created automatically by Jules for task 1172062881386547126 started by @Snider

- Added comprehensive config/mcp.php with environment variable mapping.
- Updated .env.example with MCP_* variables.
- Added boot-time validation for security-critical configuration in src/Mcp/Boot.php.
- Added $this->publishes() for the config file in Boot.php.
- Updated README.md and CLAUDE.md with configuration and security documentation.
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @Snider, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security and operational robustness of the MCP package. It introduces a structured and centralized configuration system, ensuring all relevant settings are clearly documented and easily managed via environment variables. Crucially, it adds boot-time validation to identify and warn against potentially insecure configurations in production environments, thereby reducing security risks and improving overall system stability.

Highlights

  • Centralized Configuration: Introduced config/mcp.php to consolidate all MCP-related settings, making them manageable via environment variables and providing clear defaults.
  • Enhanced Environment Documentation: The .env.example file now includes a comprehensive list of MCP_* variables, improving clarity and ease of setup for developers.
  • Boot-time Security Validation: Implemented validateConfig() in src/Mcp/Boot.php to proactively check for insecure configurations (e.g., missing dedicated DB connection in production) and log warnings or errors.
  • Publishable Configuration: The new configuration file can be published by users using php artisan vendor:publish --tag=mcp-config, allowing for easy customization.
  • Updated User Documentation: README.md and CLAUDE.md have been updated with detailed configuration tables and explanations of security implications for critical settings.
Changelog
  • .env.example
    • Added a new "MCP Configuration" section with numerous MCP_* environment variables and their default values, covering domain, database, circuit breaker, audit, analytics, retention, rate limiting, and session settings.
  • CLAUDE.md
    • Introduced a new "Security Configuration" section.
    • Detailed critical MCP security settings like MCP_DATABASE_CONNECTION, MCP_USE_WHITELIST, and MCP_AUDIT_LOG_CHANNEL.
    • Mentioned the boot-time validation in src/Mcp/Boot.php for security-critical settings.
  • README.md
    • Revised the "Configuration" section to explain both environment variable and manual file publishing methods.
    • Added a table listing key MCP_ environment variables, their descriptions, and defaults.
    • Updated the example config/mcp.php snippet to reflect the new structure and environment variable usage.
    • Removed the quota configuration block from the example.
    • Added sessions to blocked_tables in the example.
  • config/mcp.php
    • New file created, establishing a centralized configuration for the MCP package.
    • Defines various configuration categories: domain, database (connection, whitelist, tiers, blocked tables), circuit_breaker, audit, analytics, log_retention, rate_limiting, and session.
    • Each setting is configured to read from an MCP_ prefixed environment variable with a sensible default fallback.
  • src/Mcp/Boot.php
    • Added mergeConfigFrom to load the new config/mcp.php file into the application's configuration.
    • Implemented publishes to allow users to publish the mcp.php config file using php artisan vendor:publish --tag=mcp-config.
    • Introduced a validateConfig() method, called during boot, to perform security checks.
    • The validateConfig() method checks for a missing dedicated database connection in production (logging a warning), a non-existent audit log channel (logging an error), and a disabled SQL whitelist (logging a notice).
    • Validation is skipped for console commands unless they are mcp: commands.
Activity
  • The pull request was automatically created by Jules for task 1172062881386547126, initiated by @Snider.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 4, 2026

QA Pipeline Results

Check Status Details
Tests tests, assertions
PHPStan errors
Psalm issues
Code Style files need formatting
Security vulnerabilities
Artifacts
  • test-results.xml - JUnit test results
  • phpstan.json - PHPStan analysis
  • psalm.json / psalm.sarif - Psalm analysis
  • pint.json - Code style report
  • audit.json - Security audit

Generated by core php qa pipeline

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a structured configuration system for the MCP package, along with boot-time validation and updated documentation. While these changes improve security and operability, a critical vulnerability was identified: the configured SQL whitelist and blocked tables restrictions are not enforced by the query execution logic. This creates a false sense of security and could expose sensitive data. Addressing these implementation gaps is essential. Additionally, there are suggestions to improve the robustness of configuration loading, refine command detection logic in the validation script, enhance code readability, and clarify a minor inconsistency in the README documentation.

Comment thread src/Mcp/Boot.php
Comment on lines +116 to 121
if (! config('mcp.database.use_whitelist', true)) {
\Illuminate\Support\Facades\Log::notice(
'MCP: SQL whitelist validation is disabled. This reduces the protection against unauthorized queries.'
);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

A critical vulnerability exists here: the boot-time validation check implies that enabling mcp.database.use_whitelist provides protection against unauthorized SQL queries. However, the SqlQueryValidator service is not registered in the service provider and is not utilized by the QueryExecutionService. Consequently, no SQL validation is performed even when the whitelist is enabled, creating a false sense of security and leaving the system vulnerable to SQL injection and unauthorized data access. To fix this: 1. Register the SqlQueryValidator in the register() method of this class. 2. Ensure that QueryExecutionService utilizes the validator to check all queries before execution when the whitelist is enabled.

Comment thread config/mcp.php
Comment on lines +40 to +48
'blocked_tables' => [
'users',
'api_keys',
'failed_jobs',
'migrations',
'password_reset_tokens',
'personal_access_tokens',
'sessions',
],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The blocked_tables configuration is introduced here to prevent access to sensitive database tables (e.g., users, api_keys). However, the current implementation of SqlQueryValidator and QueryExecutionService does not include any logic to enforce this restriction. Without an implementation that checks queries against this list, these sensitive tables remain accessible to database query tools, rendering this security control ineffective.

Recommendation: Update the SqlQueryValidator to accept the blocked_tables configuration and implement a check to ensure that no table in the list is accessed by the query.

Comment thread README.md
Comment on lines +176 to 188
Example `config/mcp.php`:
```php
return [
'database' => [
'connection' => 'readonly', // Dedicated read-only connection
'connection' => env('MCP_DATABASE_CONNECTION'),
'use_whitelist' => true,
'blocked_tables' => ['users', 'api_keys'],
'blocked_tables' => ['users', 'api_keys', 'sessions'],
],
'analytics' => [
'enabled' => true,
'retention_days' => 90,
],
'quota' => [
'enabled' => true,
'default_limit' => 1000, // Per workspace per day
],
];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The example config/mcp.php is quite minimal and differs from the actual config/mcp.php file in a few ways that could be confusing for users:

  • The blocked_tables array is much shorter than the one in the actual config file. It would be better to show the full default list to give a complete picture of the default security posture.
  • Most values are hardcoded (e.g., use_whitelist), while the actual config file uses the env() helper extensively. Showing more env() usage would make the example more representative.

I suggest updating the example to be more aligned with the config/mcp.php file that is being added to avoid confusion.

Comment thread config/mcp.php
'connection' => env('MCP_DATABASE_CONNECTION'),

// Whether to enforce whitelist-based query validation
'use_whitelist' => env('MCP_USE_WHITELIST', true),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Environment variables are always read as strings, which can lead to unexpected behavior when a boolean or integer is expected. For example, (bool) "false" evaluates to true in PHP.

It's safer to explicitly cast values from env().

  • For boolean values, use filter_var(env('...', true), FILTER_VALIDATE_BOOLEAN).
  • For integer values, use (int) env('...', 5).

This should be applied to all boolean and integer configurations in this file to make the configuration loading more robust.

        'use_whitelist' => filter_var(env('MCP_USE_WHITELIST', true), FILTER_VALIDATE_BOOLEAN),

Comment thread src/Mcp/Boot.php
Comment on lines +85 to +92
$argv = $_SERVER['argv'] ?? [];
$isMcpCommand = false;
foreach ($argv as $arg) {
if (str_contains($arg, 'mcp:')) {
$isMcpCommand = true;
break;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current logic to detect if an MCP command is running iterates through all command-line arguments and checks if any of them contain mcp:. This is a bit fragile and could lead to false positives if, for example, an option value for a non-MCP command contains that string (e.g., php artisan some:command --option=foo-mcp:bar).

A more robust approach would be to check if the command name itself (which is typically the first argument after artisan) starts with mcp:. Also, it's better to use Laravel's request helper instead of accessing $_SERVER directly.

        $argv = request()->server('argv', []);
        $isMcpCommand = false;
        if (isset($argv[1]) && str_starts_with($argv[1], 'mcp:')) {
            $isMcpCommand = true;
        }

- Added comprehensive config/mcp.php with environment variable mapping.
- Updated .env.example with MCP_* variables.
- Added boot-time validation for security-critical configuration in src/Mcp/Boot.php.
- Added $this->publishes() for the config file in Boot.php.
- Updated README.md and CLAUDE.md with configuration and security documentation.
- Added host-uk/core and host-uk/core-php repositories to composer.json to fix CI.
- Added comprehensive config/mcp.php with environment variable mapping.
- Updated .env.example with MCP_* variables.
- Added boot-time validation for security-critical configuration in src/Mcp/Boot.php.
- Added $this->publishes() for the config file in Boot.php.
- Updated README.md and CLAUDE.md with configuration and security documentation.
- Updated composer.json to use host-uk/core-php repository for dependency resolution.
- Added comprehensive config/mcp.php with environment variable mapping.
- Updated .env.example with MCP_* variables.
- Added boot-time validation for security-critical configuration in src/Mcp/Boot.php.
- Added $this->publishes() for the config file in Boot.php.
- Updated README.md and CLAUDE.md with configuration and security documentation.
- Updated composer.json to use host-uk/core-php repository.
- Restored missing dev dependencies (Pest, PHPUnit, PHPStan, Psalm, Pint) to composer.json to fix CI failures.
@Snider Snider marked this pull request as ready for review February 5, 2026 03:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 5, 2026

Warning

Rate limit exceeded

@Snider has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/mcp-env-validation-1172062881386547126

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation: Missing env validation for sensitive configuration

1 participant