{"id":26937695,"url":"https://github.com/amornpan/py-mcp-mssql","last_synced_at":"2025-04-02T13:15:49.965Z","repository":{"id":274376089,"uuid":"922607489","full_name":"amornpan/py-mcp-mssql","owner":"amornpan","description":"py-mcp-mssql","archived":false,"fork":false,"pushed_at":"2025-02-06T03:18:11.000Z","size":272,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T04:23:49.462Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amornpan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-26T16:54:51.000Z","updated_at":"2025-02-06T03:18:14.000Z","dependencies_parsed_at":"2025-01-26T23:33:51.288Z","dependency_job_id":null,"html_url":"https://github.com/amornpan/py-mcp-mssql","commit_stats":null,"previous_names":["amornpan/py-mcp-mssql"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amornpan%2Fpy-mcp-mssql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amornpan%2Fpy-mcp-mssql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amornpan%2Fpy-mcp-mssql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amornpan%2Fpy-mcp-mssql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amornpan","download_url":"https://codeload.github.com/amornpan/py-mcp-mssql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246819782,"owners_count":20839095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-02T13:15:28.001Z","updated_at":"2025-04-02T13:15:49.940Z","avatar_url":"https://github.com/amornpan.png","language":"Python","funding_links":[],"categories":["Community Servers","🤖 AI/ML","Cloud Services","Table of Contents","Mcp Server Directories \u0026 Lists"],"sub_categories":["Other Tools and Integrations"],"readme":"# Python MSSQL MCP Server\n\n[![Version](https://img.shields.io/badge/version-1.0.1-blue.svg)](https://github.com/amornpan/py-mcp-mssql)\n[![Python](https://img.shields.io/badge/python-3.8%2B-blue)](https://www.python.org)\n[![MCP](https://img.shields.io/badge/MCP-1.2.0-green.svg)](https://github.com/modelcontextprotocol)\n[![FastAPI](https://img.shields.io/badge/FastAPI-0.104.1-teal.svg)](https://fastapi.tiangolo.com)\n[![License](https://img.shields.io/badge/license-MIT-yellow.svg)](LICENSE)\n\nA Model Context Protocol server implementation in Python that provides access to Microsoft SQL Server databases. This server enables Language Models to inspect table schemas and execute SQL queries through a standardized interface.\n\n## Features\n\n### Core Functionality\n* Asynchronous operation using Python's `asyncio`\n* Environment-based configuration using `python-dotenv`\n* Comprehensive logging system\n* Connection pooling and management via pyodbc\n* Error handling and recovery\n* FastAPI integration for API endpoints\n* Pydantic models for data validation\n* MSSQL connection handling with ODBC Driver\n\n## Prerequisites\n\n* Python 3.x\n* Required Python packages:\n  * pyodbc\n  * pydantic\n  * python-dotenv\n  * mcp-server\n* ODBC Driver 17 for SQL Server\n\n## Installation\n\n```bash\ngit clone https://github.com/amornpan/py-mcp-mssql.git\ncd py-mcp-mssql\npip install -r requirements.txt\n```\n\n## Screenshots\n\n![MCP MSSQL Server Demo](screenshots/2025-01-27_05-43-34.png)\n\nThe screenshot above demonstrates the server being used with Claude to analyze and visualize SQL data.\n\n## Project Structure\n\n```\nPY-MCP-MSSQL/\n├── src/\n│   └── mssql/\n│       ├── __init__.py\n│       └── server.py\n├── tests/\n│   ├── __init__.py\n│   ├── test_mssql.py\n│   └── test_packages.py\n├── .env\n├── .env.example\n├── .gitignore\n├── README.md\n└── requirements.txt\n```\n\n### Directory Structure Explanation\n* `src/mssql/` - Main source code directory\n  * `__init__.py` - Package initialization\n  * `server.py` - Main server implementation\n* `tests/` - Test files directory\n  * `__init__.py` - Test package initialization\n  * `test_mssql.py` - MSSQL functionality tests\n  * `test_packages.py` - Package dependency tests\n* `.env` - Environment configuration file (not in git)\n* `.env.example` - Example environment configuration\n* `.gitignore` - Git ignore rules\n* `README.md` - Project documentation\n* `requirements.txt` - Project dependencies\n\n## Configuration\n\nCreate a `.env` file in the project root:\n\n```env\nMSSQL_SERVER=your_server\nMSSQL_DATABASE=your_database\nMSSQL_USER=your_username\nMSSQL_PASSWORD=your_password\nMSSQL_DRIVER={ODBC Driver 17 for SQL Server}\n```\n\n## API Implementation Details\n\n### Resource Listing\n```python\n@app.list_resources()\nasync def list_resources() -\u003e list[Resource]\n```\n* Lists all available tables in the database\n* Returns table names with URIs in the format `mssql://\u003ctable_name\u003e/data`\n* Includes table descriptions and MIME types\n\n### Resource Reading\n```python\n@app.read_resource()\nasync def read_resource(uri: AnyUrl) -\u003e str\n```\n* Reads data from specified table\n* Accepts URIs in the format `mssql://\u003ctable_name\u003e/data`\n* Returns first 100 rows in CSV format\n* Includes column headers\n\n### SQL Execution\n```python\n@app.call_tool()\nasync def call_tool(name: str, arguments: dict) -\u003e list[TextContent]\n```\n* Executes SQL queries\n* Supports both SELECT and modification queries\n* Returns results in CSV format for SELECT queries\n* Returns affected row count for modification queries\n\n## Usage with Claude Desktop\n\nAdd to your Claude Desktop configuration:\n\nOn MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`\nOn Windows: `%APPDATA%/Claude/claude_desktop_config.json`\n\n```json\n{\n  \"mcpServers\": {\n    \"mssql\": {\n      \"command\": \"python\",\n      \"args\": [\n        \"server.py\"\n      ],\n      \"env\": {\n        \"MSSQL_SERVER\": \"your_server\",\n        \"MSSQL_DATABASE\": \"your_database\",\n        \"MSSQL_USER\": \"your_username\",\n        \"MSSQL_PASSWORD\": \"your_password\",\n        \"MSSQL_DRIVER\": \"{ODBC Driver 17 for SQL Server}\"\n      }\n    }\n  }\n}\n```\n\n## Error Handling\n\nThe server implements comprehensive error handling for:\n* Database connection failures\n* Invalid SQL queries\n* Resource access errors\n* URI validation\n* Tool execution errors\n\nAll errors are logged and returned with appropriate error messages.\n\n## Security Features\n\n* Environment variable based configuration\n* Connection string security\n* Result set size limits\n* Input validation through Pydantic\n* Proper SQL query handling\n\n## Contact Information\n\n### Amornpan Phornchaicharoen\n\n[![Email](https://img.shields.io/badge/Email-amornpan%40gmail.com-red?style=flat-square\u0026logo=gmail)](mailto:amornpan@gmail.com)\n[![LinkedIn](https://img.shields.io/badge/LinkedIn-Amornpan-blue?style=flat-square\u0026logo=linkedin)](https://www.linkedin.com/in/amornpan/)\n[![HuggingFace](https://img.shields.io/badge/🤗%20Hugging%20Face-amornpan-yellow?style=flat-square)](https://huggingface.co/amornpan)\n[![GitHub](https://img.shields.io/badge/GitHub-amornpan-black?style=flat-square\u0026logo=github)](https://github.com/amornpan)\n\nFeel free to reach out to me if you have any questions about this project or would like to collaborate!\n\n---\n*Made with ❤️ by Amornpan Phornchaicharoen*\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Author\n\nAmornpan Phornchaicharoen\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## Requirements\n\nCreate a `requirements.txt` file with:\n\n```\nfastapi\u003e=0.104.1\npydantic\u003e=2.10.6\nuvicorn\u003e=0.34.0 \npython-dotenv\u003e=1.0.1\npyodbc\u003e=4.0.35\nanyio\u003e=4.5.0\nmcp==1.2.0\n```\n\nThese versions have been tested and verified to work together. The key components are:\n* `fastapi` and `uvicorn` for the API server\n* `pydantic` for data validation\n* `pyodbc` for SQL Server connectivity\n* `mcp` for Model Context Protocol implementation\n* `python-dotenv` for environment configuration\n* `anyio` for asynchronous I/O support\n\n## Acknowledgments\n\n* Microsoft SQL Server team for ODBC drivers\n* Python pyodbc maintainers\n* Model Context Protocol community\n* Contributors to the python-dotenv project","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famornpan%2Fpy-mcp-mssql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famornpan%2Fpy-mcp-mssql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famornpan%2Fpy-mcp-mssql/lists"}