Skip to content

Commit 7a98655

Browse files
authored
Initial commit
1 parent 747cc9d commit 7a98655

34 files changed

Lines changed: 3383 additions & 0 deletions

LICENSE

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
MIT License with Additional Conditions
2+
3+
Copyright (c) 2025 Akram Sheriff
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
SPECIAL CONDITIONS:
16+
17+
1. Intellectual Property Notice: Certain intellectual property used in this project
18+
is owned by Akram Sheriff. This includes, but is not limited to, the Text2SQL
19+
agent architecture, security threat analysis methodology, and prompt engineering
20+
techniques in the MCP AI SOC Sher package.
21+
22+
2. Educational and Non-Commercial Use: This software may be freely used, modified,
23+
forked, and distributed for educational, research, and non-commercial purposes.
24+
25+
3. Commercial Use Restriction: For any commercial use, deployment, or product
26+
incorporating this software or its derivatives, a separate commercial license
27+
must be procured from Akram Sheriff. Commercial use includes, but is not limited to,
28+
incorporating the software into a product or service that generates revenue.
29+
30+
4. Contact Information: For commercial licensing inquiries, please contact
31+
Akram Sheriff at the contact information provided in the project documentation.
32+
33+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
SOFTWARE.

MANIFEST.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include LICENSE
2+
include README.md
3+
include requirements.txt
4+
include requirements-dev.txt
5+
include .env.example
6+
include pyproject.toml
7+
recursive-include examples *.py
8+
recursive-include data *.sql
9+
recursive-include docs *.md
10+
recursive-include tests *.py

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# MCP AI SOC Sher
2+
3+
A powerful AI-driven Security Operations Center (SOC) Text2SQL framework for converting natural language to SQL queries, with integrated security threat analysis and monitoring.
4+
5+
## Features
6+
7+
- **Text2SQL Conversion**: Convert natural language queries to optimized SQL
8+
- **Multiple Interfaces**: Support for STDIO, SSE, and REST API
9+
- **Security Threat Analysis**: Built-in SQL query security analysis
10+
- **Multiple Database Support**: Connect to SQLite or Snowflake databases
11+
- **Streaming Responses**: Real-time query processing feedback
12+
- **SOC Monitoring**: Security Operations Center monitoring capabilities
13+
14+
## Installation
15+
16+
```bash
17+
pip install mcp-ai-soc-sher
18+
```
19+
20+
## Quick Start
21+
22+
```python
23+
# Set your OpenAI API key
24+
import os
25+
os.environ["OPENAI_API_KEY"] = "your-api-key-here"
26+
27+
# Use as local server
28+
from mcp_ai_soc_sher.local import LocalMCPServer
29+
30+
server = LocalMCPServer()
31+
server.start()
32+
33+
# Or run from command line
34+
# mcp-ai-soc --type local --stdio --sse
35+
```
36+
37+
## Command Line Usage
38+
39+
```bash
40+
# Run local server with STDIO interface
41+
mcp-ai-soc --type local --stdio
42+
43+
# Run local server with SSE interface
44+
mcp-ai-soc --type local --sse
45+
46+
# Run remote server with REST API
47+
mcp-ai-soc --type remote
48+
```
49+
50+
## Configuration
51+
52+
Create a `.env` file with your configuration:
53+
54+
```
55+
OPENAI_API_KEY=your_openai_api_key_here
56+
MCP_DB_URI=sqlite:///your_database.db
57+
MCP_SECURITY_ENABLE_THREAT_ANALYSIS=true
58+
```
59+
60+
See the [documentation](docs/configuration.md) for all configuration options.
61+
62+
## Example
63+
64+
```python
65+
import json
66+
import requests
67+
68+
# Query the server
69+
response = requests.post(
70+
"http://localhost:8000/api/sql",
71+
headers={"Content-Type": "application/json", "X-API-Key": "your-api-key"},
72+
json={
73+
"query": "Find all suspicious login attempts in the last 24 hours",
74+
"optimize": True,
75+
"execute": True
76+
}
77+
)
78+
79+
# Process the response
80+
result = response.json()
81+
print(f"SQL Query: {result['sql']}")
82+
if result['results']:
83+
print("Results:")
84+
for row in result['results']:
85+
print(row)
86+
```
87+
88+
## Security Features
89+
90+
- Rule-based and AI-powered SQL query security analysis
91+
- Detection of potential SQL injection attacks
92+
- Sensitive table access monitoring
93+
- Configurable security levels and actions
94+
95+
## License
96+
97+
MIT License with Additional Conditions. Copyright (c) 2025 Akram Sheriff.
98+
99+
See [LICENSE](LICENSE) for details.
100+
101+
## Contributing
102+
103+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

build_and_install.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Build and install the MCP AI SOC Sher package
3+
4+
# Ensure we're in the project root directory
5+
cd "$(dirname "$0")" || exit 1
6+
7+
echo "=== Building MCP AI SOC Sher package ==="
8+
9+
# Clean up any previous builds
10+
rm -rf dist/ build/ *.egg-info/
11+
12+
# Install dependencies
13+
pip install --upgrade pip setuptools wheel build
14+
15+
# Create the distributable packages
16+
python -m build
17+
18+
echo -e "\n=== Installing MCP AI SOC Sher package ==="
19+
pip install -e .
20+
21+
echo -e "\n=== Installation complete! ==="
22+
echo "You can now run MCP AI SOC Sher with:"
23+
echo " mcp-ai-soc --type local --stdio --sse"
24+
echo " or"
25+
echo " python -m mcp_ai_soc_sher --type local --stdio --sse"
26+
echo " or"
27+
echo " ./run_mcp_ai_soc.py --type local --stdio --sse"
28+
echo ""
29+
echo "Don't forget to set your OPENAI_API_KEY in .env file or as an environment variable!"

data/init_sample_db.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
"""
3+
Initialize a sample SQLite database for the Text2SQL MCP Server.
4+
"""
5+
import os
6+
import sqlite3
7+
from pathlib import Path
8+
9+
# Determine the database path
10+
data_dir = Path(__file__).parent
11+
db_path = data_dir / "sample.db"
12+
schema_path = data_dir / "sample_schema.sql"
13+
14+
def init_sample_db():
15+
"""Initialize the sample database."""
16+
print(f"Initializing sample database at {db_path}...")
17+
18+
# Remove existing database if it exists
19+
if db_path.exists():
20+
os.remove(db_path)
21+
22+
# Create a new database and connect to it
23+
conn = sqlite3.connect(db_path)
24+
25+
# Read and execute the schema SQL
26+
with open(schema_path, "r") as f:
27+
schema_sql = f.read()
28+
29+
conn.executescript(schema_sql)
30+
conn.commit()
31+
32+
# Verify the database was created successfully
33+
cursor = conn.cursor()
34+
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
35+
tables = cursor.fetchall()
36+
print(f"Created tables: {', '.join(table[0] for table in tables)}")
37+
38+
# Close the connection
39+
conn.close()
40+
41+
print("Sample database initialized successfully.")
42+
print(f"To use this database, set MCP_DB_URI=sqlite:///{db_path}")
43+
44+
if __name__ == "__main__":
45+
init_sample_db()

data/sample_schema.sql

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
-- Sample database schema for the Text2SQL MCP Server
2+
3+
-- User management tables
4+
CREATE TABLE IF NOT EXISTS users (
5+
id INTEGER PRIMARY KEY,
6+
username TEXT NOT NULL UNIQUE,
7+
email TEXT NOT NULL UNIQUE,
8+
full_name TEXT,
9+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
10+
last_login TIMESTAMP,
11+
is_active BOOLEAN DEFAULT TRUE
12+
);
13+
14+
CREATE TABLE IF NOT EXISTS user_sessions (
15+
session_id TEXT PRIMARY KEY,
16+
user_id INTEGER NOT NULL,
17+
start_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
18+
end_time TIMESTAMP,
19+
ip_address TEXT,
20+
user_agent TEXT,
21+
FOREIGN KEY (user_id) REFERENCES users(id)
22+
);
23+
24+
-- Product catalog tables
25+
CREATE TABLE IF NOT EXISTS categories (
26+
id INTEGER PRIMARY KEY,
27+
name TEXT NOT NULL,
28+
description TEXT,
29+
parent_id INTEGER,
30+
FOREIGN KEY (parent_id) REFERENCES categories(id)
31+
);
32+
33+
CREATE TABLE IF NOT EXISTS products (
34+
id INTEGER PRIMARY KEY,
35+
name TEXT NOT NULL,
36+
description TEXT,
37+
price DECIMAL(10, 2) NOT NULL,
38+
stock_quantity INTEGER DEFAULT 0,
39+
category_id INTEGER,
40+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
41+
updated_at TIMESTAMP,
42+
FOREIGN KEY (category_id) REFERENCES categories(id)
43+
);
44+
45+
CREATE TABLE IF NOT EXISTS product_attributes (
46+
id INTEGER PRIMARY KEY,
47+
product_id INTEGER NOT NULL,
48+
name TEXT NOT NULL,
49+
value TEXT NOT NULL,
50+
FOREIGN KEY (product_id) REFERENCES products(id)
51+
);
52+
53+
-- Order management tables
54+
CREATE TABLE IF NOT EXISTS orders (
55+
id INTEGER PRIMARY KEY,
56+
user_id INTEGER NOT NULL,
57+
status TEXT NOT NULL,
58+
total_amount DECIMAL(10, 2) NOT NULL,
59+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
60+
updated_at TIMESTAMP,
61+
FOREIGN KEY (user_id) REFERENCES users(id)
62+
);
63+
64+
CREATE TABLE IF NOT EXISTS order_items (
65+
id INTEGER PRIMARY KEY,
66+
order_id INTEGER NOT NULL,
67+
product_id INTEGER NOT NULL,
68+
quantity INTEGER NOT NULL,
69+
price DECIMAL(10, 2) NOT NULL,
70+
FOREIGN KEY (order_id) REFERENCES orders(id),
71+
FOREIGN KEY (product_id) REFERENCES products(id)
72+
);
73+
74+
-- Insert sample data
75+
INSERT INTO users (username, email, full_name) VALUES
76+
('john_doe', 'john@example.com', 'John Doe'),
77+
('jane_smith', 'jane@example.com', 'Jane Smith'),
78+
('bob_johnson', 'bob@example.com', 'Bob Johnson');
79+
80+
INSERT INTO categories (name, description) VALUES
81+
('Electronics', 'Electronic devices and accessories'),
82+
('Clothing', 'Apparel and fashion items'),
83+
('Books', 'Books and publications');
84+
85+
INSERT INTO products (name, description, price, stock_quantity, category_id) VALUES
86+
('Smartphone', 'Latest smartphone with advanced features', 699.99, 50, 1),
87+
('Laptop', 'High-performance laptop for professionals', 1299.99, 30, 1),
88+
('T-shirt', 'Cotton t-shirt, various colors', 19.99, 100, 2),
89+
('Jeans', 'Denim jeans, slim fit', 49.99, 75, 2),
90+
('Programming Guide', 'Comprehensive programming reference', 39.99, 25, 3);
91+
92+
INSERT INTO orders (user_id, status, total_amount) VALUES
93+
(1, 'completed', 749.98),
94+
(2, 'processing', 1299.99),
95+
(3, 'completed', 89.98);
96+
97+
INSERT INTO order_items (order_id, product_id, quantity, price) VALUES
98+
(1, 1, 1, 699.99),
99+
(1, 3, 1, 49.99),
100+
(2, 2, 1, 1299.99),
101+
(3, 3, 2, 39.99),
102+
(3, 5, 1, 9.99);

0 commit comments

Comments
 (0)