Skip to content

Conversation

@Karanraj-6
Copy link

  • Validate that server names in mcp.json contain only letters, numbers, and hyphens
  • Raise ValueError on invalid server names
  • Prevent loading invalid configuration earlyThis PR introduces validation for server names in the MCP configuration (mcp.json).

Changes include:
Validate that server names contain only letters, numbers, and hyphens.
Raise a ValueError if an invalid server name is found, preventing the loading of invalid configurations early.
Update _load_config in McpConfig to incorporate the validation step.

Motivation:
Ensures that only properly formatted server names are loaded, reducing potential runtime errors and improving reliability of MCP configuration handling.

Testing:
Initialized McpConfig locally.
Printed all server names to confirm validation runs without errors.
Verified that invalid server names correctly raise ValueError.

@cristipufu cristipufu requested a review from Copilot September 17, 2025 05:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds validation to ensure server names in MCP configuration files contain only alphanumeric characters and hyphens. The validation prevents invalid configurations from being loaded by raising a ValueError early in the process.

Key changes:

  • Added server name validation using regex pattern matching
  • Modified configuration loading to validate each server name before creating McpServer instances
  • Introduced early error handling for invalid server names

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Karanraj-6
Copy link
Author

The _servers attribute is not initialized before being used.
Added self._servers = {} before the loop to prevent AttributeError.

@Karanraj-6 Karanraj-6 closed this Sep 17, 2025
@Karanraj-6 Karanraj-6 reopened this Sep 17, 2025
Copy link
Author

@Karanraj-6 Karanraj-6 left a comment

Choose a reason for hiding this comment

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

  • Initialize self._servers = {} before populating
  • Add validation for server names (letters, numbers, hyphens only)

@cristipufu
Copy link
Member

Hi @Karanraj-6 thanks for your contribution. Can you please rebase and squash the commits?

- Validate server names contain only letters, numbers, and hyphens
- Raise ValueError for invalid server names
- Initialize self._servers before populating
@Karanraj-6 Karanraj-6 force-pushed the add-server-name-validation branch from 21d2c8e to e4a3863 Compare September 18, 2025 15:47
@Karanraj-6
Copy link
Author

@cristipufu I’ve rebased and squashed the commits. Can you please review and merge when you get a chance?

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.

2 participants