diff --git a/.env.example b/.env.example index a24f6592..abdd1be4 100644 --- a/.env.example +++ b/.env.example @@ -47,7 +47,9 @@ SLACK_SIGNING_SECRET=your-slack-signing-secret SLACK_WEBHOOK_ERROR=https://hooks.slack.com/services/YOUR/WEBHOOK/URL SLACK_WEBHOOK_EVENT=https://hooks.slack.com/services/YOUR/WEBHOOK/URL -# Gemini AI Configuration -GEMINI_PROJECT_ID=your-gcp-project-id -GEMINI_LOCATION=us-central1 -GEMINI_MODEL=gemini-1.5-flash +# Gemini AI Configuration (REST API with API Key) +GEMINI_API_KEY=your-gemini-api-key +GEMINI_MODEL=gemini-2.0-flash + +# MCP Bridge Configuration +MCP_BRIDGE_URL=http://localhost:3100 diff --git a/.gitignore b/.gitignore index 88efa1e5..e6cc1750 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ HELP.md +.mcp.json .gradle build/ !gradle/wrapper/gradle-wrapper.jar @@ -44,3 +45,7 @@ logs .env* !.env.example + +### MCP Bridge ### +mcp-bridge/node_modules/ +mcp-bridge/.env diff --git a/.mcp.json b/.mcp.json new file mode 100644 index 00000000..afee27e8 --- /dev/null +++ b/.mcp.json @@ -0,0 +1,15 @@ +{ + "mcpServers": { + "mysql": { + "command": "npx", + "args": ["@ahngbeom/mysql-mcp-server"], + "env": { + "MYSQL_HOST": "localhost", + "MYSQL_PORT": "3306", + "MYSQL_USER": "your_user", + "MYSQL_PASS": "your_password", + "MYSQL_DB": "your_database" + } + } + } +} diff --git a/build.gradle b/build.gradle index e2926cfe..86f4e39b 100644 --- a/build.gradle +++ b/build.gradle @@ -70,8 +70,7 @@ dependencies { // notification implementation 'com.google.firebase:firebase-admin:9.2.0' - // Gemini AI - implementation 'com.google.cloud:google-cloud-vertexai:1.15.0' + // Gemini AI - using REST API directly (no SDK dependency) // test testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/mcp-bridge/.env.example b/mcp-bridge/.env.example new file mode 100644 index 00000000..7dee12b1 --- /dev/null +++ b/mcp-bridge/.env.example @@ -0,0 +1,9 @@ +# MCP Bridge Server Configuration +MCP_BRIDGE_PORT=3100 + +# MySQL Connection (Read-Only Account Recommended) +MYSQL_HOST=localhost +MYSQL_PORT=3306 +MYSQL_USER=konect_readonly +MYSQL_PASS=your_password_here +MYSQL_DB=konect diff --git a/mcp-bridge/index.js b/mcp-bridge/index.js new file mode 100644 index 00000000..148796f0 --- /dev/null +++ b/mcp-bridge/index.js @@ -0,0 +1,292 @@ +const express = require('express'); +const { spawn } = require('child_process'); +const path = require('path'); + +const app = express(); +app.use(express.json()); + +const PORT = process.env.MCP_BRIDGE_PORT || 3100; +const HOST = process.env.MCP_BRIDGE_HOST || '127.0.0.1'; + +let mcpProcess = null; +let requestId = 0; +const pendingRequests = new Map(); +let buffer = ''; + +// Restart backoff strategy +let restartAttempts = 0; +const MAX_RESTART_ATTEMPTS = 5; +const BASE_RESTART_DELAY = 1000; + +// Forbidden SQL keywords for read-only validation +const FORBIDDEN_PATTERNS = [ + /\bINSERT\b/i, + /\bUPDATE\b/i, + /\bDELETE\b/i, + /\bDROP\b/i, + /\bCREATE\b/i, + /\bALTER\b/i, + /\bTRUNCATE\b/i, + /\bGRANT\b/i, + /\bREVOKE\b/i, + /\bEXEC\b/i, + /\bEXECUTE\b/i, + /\bINTO\s+OUTFILE\b/i, + /\bINTO\s+DUMPFILE\b/i, + /;\s*\w/i // Multiple statements +]; + +// Valid table name pattern +const VALID_TABLE_NAME = /^[a-zA-Z_][a-zA-Z0-9_]*$/; + +/** + * Start MCP server process with backoff + */ +function startMcpServer() { + if (restartAttempts >= MAX_RESTART_ATTEMPTS) { + console.error(`Max restart attempts (${MAX_RESTART_ATTEMPTS}) reached. Giving up.`); + return; + } + + const mcpServerPath = path.join(__dirname, 'node_modules', '@ahngbeom', 'mysql-mcp-server', 'dist', 'index.js'); + + mcpProcess = spawn('node', [mcpServerPath], { + env: { + ...process.env, + MYSQL_HOST: process.env.MYSQL_HOST || 'localhost', + MYSQL_PORT: process.env.MYSQL_PORT || '3306', + MYSQL_USER: process.env.MYSQL_USER, + MYSQL_PASS: process.env.MYSQL_PASS, + MYSQL_DB: process.env.MYSQL_DB + }, + stdio: ['pipe', 'pipe', 'pipe'] + }); + + mcpProcess.stdout.on('data', (data) => { + buffer += data.toString(); + + // Process complete JSON-RPC messages (newline delimited) + const lines = buffer.split('\n'); + buffer = lines.pop() || ''; + + for (const line of lines) { + if (!line.trim()) continue; + + try { + const response = JSON.parse(line); + const pending = pendingRequests.get(response.id); + if (pending) { + if (response.error) { + pending.reject(new Error(response.error.message || 'MCP error')); + } else { + pending.resolve(response.result); + } + pendingRequests.delete(response.id); + } + } catch (e) { + console.error('Failed to parse MCP response:', e.message); + } + } + }); + + mcpProcess.stderr.on('data', (data) => { + console.error('MCP stderr:', data.toString()); + }); + + mcpProcess.on('exit', (code) => { + console.log(`MCP process exited with code ${code}`); + // Reject all pending requests + for (const [id, pending] of pendingRequests) { + pending.reject(new Error('MCP process exited')); + pendingRequests.delete(id); + } + + // Exponential backoff restart + restartAttempts++; + const delay = BASE_RESTART_DELAY * Math.pow(2, restartAttempts - 1); + console.log(`Attempting restart ${restartAttempts}/${MAX_RESTART_ATTEMPTS} in ${delay}ms...`); + setTimeout(startMcpServer, delay); + }); + + console.log('MCP server process started'); + restartAttempts = 0; // Reset on successful start + + // Initialize MCP connection + sendRequest('initialize', { + protocolVersion: '2024-11-05', + capabilities: {}, + clientInfo: { name: 'konect-mcp-bridge', version: '1.0.0' } + }).then(() => { + console.log('MCP connection initialized'); + return sendRequest('notifications/initialized', {}); + }).catch(err => { + console.error('MCP initialization failed:', err.message); + }); +} + +/** + * Send JSON-RPC request to MCP server + */ +function sendRequest(method, params) { + return new Promise((resolve, reject) => { + if (!mcpProcess || mcpProcess.killed) { + reject(new Error('MCP process not running')); + return; + } + + const id = ++requestId; + const timeout = setTimeout(() => { + pendingRequests.delete(id); + reject(new Error('Request timeout')); + }, 30000); + + pendingRequests.set(id, { + resolve: (result) => { + clearTimeout(timeout); + resolve(result); + }, + reject: (err) => { + clearTimeout(timeout); + reject(err); + } + }); + + const request = JSON.stringify({ + jsonrpc: '2.0', + id, + method, + params + }); + + mcpProcess.stdin.write(request + '\n'); + }); +} + +/** + * Validate SQL is read-only + */ +function validateReadOnlySql(sql) { + if (!sql || typeof sql !== 'string') { + return { valid: false, error: 'SQL is required' }; + } + + const trimmedSql = sql.trim(); + if (!trimmedSql.toUpperCase().startsWith('SELECT')) { + return { valid: false, error: 'Only SELECT queries are allowed' }; + } + + for (const pattern of FORBIDDEN_PATTERNS) { + if (pattern.test(trimmedSql)) { + return { valid: false, error: 'Query contains forbidden pattern' }; + } + } + + return { valid: true }; +} + +/** + * Validate table name + */ +function validateTableName(tableName) { + if (!tableName || typeof tableName !== 'string') { + return false; + } + return VALID_TABLE_NAME.test(tableName); +} + +// Health check endpoint +app.get('/health', (req, res) => { + const isHealthy = mcpProcess && !mcpProcess.killed; + res.status(isHealthy ? 200 : 503).json({ + status: isHealthy ? 'healthy' : 'unhealthy', + mcpRunning: isHealthy + }); +}); + +// Convenience endpoint for SQL queries +app.post('/query', async (req, res) => { + const { sql } = req.body; + + const validation = validateReadOnlySql(sql); + if (!validation.valid) { + return res.status(400).json({ + error: validation.error, + code: 'READ_ONLY_VIOLATION' + }); + } + + try { + const result = await sendRequest('tools/call', { + name: 'query', + arguments: { sql } + }); + res.json(result); + } catch (err) { + console.error('Query execution failed:', err.message); + res.status(500).json({ error: err.message }); + } +}); + +// List tables endpoint +app.get('/tables', async (req, res) => { + try { + const result = await sendRequest('tools/call', { + name: 'list_tables', + arguments: {} + }); + res.json(result); + } catch (err) { + console.error('Failed to list tables:', err.message); + res.status(500).json({ error: err.message }); + } +}); + +// Describe table endpoint +app.get('/tables/:tableName', async (req, res) => { + const { tableName } = req.params; + + if (!validateTableName(tableName)) { + return res.status(400).json({ + error: 'Invalid table name', + code: 'INVALID_TABLE_NAME' + }); + } + + try { + const result = await sendRequest('tools/call', { + name: 'describe_table', + arguments: { table: tableName } + }); + res.json(result); + } catch (err) { + console.error(`Failed to describe table ${tableName}:`, err.message); + res.status(500).json({ error: err.message }); + } +}); + +// Start server +startMcpServer(); + +app.listen(PORT, HOST, () => { + console.log(`MCP Bridge server running on ${HOST}:${PORT}`); +}); + +// Graceful shutdown +function gracefulShutdown(signal) { + console.log(`Received ${signal}, shutting down...`); + + // Reject all pending requests + for (const [id, pending] of pendingRequests) { + pending.reject(new Error('Server shutting down')); + pendingRequests.delete(id); + } + + if (mcpProcess) { + mcpProcess.kill(); + } + + process.exit(0); +} + +process.on('SIGTERM', () => gracefulShutdown('SIGTERM')); +process.on('SIGINT', () => gracefulShutdown('SIGINT')); diff --git a/mcp-bridge/package-lock.json b/mcp-bridge/package-lock.json new file mode 100644 index 00000000..a52cc053 --- /dev/null +++ b/mcp-bridge/package-lock.json @@ -0,0 +1,1683 @@ +{ + "name": "konect-mcp-bridge", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "konect-mcp-bridge", + "version": "1.0.0", + "dependencies": { + "@ahngbeom/mysql-mcp-server": "*", + "express": "^4.21.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@ahngbeom/mysql-mcp-server": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@ahngbeom/mysql-mcp-server/-/mysql-mcp-server-1.0.1.tgz", + "integrity": "sha512-S4lMmqOzwdBGPMbvsEo0XKzrNSK1tObcj3n338VG4R0o8noFDGEEITA4QBiP7g7xgCqAsu/7V0k/a7Y6hXGeww==", + "license": "MIT", + "dependencies": { + "@modelcontextprotocol/sdk": "^1.0.0", + "mysql2": "^3.11.0" + }, + "bin": { + "mysql-mcp-server": "dist/index.js" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@hono/node-server": { + "version": "1.19.11", + "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-1.19.11.tgz", + "integrity": "sha512-dr8/3zEaB+p0D2n/IUrlPF1HZm586qgJNXK1a9fhg/PzdtkK7Ksd5l312tJX2yBuALqDYBlG20QEbayqPyxn+g==", + "license": "MIT", + "engines": { + "node": ">=18.14.1" + }, + "peerDependencies": { + "hono": "^4" + } + }, + "node_modules/@modelcontextprotocol/sdk": { + "version": "1.27.1", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.27.1.tgz", + "integrity": "sha512-sr6GbP+4edBwFndLbM60gf07z0FQ79gaExpnsjMGePXqFcSSb7t6iscpjk9DhFhwd+mTEQrzNafGP8/iGGFYaA==", + "license": "MIT", + "dependencies": { + "@hono/node-server": "^1.19.9", + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", + "content-type": "^1.0.5", + "cors": "^2.8.5", + "cross-spawn": "^7.0.5", + "eventsource": "^3.0.2", + "eventsource-parser": "^3.0.0", + "express": "^5.2.1", + "express-rate-limit": "^8.2.1", + "hono": "^4.11.4", + "jose": "^6.1.3", + "json-schema-typed": "^8.0.2", + "pkce-challenge": "^5.0.0", + "raw-body": "^3.0.0", + "zod": "^3.25 || ^4.0", + "zod-to-json-schema": "^3.25.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@cfworker/json-schema": "^4.1.1", + "zod": "^3.25 || ^4.0" + }, + "peerDependenciesMeta": { + "@cfworker/json-schema": { + "optional": true + }, + "zod": { + "optional": false + } + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/body-parser": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz", + "integrity": "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.3", + "http-errors": "^2.0.0", + "iconv-lite": "^0.7.0", + "on-finished": "^2.4.1", + "qs": "^6.14.1", + "raw-body": "^3.0.1", + "type-is": "^2.0.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/content-disposition": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz", + "integrity": "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/@modelcontextprotocol/sdk/node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/@types/node": { + "version": "25.3.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.3.5.tgz", + "integrity": "sha512-oX8xrhvpiyRCQkG1MFchB09f+cXftgIXb3a7UUa4Y3wpmZPw5tyZGTLWhlESOLq1Rq6oDlc8npVU2/9xiCuXMA==", + "license": "MIT", + "peer": true, + "dependencies": { + "undici-types": "~7.18.0" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ajv": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", + "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/aws-ssl-profiles": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", + "integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/body-parser": { + "version": "1.20.4", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz", + "integrity": "sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.14.0", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/body-parser/node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", + "license": "MIT" + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/eventsource": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz", + "integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==", + "license": "MIT", + "dependencies": { + "eventsource-parser": "^3.0.1" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz", + "integrity": "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/express": { + "version": "4.22.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz", + "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==", + "license": "MIT", + "peer": true, + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.3", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.12", + "proxy-addr": "~2.0.7", + "qs": "~6.14.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express-rate-limit": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.3.0.tgz", + "integrity": "sha512-KJzBawY6fB9FiZGdE/0aftepZ91YlaGIrV8vgblRM3J8X+dHx/aiowJWwkx6LIGyuqGiANsjSwwrbb8mifOJ4Q==", + "license": "MIT", + "dependencies": { + "ip-address": "10.1.0" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/express-rate-limit" + }, + "peerDependencies": { + "express": ">= 4.11" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", + "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/generate-function": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "license": "MIT", + "dependencies": { + "is-property": "^1.0.2" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/hono": { + "version": "4.12.5", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.5.tgz", + "integrity": "sha512-3qq+FUBtlTHhtYxbxheZgY8NIFnkkC/MR8u5TTsr7YZ3wixryQ3cCwn3iZbg8p8B88iDBBAYSfZDS75t8MN7Vg==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ip-address": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz", + "integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==", + "license": "MIT" + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "license": "ISC" + }, + "node_modules/jose": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.0.tgz", + "integrity": "sha512-xsfE1TcSCbUdo6U07tR0mvhg0flGxU8tPLbF03mirl2ukGQENhUg4ubGYQnhVH0b5stLlPM+WOqDkEl1R1y5sQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "node_modules/json-schema-typed": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.2.tgz", + "integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==", + "license": "BSD-2-Clause" + }, + "node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" + }, + "node_modules/lru.min": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.4.tgz", + "integrity": "sha512-DqC6n3QQ77zdFpCMASA1a3Jlb64Hv2N2DciFGkO/4L9+q/IpIAuRlKOvCXabtRW6cQf8usbmM6BE/TOPysCdIA==", + "license": "MIT", + "engines": { + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/mysql2": { + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.19.0.tgz", + "integrity": "sha512-760Ay9HViAUT7V8QkYxrIx/LHJPGWtE+D/31VuiDm1eu2IFaUIqMcK7+hVHnmgnC7JnnwreFKsZoa8K6BnGl8Q==", + "license": "MIT", + "dependencies": { + "aws-ssl-profiles": "^1.1.2", + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.7.2", + "long": "^5.3.2", + "lru.min": "^1.1.4", + "named-placeholders": "^1.1.6", + "sql-escaper": "^1.3.3" + }, + "engines": { + "node": ">= 8.0" + }, + "peerDependencies": { + "@types/node": ">= 8" + } + }, + "node_modules/mysql2/node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/named-placeholders": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.6.tgz", + "integrity": "sha512-Tz09sEL2EEuv5fFowm419c1+a/jSMiBjI9gHxVLrVdbUkkNUUfjsVYs9pVZu5oCon/kmRh9TfLEObFtkVxmY0w==", + "license": "MIT", + "dependencies": { + "lru.min": "^1.1.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", + "license": "MIT" + }, + "node_modules/pkce-challenge": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz", + "integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==", + "license": "MIT", + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.14.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz", + "integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/raw-body/node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/router/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/router/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/router/node_modules/path-to-regexp": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz", + "integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/sql-escaper": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/sql-escaper/-/sql-escaper-1.3.3.tgz", + "integrity": "sha512-BsTCV265VpTp8tm1wyIm1xqQCS+Q9NHx2Sr+WcnUrgLrQ6yiDIvHYJV5gHxsj1lMBy2zm5twLaZao8Jd+S8JJw==", + "license": "MIT", + "engines": { + "bun": ">=1.0.0", + "deno": ">=2.0.0", + "node": ">=12.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/mysqljs/sql-escaper?sponsor=1" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/undici-types": { + "version": "7.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", + "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", + "license": "MIT" + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/zod": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz", + "integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==", + "license": "MIT", + "peer": true, + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-to-json-schema": { + "version": "3.25.1", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.25.1.tgz", + "integrity": "sha512-pM/SU9d3YAggzi6MtR4h7ruuQlqKtad8e9S0fmxcMi+ueAK5Korys/aWcV9LIIHTVbj01NdzxcnXSN+O74ZIVA==", + "license": "ISC", + "peerDependencies": { + "zod": "^3.25 || ^4" + } + } + } +} diff --git a/mcp-bridge/package.json b/mcp-bridge/package.json new file mode 100644 index 00000000..0a4b1162 --- /dev/null +++ b/mcp-bridge/package.json @@ -0,0 +1,17 @@ +{ + "name": "konect-mcp-bridge", + "version": "1.0.0", + "description": "HTTP bridge for MCP MySQL server (stdio → HTTP)", + "main": "index.js", + "scripts": { + "start": "node index.js", + "dev": "node index.js" + }, + "dependencies": { + "express": "^4.21.0", + "@ahngbeom/mysql-mcp-server": "^1.0.0" + }, + "engines": { + "node": ">=18.0.0" + } +} diff --git a/src/main/java/gg/agit/konect/infrastructure/gemini/client/GeminiClient.java b/src/main/java/gg/agit/konect/infrastructure/gemini/client/GeminiClient.java index 1d086ebc..834714ca 100644 --- a/src/main/java/gg/agit/konect/infrastructure/gemini/client/GeminiClient.java +++ b/src/main/java/gg/agit/konect/infrastructure/gemini/client/GeminiClient.java @@ -1,125 +1,281 @@ package gg.agit.konect.infrastructure.gemini.client; -import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; +import org.springframework.web.client.RestClient; +import org.springframework.web.client.RestClientException; -import com.google.cloud.vertexai.VertexAI; -import com.google.cloud.vertexai.api.GenerateContentResponse; -import com.google.cloud.vertexai.generativeai.GenerativeModel; -import com.google.cloud.vertexai.generativeai.ResponseHandler; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import gg.agit.konect.infrastructure.gemini.config.GeminiProperties; -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; +import gg.agit.konect.infrastructure.mcp.client.McpClient; import lombok.extern.slf4j.Slf4j; @Slf4j @Component public class GeminiClient { - private static final String INTENT_ANALYSIS_PROMPT = """ + private static final String API_URL_TEMPLATE = + "https://generativelanguage.googleapis.com/v1beta/models/%s:generateContent"; + + private static final String API_KEY_HEADER = "x-goog-api-key"; + + private static final double GENERATION_TEMPERATURE = 0.7; + private static final int MAX_OUTPUT_TOKENS = 1024; + + private static final String SYSTEM_PROMPT = """ 당신은 KONECT 서비스의 데이터 분석 AI입니다. - 사용자의 질문을 분석하여 다음 중 하나의 쿼리 타입만 반환하세요. - 반드시 아래 목록 중 하나의 값만 반환하고, 다른 텍스트는 포함하지 마세요. - - 가능한 쿼리 타입: - - USER_COUNT: 가입된 사용자 수, 회원 수, 유저 수 관련 질문 - - CLUB_COUNT: 전체 동아리 수, 동아리 개수 관련 질문 - - CLUB_RECRUITING_COUNT: 현재 모집 중인 동아리 수, 모집 현황 관련 질문 - - CLUB_MEMBER_TOTAL_COUNT: 전체 동아리원 수, 동아리 멤버 총 인원 관련 질문 - - UNKNOWN: 위 항목에 해당하지 않는 질문 - - 예시: - - "가입된 사용자 수 알려줘" -> USER_COUNT - - "현재 모집 중인 동아리 몇개야?" -> CLUB_RECRUITING_COUNT - - "전체 동아리 수는?" -> CLUB_COUNT - - "동아리원이 총 몇명이야?" -> CLUB_MEMBER_TOTAL_COUNT - - "오늘 날씨 어때?" -> UNKNOWN - - "특정 사용자 이메일 알려줘" -> UNKNOWN - - 사용자 질문: %s - - 쿼리 타입: - """; + 사용자 질문에 답하기 위해 query 도구를 사용하여 MySQL 데이터베이스를 조회하세요. + SELECT 문만 사용 가능합니다. - private static final String RESPONSE_GENERATION_PROMPT = """ - 당신은 KONECT 서비스의 친절한 AI 어시스턴트입니다. - 아래 정보를 바탕으로 사용자에게 자연스럽고 친절한 한국어로 응답해주세요. - 이모지를 적절히 사용하여 친근하게 답변해주세요. - 응답은 간결하게 2-3문장으로 작성해주세요. + 주요 테이블: + - users: 사용자 정보 (deleted_at IS NULL = 활성 사용자) + - club: 동아리 정보 + - club_member: 동아리 멤버 정보 + - club_recruitment: 모집 공고 (is_always_recruiting=true 또는 start_at <= NOW() AND end_at >= NOW() = 모집 중) - 사용자 질문: %s - 조회된 데이터: %s + 질문에 적절한 SQL을 작성하고 query 도구를 호출하세요. + 결과를 받으면 사용자에게 친절하고 자연스러운 한국어로 응답하세요. + 이모지를 적절히 사용하여 친근하게 답변하세요. + 응답은 간결하게 2-3문장으로 작성하세요. - 응답: + 지원하지 않는 질문(데이터베이스와 무관한 질문)에는 정중히 거절하고, + 어떤 질문이 가능한지 안내하세요. """; + private static final Map QUERY_TOOL = Map.of( + "name", "query", + "description", "MySQL 데이터베이스에 SELECT 쿼리를 실행합니다. 반드시 SELECT 문만 사용하세요.", + "parameters", Map.of( + "type", "object", + "properties", Map.of( + "sql", Map.of( + "type", "string", + "description", "실행할 SELECT SQL 쿼리" + ) + ), + "required", List.of("sql") + ) + ); + + private final RestClient restClient; private final GeminiProperties geminiProperties; - private VertexAI vertexAI; - private GenerativeModel generativeModel; + private final McpClient mcpClient; + private final ObjectMapper objectMapper; - public GeminiClient(GeminiProperties geminiProperties) { + public GeminiClient(RestClient.Builder restClientBuilder, + GeminiProperties geminiProperties, + McpClient mcpClient, + ObjectMapper objectMapper) { + this.restClient = restClientBuilder.build(); this.geminiProperties = geminiProperties; + this.mcpClient = mcpClient; + this.objectMapper = objectMapper; } - @PostConstruct - public void init() { + /** + * Process user query with function calling support. + * + * @param userMessage User's question + * @return AI response + */ + public String chat(String userMessage) { try { - this.vertexAI = new VertexAI( - geminiProperties.projectId(), - geminiProperties.location() - ); - this.generativeModel = new GenerativeModel(geminiProperties.model(), vertexAI); - log.info("GeminiClient 초기화 완료: project={}, location={}, model={}", - geminiProperties.projectId(), - geminiProperties.location(), - geminiProperties.model() - ); + // 1. First call - may result in tool call + Map request = buildInitialRequest(userMessage); + String response = callGeminiApi(request); + + JsonNode responseNode = objectMapper.readTree(response); + + // 2. Check for function call + JsonNode functionCall = extractFunctionCall(responseNode); + if (functionCall != null) { + String toolName = functionCall.path("name").asText(); + JsonNode args = functionCall.path("args"); + + if ("query".equals(toolName) && args.has("sql")) { + String sql = args.get("sql").asText(); + log.debug("Executing SQL via MCP"); + + // 3. Execute query via MCP + String queryResult; + try { + queryResult = mcpClient.executeQuery(sql); + } catch (McpClient.McpQueryException e) { + queryResult = "쿼리 실행 오류: " + e.getMessage(); + } + + // 4. Send result back to Gemini + return callWithToolResult(userMessage, toolName, sql, queryResult); + } + } + + // No function call - return direct response + return extractTextResponse(responseNode); + } catch (Exception e) { - log.warn("GeminiClient 초기화 실패 (테스트 환경이거나 인증 정보 없음): {}", e.getMessage()); + log.error("Gemini API call failed", e); + return "죄송합니다. 요청을 처리하는 중 오류가 발생했습니다."; } } - @PreDestroy - public void destroy() { - if (vertexAI != null) { - try { - vertexAI.close(); - log.info("GeminiClient 리소스 해제 완료"); - } catch (Exception e) { - log.warn("GeminiClient 리소스 해제 중 오류", e); - } + private Map buildInitialRequest(String userMessage) { + Map request = new HashMap<>(); + + // System instruction + request.put("systemInstruction", Map.of( + "parts", List.of(Map.of("text", SYSTEM_PROMPT)) + )); + + // User message + request.put("contents", List.of( + Map.of("role", "user", "parts", List.of(Map.of("text", userMessage))) + )); + + // Tools (function declarations) + request.put("tools", List.of( + Map.of("functionDeclarations", List.of(QUERY_TOOL)) + )); + + // Generation config + request.put("generationConfig", Map.of( + "temperature", GENERATION_TEMPERATURE, + "maxOutputTokens", MAX_OUTPUT_TOKENS + )); + + return request; + } + + private String callWithToolResult(String userMessage, String toolName, String sql, String result) { + try { + Map request = new HashMap<>(); + + // System instruction + request.put("systemInstruction", Map.of( + "parts", List.of(Map.of("text", SYSTEM_PROMPT)) + )); + + // Conversation history with tool call and result + List> contents = new ArrayList<>(); + + // User message + contents.add(Map.of( + "role", "user", + "parts", List.of(Map.of("text", userMessage)) + )); + + // Model's function call + contents.add(Map.of( + "role", "model", + "parts", List.of(Map.of( + "functionCall", Map.of( + "name", toolName, + "args", Map.of("sql", sql) + ) + )) + )); + + // Function result + contents.add(Map.of( + "role", "user", + "parts", List.of(Map.of( + "functionResponse", Map.of( + "name", toolName, + "response", Map.of("result", result) + ) + )) + )); + + request.put("contents", contents); + + // Tools still available for potential multi-turn + request.put("tools", List.of( + Map.of("functionDeclarations", List.of(QUERY_TOOL)) + )); + + request.put("generationConfig", Map.of( + "temperature", GENERATION_TEMPERATURE, + "maxOutputTokens", MAX_OUTPUT_TOKENS + )); + + String response = callGeminiApi(request); + JsonNode responseNode = objectMapper.readTree(response); + + return extractTextResponse(responseNode); + + } catch (Exception e) { + log.error("Failed to process tool result", e); + return "쿼리 결과를 처리하는 중 오류가 발생했습니다."; } } - public String analyzeIntent(String userQuery) { - String prompt = String.format(INTENT_ANALYSIS_PROMPT, userQuery); - String result = callGemini(prompt); - if (result == null) { - return "UNKNOWN"; + private String callGeminiApi(Map request) { + String url = String.format(API_URL_TEMPLATE, geminiProperties.model()); + + try { + String response = restClient.post() + .uri(url) + .header(API_KEY_HEADER, geminiProperties.apiKey()) + .contentType(MediaType.APPLICATION_JSON) + .body(request) + .retrieve() + .body(String.class); + + return response; + + } catch (RestClientException e) { + log.error("Gemini API call failed"); + throw new GeminiException("Gemini API call failed", e); } - return result.trim().toUpperCase(); } - public String generateResponse(String userQuery, String data) { - String prompt = String.format(RESPONSE_GENERATION_PROMPT, userQuery, data); - String result = callGemini(prompt); - return result != null ? result : "응답을 생성할 수 없습니다."; + private JsonNode extractFunctionCall(JsonNode response) { + JsonNode candidates = response.path("candidates"); + if (candidates.isArray() && !candidates.isEmpty()) { + JsonNode content = candidates.get(0).path("content"); + JsonNode parts = content.path("parts"); + if (parts.isArray()) { + // Iterate through all parts to find functionCall + for (JsonNode part : parts) { + if (part.has("functionCall")) { + return part.get("functionCall"); + } + } + } + } + return null; } - private String callGemini(String prompt) { - if (generativeModel == null) { - log.error("GenerativeModel이 초기화되지 않았습니다."); - return null; + private String extractTextResponse(JsonNode response) { + JsonNode candidates = response.path("candidates"); + if (candidates.isArray() && !candidates.isEmpty()) { + JsonNode content = candidates.get(0).path("content"); + JsonNode parts = content.path("parts"); + if (parts.isArray()) { + // Combine all text parts + StringBuilder textBuilder = new StringBuilder(); + for (JsonNode part : parts) { + if (part.has("text")) { + textBuilder.append(part.get("text").asText()); + } + } + if (!textBuilder.isEmpty()) { + return textBuilder.toString(); + } + } } + return "응답을 생성할 수 없습니다."; + } - try { - GenerateContentResponse response = generativeModel.generateContent(prompt); - return ResponseHandler.getText(response); - } catch (IOException e) { - log.error("Gemini API 호출 실패", e); - return null; + public static class GeminiException extends RuntimeException { + public GeminiException(String message, Throwable cause) { + super(message, cause); } } } diff --git a/src/main/java/gg/agit/konect/infrastructure/gemini/config/GeminiProperties.java b/src/main/java/gg/agit/konect/infrastructure/gemini/config/GeminiProperties.java index 3cc553f8..5ccd3e47 100644 --- a/src/main/java/gg/agit/konect/infrastructure/gemini/config/GeminiProperties.java +++ b/src/main/java/gg/agit/konect/infrastructure/gemini/config/GeminiProperties.java @@ -4,8 +4,7 @@ @ConfigurationProperties(prefix = "gemini") public record GeminiProperties( - String projectId, - String location, + String apiKey, String model ) { diff --git a/src/main/java/gg/agit/konect/infrastructure/mcp/client/McpClient.java b/src/main/java/gg/agit/konect/infrastructure/mcp/client/McpClient.java new file mode 100644 index 00000000..5f0fe988 --- /dev/null +++ b/src/main/java/gg/agit/konect/infrastructure/mcp/client/McpClient.java @@ -0,0 +1,261 @@ +package gg.agit.konect.infrastructure.mcp.client; + +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.regex.Pattern; + +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestClient; +import org.springframework.web.client.RestClientException; +import org.springframework.web.util.UriComponentsBuilder; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import gg.agit.konect.infrastructure.mcp.config.McpProperties; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +public class McpClient { + + private static final List FORBIDDEN_PATTERNS = List.of( + Pattern.compile("\\bINSERT\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bUPDATE\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bDELETE\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bDROP\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bCREATE\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bALTER\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bTRUNCATE\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bGRANT\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bREVOKE\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bEXEC\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bEXECUTE\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bINTO\\s+OUTFILE\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile("\\bINTO\\s+DUMPFILE\\b", Pattern.CASE_INSENSITIVE), + Pattern.compile(";\\s*\\w", Pattern.CASE_INSENSITIVE) // Multiple statements + ); + + private static final Pattern VALID_TABLE_NAME = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); + + private final RestClient restClient; + private final McpProperties mcpProperties; + private final ObjectMapper objectMapper; + + public McpClient(RestClient.Builder restClientBuilder, + McpProperties mcpProperties, + ObjectMapper objectMapper) { + this.restClient = restClientBuilder.build(); + this.mcpProperties = mcpProperties; + this.objectMapper = objectMapper; + } + + /** + * Execute a SELECT query via MCP bridge server. + * + * @param sql SQL query (SELECT only) + * @return Query result as formatted string + * @throws McpQueryException if query fails or is not read-only + */ + public String executeQuery(String sql) { + validateReadOnly(sql); + + try { + String response = restClient.post() + .uri(mcpProperties.url() + "/query") + .contentType(MediaType.APPLICATION_JSON) + .body(Map.of("sql", sql)) + .retrieve() + .body(String.class); + + return formatQueryResult(response); + } catch (RestClientException e) { + log.error("MCP query execution failed"); + throw new McpQueryException("Failed to execute query", e); + } + } + + /** + * List all tables in the database. + * + * @return List of table names + */ + public List listTables() { + try { + String response = restClient.get() + .uri(mcpProperties.url() + "/tables") + .retrieve() + .body(String.class); + + return parseTableList(response); + } catch (RestClientException e) { + log.error("Failed to list tables"); + throw new McpQueryException("Failed to list tables", e); + } + } + + /** + * Get schema information for a specific table. + * + * @param tableName Name of the table + * @return Table schema as formatted string + */ + public String describeTable(String tableName) { + validateTableName(tableName); + + try { + String uri = UriComponentsBuilder + .fromHttpUrl(mcpProperties.url()) + .pathSegment("tables", tableName) + .build() + .toUriString(); + + String response = restClient.get() + .uri(uri) + .retrieve() + .body(String.class); + + return formatTableDescription(response); + } catch (RestClientException e) { + log.error("Failed to describe table"); + throw new McpQueryException("Failed to describe table", e); + } + } + + /** + * Check if MCP bridge server is healthy. + * + * @return true if healthy + */ + public boolean isHealthy() { + try { + String response = restClient.get() + .uri(mcpProperties.url() + "/health") + .retrieve() + .body(String.class); + + JsonNode node = objectMapper.readTree(response); + return "healthy".equals(node.path("status").asText()); + } catch (Exception e) { + log.warn("MCP health check failed"); + return false; + } + } + + private void validateReadOnly(String sql) { + if (sql == null || sql.isBlank()) { + throw new McpQueryException("SQL query cannot be empty"); + } + + String normalizedSql = sql.trim().toUpperCase(Locale.ROOT); + + // Must start with SELECT + if (!normalizedSql.startsWith("SELECT")) { + throw new McpQueryException("Only SELECT queries are allowed"); + } + + // Check for forbidden patterns using word boundary regex + for (Pattern pattern : FORBIDDEN_PATTERNS) { + if (pattern.matcher(sql).find()) { + throw new McpQueryException("Query contains forbidden pattern"); + } + } + } + + private void validateTableName(String tableName) { + if (tableName == null || tableName.isBlank()) { + throw new McpQueryException("Table name cannot be empty"); + } + + if (!VALID_TABLE_NAME.matcher(tableName).matches()) { + throw new McpQueryException("Invalid table name"); + } + } + + private String formatQueryResult(String response) { + try { + JsonNode root = objectMapper.readTree(response); + + // MCP tools/call response structure + JsonNode content = root.path("content"); + if (content.isArray() && !content.isEmpty()) { + JsonNode firstContent = content.get(0); + if (firstContent.has("text")) { + return firstContent.get("text").asText(); + } + } + + // Direct result + if (root.isArray()) { + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(root); + } + + return response; + } catch (JsonProcessingException e) { + log.warn("Failed to format query result, returning raw response"); + return response; + } + } + + private List parseTableList(String response) { + try { + JsonNode root = objectMapper.readTree(response); + + // Handle MCP response format + JsonNode content = root.path("content"); + if (content.isArray() && !content.isEmpty()) { + JsonNode firstContent = content.get(0); + if (firstContent.has("text")) { + String text = firstContent.get("text").asText(); + // Parse text as table list (assuming comma or newline separated) + return List.of(text.split("[,\\n]")).stream() + .map(String::trim) + .filter(s -> !s.isEmpty()) + .toList(); + } + } + + // Direct array response + if (root.isArray()) { + return objectMapper.convertValue(root, new TypeReference>() { }); + } + + return List.of(); + } catch (JsonProcessingException e) { + log.warn("Failed to parse table list"); + return List.of(); + } + } + + private String formatTableDescription(String response) { + try { + JsonNode root = objectMapper.readTree(response); + + JsonNode content = root.path("content"); + if (content.isArray() && !content.isEmpty()) { + JsonNode firstContent = content.get(0); + if (firstContent.has("text")) { + return firstContent.get("text").asText(); + } + } + + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(root); + } catch (JsonProcessingException e) { + return response; + } + } + + public static class McpQueryException extends RuntimeException { + public McpQueryException(String message) { + super(message); + } + + public McpQueryException(String message, Throwable cause) { + super(message, cause); + } + } +} diff --git a/src/main/java/gg/agit/konect/infrastructure/mcp/config/McpProperties.java b/src/main/java/gg/agit/konect/infrastructure/mcp/config/McpProperties.java new file mode 100644 index 00000000..93106ecf --- /dev/null +++ b/src/main/java/gg/agit/konect/infrastructure/mcp/config/McpProperties.java @@ -0,0 +1,13 @@ +package gg.agit.konect.infrastructure.mcp.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +import jakarta.validation.constraints.NotBlank; + +@ConfigurationProperties(prefix = "mcp") +public record McpProperties( + @NotBlank + String url +) { + +} diff --git a/src/main/java/gg/agit/konect/infrastructure/slack/ai/SlackAIService.java b/src/main/java/gg/agit/konect/infrastructure/slack/ai/SlackAIService.java index 9f997d3b..385fe354 100644 --- a/src/main/java/gg/agit/konect/infrastructure/slack/ai/SlackAIService.java +++ b/src/main/java/gg/agit/konect/infrastructure/slack/ai/SlackAIService.java @@ -19,10 +19,8 @@ public class SlackAIService { private static final Pattern AI_PREFIX_PATTERN = Pattern.compile("^[Aa][Ii]\\)\\s*(.+)$"); private static final Pattern MENTION_PATTERN = Pattern.compile("^<@[^>]+>\\s*"); - private static final String UNKNOWN = "UNKNOWN"; private final GeminiClient geminiClient; - private final StatisticsQueryExecutor queryExecutor; private final SlackClient slackClient; private final SlackProperties slackProperties; @@ -63,32 +61,14 @@ public void processAIQuery(String text) { return; } - log.debug("AI 질문 처리 시작"); + log.debug("AI 질문 처리 시작: {}", userQuery); - // 1. Gemini에게 의도 분석 요청 - String queryType = geminiClient.analyzeIntent(userQuery); - log.debug("분석된 쿼리 타입: {}", queryType); - - String response; - - // 2. 지원하지 않는 질문인 경우 - if (UNKNOWN.equals(queryType)) { - response = generateUnsupportedResponse(userQuery); - } else { - // 3. 안전한 통계 쿼리 실행 - String data = queryExecutor.execute(queryType); - - if (data == null) { - response = generateUnsupportedResponse(userQuery); - } else { - // 4. Gemini에게 자연어 응답 생성 요청 - response = geminiClient.generateResponse(userQuery, data); - } - } + // GeminiClient가 MCP를 통해 자동으로 SQL 결정 및 실행 + String response = geminiClient.chat(userQuery); log.debug("AI 응답 생성 완료"); - // 5. Slack에 응답 전송 + // Slack에 응답 전송 String slackMessage = formatSlackResponse(response); slackClient.sendMessage(slackMessage, slackProperties.webhooks().event()); @@ -99,14 +79,6 @@ public void processAIQuery(String text) { } } - private String generateUnsupportedResponse(String userQuery) { - return geminiClient.generateResponse( - userQuery, - "이 질문은 현재 지원하지 않는 유형입니다. " - + "사용자 수, 동아리 수, 모집 현황, 동아리원 수 등의 통계 질문을 해주세요." - ); - } - private String formatSlackResponse(String response) { return String.format(":robot_face: *AI 응답*\n%s", response); } diff --git a/src/main/java/gg/agit/konect/infrastructure/slack/ai/StatisticsQueryExecutor.java b/src/main/java/gg/agit/konect/infrastructure/slack/ai/StatisticsQueryExecutor.java deleted file mode 100644 index 941d5420..00000000 --- a/src/main/java/gg/agit/konect/infrastructure/slack/ai/StatisticsQueryExecutor.java +++ /dev/null @@ -1,53 +0,0 @@ -package gg.agit.konect.infrastructure.slack.ai; - -import org.springframework.stereotype.Component; - -import gg.agit.konect.domain.club.repository.ClubMemberRepository; -import gg.agit.konect.domain.club.repository.ClubRecruitmentRepository; -import gg.agit.konect.domain.club.repository.ClubRepository; -import gg.agit.konect.domain.user.repository.UserRepository; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Component -@RequiredArgsConstructor -public class StatisticsQueryExecutor { - - private final UserRepository userRepository; - private final ClubRepository clubRepository; - private final ClubRecruitmentRepository clubRecruitmentRepository; - private final ClubMemberRepository clubMemberRepository; - - public String execute(String queryType) { - log.debug("통계 쿼리 실행: queryType={}", queryType); - - return switch (queryType) { - case "USER_COUNT" -> executeUserCount(); - case "CLUB_COUNT" -> executeClubCount(); - case "CLUB_RECRUITING_COUNT" -> executeClubRecruitingCount(); - case "CLUB_MEMBER_TOTAL_COUNT" -> executeClubMemberTotalCount(); - default -> null; - }; - } - - private String executeUserCount() { - long count = userRepository.countActiveUsers(); - return String.format("현재 가입된 활성 사용자 수: %d명", count); - } - - private String executeClubCount() { - long count = clubRepository.countAll(); - return String.format("전체 동아리 수: %d개", count); - } - - private String executeClubRecruitingCount() { - long count = clubRecruitmentRepository.countCurrentlyRecruiting(); - return String.format("현재 모집 중인 동아리 수: %d개", count); - } - - private String executeClubMemberTotalCount() { - long count = clubMemberRepository.countAll(); - return String.format("전체 동아리원 수: %d명", count); - } -} diff --git a/src/main/resources/application-infrastructure.yml b/src/main/resources/application-infrastructure.yml index 310869bd..d2c4de53 100644 --- a/src/main/resources/application-infrastructure.yml +++ b/src/main/resources/application-infrastructure.yml @@ -14,6 +14,8 @@ slack: signing-secret: ${SLACK_SIGNING_SECRET} gemini: - project-id: ${GEMINI_PROJECT_ID} - location: ${GEMINI_LOCATION:us-central1} - model: ${GEMINI_MODEL:gemini-1.5-flash} + api-key: ${GEMINI_API_KEY} + model: ${GEMINI_MODEL:gemini-2.0-flash} + +mcp: + url: ${MCP_BRIDGE_URL:http://localhost:3100} diff --git a/src/test/java/gg/agit/konect/support/TestGeminiConfig.java b/src/test/java/gg/agit/konect/support/TestGeminiConfig.java index 474fb102..12d0cbcb 100644 --- a/src/test/java/gg/agit/konect/support/TestGeminiConfig.java +++ b/src/test/java/gg/agit/konect/support/TestGeminiConfig.java @@ -1,6 +1,5 @@ package gg.agit.konect.support; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -18,8 +17,7 @@ public class TestGeminiConfig { @Primary public GeminiClient geminiClient() { GeminiClient mockClient = mock(GeminiClient.class); - when(mockClient.analyzeIntent(anyString())).thenReturn("UNKNOWN"); - when(mockClient.generateResponse(anyString(), any())).thenReturn("테스트 응답입니다."); + when(mockClient.chat(anyString())).thenReturn("테스트 응답입니다."); return mockClient; } } diff --git a/src/test/java/gg/agit/konect/support/TestMcpConfig.java b/src/test/java/gg/agit/konect/support/TestMcpConfig.java new file mode 100644 index 00000000..07b6fbee --- /dev/null +++ b/src/test/java/gg/agit/konect/support/TestMcpConfig.java @@ -0,0 +1,28 @@ +package gg.agit.konect.support; + +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.List; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; + +import gg.agit.konect.infrastructure.mcp.client.McpClient; + +@TestConfiguration +public class TestMcpConfig { + + @Bean + @Primary + public McpClient mcpClient() { + McpClient mockClient = mock(McpClient.class); + when(mockClient.executeQuery(anyString())).thenReturn("테스트 쿼리 결과"); + when(mockClient.listTables()).thenReturn(List.of("users", "club", "club_member")); + when(mockClient.describeTable(anyString())).thenReturn("테스트 테이블 스키마"); + when(mockClient.isHealthy()).thenReturn(true); + return mockClient; + } +} diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 602aeddb..96be1cdf 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -123,9 +123,11 @@ slack: signing-secret: test-signing-secret gemini: - project-id: test-project - location: us-central1 - model: gemini-1.5-flash + api-key: test-api-key + model: gemini-2.0-flash + +mcp: + url: http://localhost:3100 logging: ignored-url-patterns: