Content
# Oracle 11g MCP Server
Implementation of Oracle database MCP server based on official MCP Java SDK, providing SQL execution, table structure query, and table search functionality.
## Features
- Implemented based on MCP (Model Context Protocol) Java SDK
- Provides three core tools:
- `execute_sql` - Execute arbitrary SQL statements
- `get_table_schema` - Get detailed structure information of tables
- `search_tables` - Search tables and columns by keyword
- Supports SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, and other SQL operations
- Supports transaction management (DML operations with automatic transactions)
- Supports parameterized queries
- Result set limited to 1000 rows to avoid memory overflow
## Environment Requirements
- JDK 17 or higher
- Gradle 8.x
- Oracle database (supports 11g and above)
## Building the Project
```bash
./gradlew clean build
```
After successful build, the executable JAR file is located at `build/libs/oracle-11g-mcp.jar`
## Configuration
### Environment Variable Configuration
Create `.env` file (optional):
```env
ORACLE_JDBC_URL=jdbc:oracle:thin:@//host:port/service_name
ORACLE_USERNAME=your_username
ORACLE_PASSWORD=your_password
```
Or set environment variables directly:
```bash
export ORACLE_JDBC_URL="jdbc:oracle:thin:@//localhost:1521/XE"
export ORACLE_USERNAME="system"
export ORACLE_PASSWORD="oracle"
```
### JDBC URL Format
Supports the following formats:
- SID format: `jdbc:oracle:thin:@host:port:SID`
- Service Name format: `jdbc:oracle:thin:@//host:port/service_name`
## Running the Server
### Direct Execution
```bash
java -jar build/libs/oracle-11g-mcp.jar
```
### Using Startup Script
```bash
./run-mcp-server.sh
```
## Docker Support
### Building Docker Image
```bash
docker build -t oracle-mcp-server .
```
### Using Docker Compose
Production environment:
```bash
docker-compose up
```
Development environment (includes Oracle 11g XE):
```bash
docker-compose -f docker-compose.dev.yml up
```
## MCP Tool Description
### execute_sql
General-purpose tool for executing arbitrary SQL statements.
**Parameters:**
- `sql` (required): SQL statement to be executed
- `params` (optional): Parameter array for parameterized queries
**Example:**
Query data:
```json
{
"name": "execute_sql",
"arguments": {
"sql": "SELECT * FROM users WHERE status = ?",
"params": ["active"]
}
}
```
Create table:
```json
{
"name": "execute_sql",
"arguments": {
"sql": "CREATE TABLE test_table (id NUMBER PRIMARY KEY, name VARCHAR2(100))"
}
}
```
Insert data:
```json
{
"name": "execute_sql",
"arguments": {
"sql": "INSERT INTO test_table (id, name) VALUES (?, ?)",
"params": ["1", "Test User"]
}
}
```
### get_table_schema
Get detailed structure information of tables, including column definitions, primary keys, indexes, foreign keys, and comments.
**Parameters:**
- `table_name` (required): Table name
- `schema` (optional): Schema name (default: current user)
**Example:**
```json
{
"name": "get_table_schema",
"arguments": {
"table_name": "EMPLOYEES",
"schema": "HR"
}
}
```
**Returned information includes:**
- Column information (name, type, length, precision, nullable, default value, comment)
- Primary key information
- Index information (name, type, unique, included columns)
- Foreign key information (constraint name, columns, referenced table, referenced columns, delete rule)
- Table comment
### search_tables
Search tables and columns by keyword, supporting searches in table names, column names, and comments.
**Parameters:**
- `keyword` (required): Search keyword
- `schema` (optional): Schema to limit search (default: search all accessible schemas)
- `search_columns` (optional): Whether to search column names and comments (default: true)
- `limit` (optional): Maximum number of returned results (default: 100, maximum: 500)
**Example:**
Search for tables and columns containing "order":
```json
{
"name": "search_tables",
"arguments": {
"keyword": "order",
"search_columns": true,
"limit": 50
}
}
```
Search for tables in a specific schema:
```json
{
"name": "search_tables",
"arguments": {
"keyword": "customer",
"schema": "SALES",
"search_columns": false
}
}
```
**Returned information includes:**
- Matching table list (including row count, last analyzed time, comment)
- Matching column list (including owning table, data type, nullable, comment)
- Results sorted by relevance (exact match > prefix match > contains match)
## Project Structure
```
oracle-11g-mcp/
├── build.gradle # Gradle build configuration
├── src/main/java/
│ └── com/oracle/mcp/
│ ├── config/ # Configuration classes
│ ├── server/ # MCP server implementation
│ └── tools/ # SQL execution tools
├── docker-compose.yml # Production environment configuration
├── docker-compose.dev.yml # Development environment configuration
└── Dockerfile # Docker image build
```
## Dependencies
- `io.modelcontextprotocol.sdk:mcp:0.10.0` - MCP Java SDK
- `com.oracle.database.jdbc:ojdbc8:23.5.0.24.07` - Oracle JDBC driver
- `com.fasterxml.jackson.core:jackson-databind:2.15.3` - JSON processing
- `io.github.cdimascio:dotenv-java:3.0.0` - Environment variable management
- `ch.qos.logback:logback-classic:1.4.14` - Logging framework
## Precautions
1. Query result set limited to 1000 rows, excess truncated
2. DML operations (INSERT, UPDATE, DELETE) use automatic transactions
3. DDL operations (CREATE, ALTER, DROP) take effect immediately
4. Supports all standard SQL statements and Oracle-specific syntax
## License
MIT License