Skip to content

refactor: update get_table_schema and enforce allowed_tables #806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

srikanth-karthi
Copy link
Contributor

@srikanth-karthi srikanth-karthi commented Jul 14, 2025

Summary

This pull request introduces two main changes:

  • Adds a --allowed_tables CLI argument to restrict which tables can be queried in read-only mode.
  • Simplifies the get_table_schema function by removing the database_name parameter. It now uses the database name from the connection directly.

Changes

  • Introduced --allowed_tables CLI argument for whitelisting tables.
  • Enforced allowed_tables inside run_query to reject unauthorized table access.
  • Removed the database_name argument from get_table_schema.
  • Updated the get_table_schema implementation to use DBConnectionSingleton for the database name.
  • Updated test cases and added new ones for the allowed table logic and modified schema function.

Testing

  • ✅ Verified that queries to non-whitelisted tables are blocked with a proper error message.
  • ✅ Validated that get_table_schema works correctly without the database_name argument.
  • ✅ Ensured all previous tests continue to pass.
  • ✅ Performed manual tests using the MCP CLI.

User Experience Improvements

Feature Before After
Allowed table restriction Not available Available via --allowed_tables CLI argument
Schema fetching (get_table_schema) Required explicit database_name Automatically uses the configured connection’s DB

Breaking Change

No. This change is backward compatible.


RFC / Issue

Not applicable.


Checklist

  • Reviewed contributing guidelines
  • Self-reviewed the changes
  • Verified tests pass
  • Documentation updated
  • Feature tested manually

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@srikanth-karthi srikanth-karthi requested review from kennthhz and a team as code owners July 14, 2025 09:44
@srikanth-karthi srikanth-karthi changed the title Add Allowed Table Restriction and Simplify Schema Fetching in MySQL MCP refactor: update get_table_schema and enforce allowed_tables Jul 14, 2025
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.

1 participant