@naganpm/snowflake-mcp-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.continue/prompts/new-prompt.md +14 -0
- package/.env.example +7 -0
- package/Dockerfile +21 -0
- package/LICENSE +21 -0
- package/QUICKSTART.md +174 -0
- package/README.md +205 -0
- package/SETUP_COMPLETE.md +226 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server.d.ts +3 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +129 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/middleware/error.middleware.d.ts +3 -0
- package/dist/middleware/error.middleware.d.ts.map +1 -0
- package/dist/middleware/error.middleware.js +18 -0
- package/dist/middleware/error.middleware.js.map +1 -0
- package/dist/routes/snowflake.routes.d.ts +3 -0
- package/dist/routes/snowflake.routes.d.ts.map +1 -0
- package/dist/routes/snowflake.routes.js +120 -0
- package/dist/routes/snowflake.routes.js.map +1 -0
- package/dist/services/snowflake.service.d.ts +32 -0
- package/dist/services/snowflake.service.d.ts.map +1 -0
- package/dist/services/snowflake.service.js +126 -0
- package/dist/services/snowflake.service.js.map +1 -0
- package/docker-compose.yml +16 -0
- package/examples/usage.ts +84 -0
- package/package.json +45 -0
- package/postman_collection.json +148 -0
- package/src/index.ts +51 -0
- package/src/mcp-server.ts +137 -0
- package/src/middleware/error.middleware.ts +22 -0
- package/src/routes/snowflake.routes.ts +123 -0
- package/src/services/snowflake.service.ts +149 -0
- package/test-api.sh +39 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Snowflake MCP
|
|
3
|
+
description: Create a snowflake MCP
|
|
4
|
+
invokable: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
URL: https://bd50859.us-east-2.aws.snowflakecomputing.com/
|
|
8
|
+
USERNAME: DEP_QA2
|
|
9
|
+
PASSWORD: Depqa2222$
|
|
10
|
+
|
|
11
|
+
### Instructions
|
|
12
|
+
- Create a snowflake mcp server in current folder and I want to configure this MCP as npm package.
|
|
13
|
+
- Use express.js and typescript preferrably.
|
|
14
|
+
- You can refer to @naganpm/mysql-mcp-server npm package for reference.
|
package/.env.example
ADDED
package/Dockerfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
FROM node:18-alpine
|
|
2
|
+
|
|
3
|
+
WORKDIR /app
|
|
4
|
+
|
|
5
|
+
# Copy package files
|
|
6
|
+
COPY package*.json ./
|
|
7
|
+
|
|
8
|
+
# Install dependencies
|
|
9
|
+
RUN npm ci --only=production
|
|
10
|
+
|
|
11
|
+
# Copy built files
|
|
12
|
+
COPY dist ./dist
|
|
13
|
+
|
|
14
|
+
# Expose port
|
|
15
|
+
EXPOSE 3000
|
|
16
|
+
|
|
17
|
+
# Set environment variable
|
|
18
|
+
ENV NODE_ENV=production
|
|
19
|
+
|
|
20
|
+
# Start the server
|
|
21
|
+
CMD ["node", "dist/index.js"]
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
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
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/QUICKSTART.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Snowflake MCP Server - Quick Start Guide
|
|
2
|
+
|
|
3
|
+
## ๐ Getting Started
|
|
4
|
+
|
|
5
|
+
### 1. Install Dependencies
|
|
6
|
+
```bash
|
|
7
|
+
npm install
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### 2. Configure Environment
|
|
11
|
+
Edit `.env` file with your Snowflake credentials:
|
|
12
|
+
```env
|
|
13
|
+
SNOWFLAKE_ACCOUNT=your-account.region.cloud
|
|
14
|
+
SNOWFLAKE_USERNAME=your-username
|
|
15
|
+
SNOWFLAKE_PASSWORD=your-password
|
|
16
|
+
SNOWFLAKE_WAREHOUSE=YOUR_WAREHOUSE # Optional
|
|
17
|
+
SNOWFLAKE_DATABASE=YOUR_DATABASE # Optional
|
|
18
|
+
SNOWFLAKE_SCHEMA=YOUR_SCHEMA # Optional
|
|
19
|
+
PORT=3000
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 3. Run the Server
|
|
23
|
+
|
|
24
|
+
**Development Mode:**
|
|
25
|
+
```bash
|
|
26
|
+
npm run dev
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Production Mode:**
|
|
30
|
+
```bash
|
|
31
|
+
npm run build
|
|
32
|
+
npm start
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## ๐ก API Endpoints
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | Description |
|
|
38
|
+
|--------|----------|-------------|
|
|
39
|
+
| GET | `/health` | Health check |
|
|
40
|
+
| GET | `/api/snowflake/status` | Connection status |
|
|
41
|
+
| POST | `/api/snowflake/query` | Execute SQL query |
|
|
42
|
+
| GET | `/api/snowflake/databases` | List databases |
|
|
43
|
+
| GET | `/api/snowflake/schemas` | List schemas |
|
|
44
|
+
| GET | `/api/snowflake/tables` | List tables |
|
|
45
|
+
| GET | `/api/snowflake/tables/:name/describe` | Describe table |
|
|
46
|
+
| GET | `/api/snowflake/warehouses` | List warehouses |
|
|
47
|
+
| GET | `/api/snowflake/session` | Current session info |
|
|
48
|
+
|
|
49
|
+
## ๐งช Testing
|
|
50
|
+
|
|
51
|
+
### Using cURL
|
|
52
|
+
```bash
|
|
53
|
+
# Health check
|
|
54
|
+
curl http://localhost:3000/health
|
|
55
|
+
|
|
56
|
+
# Execute query
|
|
57
|
+
curl -X POST http://localhost:3000/api/snowflake/query \
|
|
58
|
+
-H "Content-Type: application/json" \
|
|
59
|
+
-d '{"query": "SELECT CURRENT_DATE()"}'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Using the test script
|
|
63
|
+
```bash
|
|
64
|
+
./test-api.sh
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Import Postman Collection
|
|
68
|
+
Import `postman_collection.json` into Postman for easy testing.
|
|
69
|
+
|
|
70
|
+
## ๐ฆ NPM Package Usage
|
|
71
|
+
|
|
72
|
+
After publishing to NPM, users can install:
|
|
73
|
+
```bash
|
|
74
|
+
npm install @naganpm/snowflake-mcp-server
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Then use programmatically:
|
|
78
|
+
```typescript
|
|
79
|
+
import { SnowflakeService } from '@naganpm/snowflake-mcp-server';
|
|
80
|
+
|
|
81
|
+
const service = SnowflakeService.getInstance();
|
|
82
|
+
const result = await service.executeQuery('SELECT 1');
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## ๐ณ Docker Deployment
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Build and run with Docker Compose
|
|
89
|
+
docker-compose up -d
|
|
90
|
+
|
|
91
|
+
# Or build manually
|
|
92
|
+
docker build -t snowflake-mcp .
|
|
93
|
+
docker run -p 3000:3000 --env-file .env snowflake-mcp
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## ๐ Project Structure
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
snowflake-mcp-server/
|
|
100
|
+
โโโ src/
|
|
101
|
+
โ โโโ index.ts # Main server entry
|
|
102
|
+
โ โโโ services/
|
|
103
|
+
โ โ โโโ snowflake.service.ts # Snowflake SDK wrapper
|
|
104
|
+
โ โโโ routes/
|
|
105
|
+
โ โ โโโ snowflake.routes.ts # API routes
|
|
106
|
+
โ โโโ middleware/
|
|
107
|
+
โ โโโ error.middleware.ts # Error handling
|
|
108
|
+
โโโ dist/ # Compiled JavaScript
|
|
109
|
+
โโโ examples/ # Usage examples
|
|
110
|
+
โโโ package.json
|
|
111
|
+
โโโ tsconfig.json
|
|
112
|
+
โโโ .env # Environment config
|
|
113
|
+
โโโ Dockerfile
|
|
114
|
+
โโโ docker-compose.yml
|
|
115
|
+
โโโ README.md
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## ๐ Security Notes
|
|
119
|
+
|
|
120
|
+
- Never commit `.env` file to version control
|
|
121
|
+
- Use environment variables for sensitive data
|
|
122
|
+
- Consider using Snowflake key-pair authentication for production
|
|
123
|
+
- Implement rate limiting for production use
|
|
124
|
+
- Add authentication/authorization middleware
|
|
125
|
+
|
|
126
|
+
## ๐ ๏ธ Development Commands
|
|
127
|
+
|
|
128
|
+
| Command | Description |
|
|
129
|
+
|---------|-------------|
|
|
130
|
+
| `npm run dev` | Run in development mode |
|
|
131
|
+
| `npm run build` | Build TypeScript to JavaScript |
|
|
132
|
+
| `npm start` | Run production build |
|
|
133
|
+
| `npm run watch` | Watch mode for development |
|
|
134
|
+
| `npm run clean` | Clean dist folder |
|
|
135
|
+
|
|
136
|
+
## ๐ Publishing to NPM
|
|
137
|
+
|
|
138
|
+
1. Update version in `package.json`
|
|
139
|
+
2. Build the project: `npm run build`
|
|
140
|
+
3. Login to NPM: `npm login`
|
|
141
|
+
4. Publish: `npm publish --access public`
|
|
142
|
+
|
|
143
|
+
## ๐ค Contributing
|
|
144
|
+
|
|
145
|
+
1. Fork the repository
|
|
146
|
+
2. Create a feature branch
|
|
147
|
+
3. Make your changes
|
|
148
|
+
4. Submit a pull request
|
|
149
|
+
|
|
150
|
+
## ๐ License
|
|
151
|
+
|
|
152
|
+
MIT License - see LICENSE file for details
|
|
153
|
+
|
|
154
|
+
## ๐ Troubleshooting
|
|
155
|
+
|
|
156
|
+
### Connection Issues
|
|
157
|
+
- Verify Snowflake credentials in `.env`
|
|
158
|
+
- Check network connectivity to Snowflake
|
|
159
|
+
- Ensure account format is correct (account.region.cloud)
|
|
160
|
+
|
|
161
|
+
### Build Issues
|
|
162
|
+
- Clear node_modules: `rm -rf node_modules && npm install`
|
|
163
|
+
- Clear dist: `npm run clean && npm run build`
|
|
164
|
+
|
|
165
|
+
### Runtime Issues
|
|
166
|
+
- Check logs for error messages
|
|
167
|
+
- Verify environment variables are loaded
|
|
168
|
+
- Test with simple queries first
|
|
169
|
+
|
|
170
|
+
## ๐ Additional Resources
|
|
171
|
+
|
|
172
|
+
- [Snowflake SDK Documentation](https://docs.snowflake.com/en/user-guide/nodejs-driver)
|
|
173
|
+
- [Express.js Documentation](https://expressjs.com/)
|
|
174
|
+
- [TypeScript Documentation](https://www.typescriptlang.org/)
|
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Snowflake MCP Server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server for Snowflake database integration built with Express.js and TypeScript.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- โ
Execute custom SQL queries
|
|
8
|
+
- โ
List databases, schemas, and tables
|
|
9
|
+
- โ
Describe table structures
|
|
10
|
+
- โ
List warehouses
|
|
11
|
+
- โ
Get current session information
|
|
12
|
+
- โ
Connection status monitoring
|
|
13
|
+
- โ
TypeScript support
|
|
14
|
+
- โ
RESTful API
|
|
15
|
+
- โ
Error handling
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
1. Copy `.env.example` to `.env`:
|
|
26
|
+
```bash
|
|
27
|
+
cp .env.example .env
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
2. Update `.env` with your Snowflake credentials:
|
|
31
|
+
```env
|
|
32
|
+
SNOWFLAKE_ACCOUNT=your-account.region.cloud
|
|
33
|
+
SNOWFLAKE_USERNAME=your-username
|
|
34
|
+
SNOWFLAKE_PASSWORD=your-password
|
|
35
|
+
SNOWFLAKE_WAREHOUSE=YOUR_WAREHOUSE
|
|
36
|
+
SNOWFLAKE_DATABASE=YOUR_DATABASE
|
|
37
|
+
SNOWFLAKE_SCHEMA=YOUR_SCHEMA
|
|
38
|
+
PORT=3000
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Development Mode
|
|
44
|
+
```bash
|
|
45
|
+
npm run dev
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Build
|
|
49
|
+
```bash
|
|
50
|
+
npm run build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Production
|
|
54
|
+
```bash
|
|
55
|
+
npm start
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API Endpoints
|
|
59
|
+
|
|
60
|
+
### Health Check
|
|
61
|
+
```
|
|
62
|
+
GET /health
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Execute Query
|
|
66
|
+
```
|
|
67
|
+
POST /api/snowflake/query
|
|
68
|
+
Content-Type: application/json
|
|
69
|
+
|
|
70
|
+
{
|
|
71
|
+
"query": "SELECT * FROM table_name LIMIT 10",
|
|
72
|
+
"binds": []
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### List Databases
|
|
77
|
+
```
|
|
78
|
+
GET /api/snowflake/databases
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### List Schemas
|
|
82
|
+
```
|
|
83
|
+
GET /api/snowflake/schemas?database=YOUR_DATABASE
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### List Tables
|
|
87
|
+
```
|
|
88
|
+
GET /api/snowflake/tables?database=YOUR_DATABASE&schema=YOUR_SCHEMA
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Describe Table
|
|
92
|
+
```
|
|
93
|
+
GET /api/snowflake/tables/:tableName/describe
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### List Warehouses
|
|
97
|
+
```
|
|
98
|
+
GET /api/snowflake/warehouses
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Get Current Session
|
|
102
|
+
```
|
|
103
|
+
GET /api/snowflake/session
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Connection Status
|
|
107
|
+
```
|
|
108
|
+
GET /api/snowflake/status
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Example Requests
|
|
112
|
+
|
|
113
|
+
### Using cURL
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Health check
|
|
117
|
+
curl http://localhost:3000/health
|
|
118
|
+
|
|
119
|
+
# Execute query
|
|
120
|
+
curl -X POST http://localhost:3000/api/snowflake/query \
|
|
121
|
+
-H "Content-Type: application/json" \
|
|
122
|
+
-d '{"query": "SELECT CURRENT_DATE()"}'
|
|
123
|
+
|
|
124
|
+
# List databases
|
|
125
|
+
curl http://localhost:3000/api/snowflake/databases
|
|
126
|
+
|
|
127
|
+
# List tables
|
|
128
|
+
curl "http://localhost:3000/api/snowflake/tables?database=MYDB&schema=PUBLIC"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Using JavaScript/TypeScript
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// Execute query
|
|
135
|
+
const response = await fetch('http://localhost:3000/api/snowflake/query', {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
headers: {
|
|
138
|
+
'Content-Type': 'application/json',
|
|
139
|
+
},
|
|
140
|
+
body: JSON.stringify({
|
|
141
|
+
query: 'SELECT * FROM my_table LIMIT 10',
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const result = await response.json();
|
|
146
|
+
console.log(result.data);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Response Format
|
|
150
|
+
|
|
151
|
+
All successful responses follow this format:
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"success": true,
|
|
155
|
+
"data": {
|
|
156
|
+
"columns": ["col1", "col2"],
|
|
157
|
+
"rows": [
|
|
158
|
+
{ "col1": "value1", "col2": "value2" }
|
|
159
|
+
],
|
|
160
|
+
"rowCount": 1,
|
|
161
|
+
"executionTime": 123
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Error responses:
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"success": false,
|
|
170
|
+
"error": {
|
|
171
|
+
"message": "Error message",
|
|
172
|
+
"code": "ERROR_CODE"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Development
|
|
178
|
+
|
|
179
|
+
### Project Structure
|
|
180
|
+
```
|
|
181
|
+
.
|
|
182
|
+
โโโ src/
|
|
183
|
+
โ โโโ index.ts # Main entry point
|
|
184
|
+
โ โโโ services/
|
|
185
|
+
โ โ โโโ snowflake.service.ts # Snowflake service
|
|
186
|
+
โ โโโ routes/
|
|
187
|
+
โ โ โโโ snowflake.routes.ts # API routes
|
|
188
|
+
โ โโโ middleware/
|
|
189
|
+
โ โโโ error.middleware.ts # Error handling
|
|
190
|
+
โโโ package.json
|
|
191
|
+
โโโ tsconfig.json
|
|
192
|
+
โโโ .env
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Scripts
|
|
196
|
+
|
|
197
|
+
- `npm run build` - Build TypeScript to JavaScript
|
|
198
|
+
- `npm run dev` - Run in development mode with ts-node
|
|
199
|
+
- `npm start` - Run production build
|
|
200
|
+
- `npm run watch` - Watch mode for development
|
|
201
|
+
- `npm run clean` - Clean dist folder
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# Snowflake MCP Server - Complete Setup โ
|
|
2
|
+
|
|
3
|
+
## โจ What Has Been Created
|
|
4
|
+
|
|
5
|
+
A production-ready Snowflake MCP (Model Context Protocol) server configured as an NPM package with the following features:
|
|
6
|
+
|
|
7
|
+
### ๐ฏ Core Features
|
|
8
|
+
- **Express.js REST API** with TypeScript
|
|
9
|
+
- **Snowflake SDK Integration** for database operations
|
|
10
|
+
- **Singleton Pattern** for connection management
|
|
11
|
+
- **Error Handling Middleware**
|
|
12
|
+
- **CORS Support**
|
|
13
|
+
- **Environment Configuration**
|
|
14
|
+
- **Health Monitoring**
|
|
15
|
+
|
|
16
|
+
### ๐ Project Structure
|
|
17
|
+
```
|
|
18
|
+
snowflake-mcp-server/
|
|
19
|
+
โโโ src/
|
|
20
|
+
โ โโโ index.ts # Main server (Express app)
|
|
21
|
+
โ โโโ services/
|
|
22
|
+
โ โ โโโ snowflake.service.ts # Snowflake connection & queries
|
|
23
|
+
โ โโโ routes/
|
|
24
|
+
โ โ โโโ snowflake.routes.ts # API endpoints
|
|
25
|
+
โ โโโ middleware/
|
|
26
|
+
โ โโโ error.middleware.ts # Error handling
|
|
27
|
+
โโโ dist/ # Compiled JavaScript
|
|
28
|
+
โโโ examples/
|
|
29
|
+
โ โโโ usage.ts # Usage examples
|
|
30
|
+
โโโ node_modules/ # Dependencies
|
|
31
|
+
โโโ .env # Your Snowflake credentials
|
|
32
|
+
โโโ .env.example # Template
|
|
33
|
+
โโโ package.json # NPM configuration
|
|
34
|
+
โโโ tsconfig.json # TypeScript config
|
|
35
|
+
โโโ Dockerfile # Docker image
|
|
36
|
+
โโโ docker-compose.yml # Docker compose
|
|
37
|
+
โโโ postman_collection.json # API testing
|
|
38
|
+
โโโ test-api.sh # Bash test script
|
|
39
|
+
โโโ README.md # Full documentation
|
|
40
|
+
โโโ QUICKSTART.md # Quick start guide
|
|
41
|
+
โโโ LICENSE # MIT license
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### ๐ Available API Endpoints
|
|
45
|
+
|
|
46
|
+
| Endpoint | Method | Description |
|
|
47
|
+
|----------|--------|-------------|
|
|
48
|
+
| `/health` | GET | Health check |
|
|
49
|
+
| `/api/snowflake/status` | GET | Connection status |
|
|
50
|
+
| `/api/snowflake/query` | POST | Execute SQL query |
|
|
51
|
+
| `/api/snowflake/databases` | GET | List all databases |
|
|
52
|
+
| `/api/snowflake/schemas` | GET | List schemas |
|
|
53
|
+
| `/api/snowflake/tables` | GET | List tables |
|
|
54
|
+
| `/api/snowflake/tables/:name/describe` | GET | Describe table structure |
|
|
55
|
+
| `/api/snowflake/warehouses` | GET | List warehouses |
|
|
56
|
+
| `/api/snowflake/session` | GET | Current session info |
|
|
57
|
+
|
|
58
|
+
### ๐ง Configuration
|
|
59
|
+
|
|
60
|
+
**Port:** 3000
|
|
61
|
+
|
|
62
|
+
All credentials should be stored in `.env` file (not committed to git).
|
|
63
|
+
|
|
64
|
+
See `.env.example` for configuration template.
|
|
65
|
+
|
|
66
|
+
## ๐ Quick Start Commands
|
|
67
|
+
|
|
68
|
+
### 1. Development Mode
|
|
69
|
+
```bash
|
|
70
|
+
npm run dev
|
|
71
|
+
# Server runs at: http://localhost:3000
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 2. Build for Production
|
|
75
|
+
```bash
|
|
76
|
+
npm run build
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 3. Run Production Build
|
|
80
|
+
```bash
|
|
81
|
+
npm start
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 4. Test the API
|
|
85
|
+
```bash
|
|
86
|
+
# Using curl
|
|
87
|
+
curl http://localhost:3000/health
|
|
88
|
+
|
|
89
|
+
# Using the test script
|
|
90
|
+
./test-api.sh
|
|
91
|
+
|
|
92
|
+
# Using Postman
|
|
93
|
+
# Import postman_collection.json into Postman
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## ๐ฆ NPM Package Details
|
|
97
|
+
|
|
98
|
+
- **Package Name:** `@naganpm/snowflake-mcp-server`
|
|
99
|
+
- **Version:** 1.0.0
|
|
100
|
+
- **Main Entry:** `dist/index.js`
|
|
101
|
+
- **TypeScript Definitions:** `dist/index.d.ts`
|
|
102
|
+
- **Binary:** `snowflake-mcp-server`
|
|
103
|
+
|
|
104
|
+
### To Publish to NPM:
|
|
105
|
+
```bash
|
|
106
|
+
npm login
|
|
107
|
+
npm publish --access public
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## ๐งช Testing Examples
|
|
111
|
+
|
|
112
|
+
### Test Health Check
|
|
113
|
+
```bash
|
|
114
|
+
curl http://localhost:3000/health
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Execute a Query
|
|
118
|
+
```bash
|
|
119
|
+
curl -X POST http://localhost:3000/api/snowflake/query \
|
|
120
|
+
-H "Content-Type: application/json" \
|
|
121
|
+
-d '{
|
|
122
|
+
"query": "SELECT CURRENT_DATE(), CURRENT_USER(), CURRENT_ROLE()"
|
|
123
|
+
}'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### List Databases
|
|
127
|
+
```bash
|
|
128
|
+
curl http://localhost:3000/api/snowflake/databases
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Get Session Info
|
|
132
|
+
```bash
|
|
133
|
+
curl http://localhost:3000/api/snowflake/session
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## ๐ณ Docker Deployment
|
|
137
|
+
|
|
138
|
+
### Build and Run
|
|
139
|
+
```bash
|
|
140
|
+
docker-compose up -d
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Manual Docker Build
|
|
144
|
+
```bash
|
|
145
|
+
docker build -t snowflake-mcp .
|
|
146
|
+
docker run -p 3000:3000 --env-file .env snowflake-mcp
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## ๐ Key Dependencies
|
|
150
|
+
|
|
151
|
+
- **express** ^4.18.2 - Web framework
|
|
152
|
+
- **snowflake-sdk** ^1.11.0 - Snowflake database driver
|
|
153
|
+
- **typescript** ^5.3.3 - Type safety
|
|
154
|
+
- **dotenv** ^16.4.1 - Environment configuration
|
|
155
|
+
- **cors** ^2.8.5 - CORS support
|
|
156
|
+
|
|
157
|
+
## ๐ Usage as NPM Package
|
|
158
|
+
|
|
159
|
+
After installation:
|
|
160
|
+
```typescript
|
|
161
|
+
import { SnowflakeService } from '@naganpm/snowflake-mcp-server';
|
|
162
|
+
|
|
163
|
+
// Get singleton instance
|
|
164
|
+
const service = SnowflakeService.getInstance();
|
|
165
|
+
|
|
166
|
+
// Execute queries
|
|
167
|
+
const result = await service.executeQuery('SELECT * FROM my_table LIMIT 10');
|
|
168
|
+
console.log(result.rows);
|
|
169
|
+
|
|
170
|
+
// List databases
|
|
171
|
+
const databases = await service.listDatabases();
|
|
172
|
+
|
|
173
|
+
// Describe table
|
|
174
|
+
const tableInfo = await service.describeTable('my_table');
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## โ
Verified Working
|
|
178
|
+
|
|
179
|
+
- โ
Server starts successfully
|
|
180
|
+
- โ
Health endpoint responds
|
|
181
|
+
- โ
Status endpoint works
|
|
182
|
+
- โ
TypeScript compiles without errors
|
|
183
|
+
- โ
All dependencies installed
|
|
184
|
+
- โ
Environment configuration loaded
|
|
185
|
+
|
|
186
|
+
## ๐ Documentation Files
|
|
187
|
+
|
|
188
|
+
- **README.md** - Comprehensive documentation
|
|
189
|
+
- **QUICKSTART.md** - Quick start guide
|
|
190
|
+
- **postman_collection.json** - Postman API collection
|
|
191
|
+
- **examples/usage.ts** - Code examples
|
|
192
|
+
- **test-api.sh** - Automated testing script
|
|
193
|
+
|
|
194
|
+
## ๐ Security Notes
|
|
195
|
+
|
|
196
|
+
- `.env` file is in `.gitignore` (not committed)
|
|
197
|
+
- Password stored only locally
|
|
198
|
+
- Add authentication middleware for production
|
|
199
|
+
- Consider using Snowflake key-pair auth for production
|
|
200
|
+
- Implement rate limiting
|
|
201
|
+
|
|
202
|
+
## ๐ ๏ธ Development Workflow
|
|
203
|
+
|
|
204
|
+
1. **Make changes** in `src/` directory
|
|
205
|
+
2. **Test** with `npm run dev`
|
|
206
|
+
3. **Build** with `npm run build`
|
|
207
|
+
4. **Deploy** with `npm start` or Docker
|
|
208
|
+
|
|
209
|
+
## ๐ Next Steps
|
|
210
|
+
|
|
211
|
+
1. Add your Snowflake warehouse, database, and schema to `.env` (optional)
|
|
212
|
+
2. Start the server: `npm run dev`
|
|
213
|
+
3. Test with Postman or curl
|
|
214
|
+
4. Deploy to production or publish to NPM
|
|
215
|
+
5. Add authentication/authorization if needed
|
|
216
|
+
6. Set up CI/CD pipeline
|
|
217
|
+
|
|
218
|
+
## ๐ Success!
|
|
219
|
+
|
|
220
|
+
Your Snowflake MCP server is ready to use! It's configured as a proper NPM package following the structure of `@naganpm/mysql-mcp-server`.
|
|
221
|
+
|
|
222
|
+
Start the server with `npm run dev` and visit:
|
|
223
|
+
- Health: http://localhost:3000/health
|
|
224
|
+
- API Docs: See README.md for all endpoints
|
|
225
|
+
|
|
226
|
+
Happy coding! ๐
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAgB,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AAS9D,QAAA,MAAM,GAAG,EAAE,OAAmB,CAAC;AAwC/B,eAAe,GAAG,CAAC"}
|