@lovrabet/dataset-mcp-server 1.3.1-beta.1 → 1.3.1
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/README.md +12 -0
- package/dist/analyzer/dataset-analyzer.js +1 -1
- package/dist/api/cache.js +1 -1
- package/dist/api/dev-api-client.js +1 -1
- package/dist/auth/constants.js +1 -1
- package/dist/auth/cookie-manager.js +1 -1
- package/dist/auth/session-validator.js +1 -1
- package/dist/index.js +1 -1
- package/dist/server.js +1 -1
- package/dist/tools/execute-custom-sql.js +1 -1
- package/dist/tools/generate-sdk-code.js +1 -1
- package/dist/tools/generate-sql-code.js +1 -1
- package/dist/tools/get-dataset-detail.js +1 -1
- package/dist/tools/get-operation-detail.js +1 -1
- package/dist/tools/get-operations.js +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/list-datasets.js +1 -1
- package/dist/tools/list-sql-queries.js +1 -1
- package/dist/tools/login.js +1 -1
- package/dist/tools/save-custom-sql.js +1 -1
- package/dist/tools/save-or-update-custom-sql.js +1 -1
- package/dist/tools/search-datasets.js +1 -1
- package/dist/tools/validate-sql-content.js +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/mcp-types.js +1 -1
- package/dist/utils/sql-parser.js +1 -1
- package/package.json +1 -1
package/dist/types/mcp-types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
const a23_0x2ac05f=a23_0x1d9f;function a23_0x2110(){const _0x37ff28=['AUTH_REQUIRED','3277836iZkjiD','SQL_VALIDATION_FAILED','759670nEESpA','type','检查\x20SQL\x20语法,确保关键字拼写正确、括号匹配','login({\x20env:\x20\x22online\x22\x20})','PARAMETER_INVALID','类型不匹配','查看所有可用的数据集','list_datasets','get_dataset_detail({\x20datasetCode:\x20\x22customer\x22\x20})','tool','suggestions','129977aZejtz','1383165XZsbZS','PARAMETER_MISSING','获取数据集详情以确认表名和字段名','push','error','UNKNOWN_ERROR','length','<dataset-code>','description','18pynzBW','查看所有可用的\x20SQL\x20查询','status','6YIWehS','list_datasets({\x20pageSize:\x20999\x20})','10QwijRk','4204NucOyN','246QUuvgl','severity','使用\x20list_datasets\x20工具查看所有可用的数据集表名','字段不存在','TABLE_NOT_FOUND','fixSteps','NETWORK_ERROR','code','字段名歧义','86876snzGSx','canAutoFix','recoverable','SQL_NOT_FOUND','toISOString','response','缺少\x20WHERE\x20条件','表不存在','登录到\x20Lovrabet\x20平台','fixedSql','SQL_EXECUTION_FAILED','缺少必需参数:\x20','确保\x20SELECT\x20语句格式正确,如:\x20SELECT\x20id,\x20name\x20FROM\x20table\x20WHERE\x20status\x20=\x201','list_sql_queries','message','typeLabel','使用\x20get_dataset_detail\x20工具查看数据集的所有字段','SYNTAX_ERROR','DATASET_NOT_FOUND','536192XYmWsD','API_ERROR','location','login','suggestedAction','get_dataset_detail','22ZerbQe'];a23_0x2110=function(){return _0x37ff28;};return a23_0x2110();}(function(_0x1b4f40,_0x21dd7b){const _0x53dc57=a23_0x1d9f,_0x5120db=_0x1b4f40();while(!![]){try{const _0x2931c8=-parseInt(_0x53dc57(0x147))/0x1+-parseInt(_0x53dc57(0x115))/0x2*(parseInt(_0x53dc57(0x116))/0x3)+parseInt(_0x53dc57(0x11f))/0x4*(-parseInt(_0x53dc57(0x114))/0x5)+parseInt(_0x53dc57(0x112))/0x6*(parseInt(_0x53dc57(0x148))/0x7)+parseInt(_0x53dc57(0x132))/0x8*(parseInt(_0x53dc57(0x10f))/0x9)+parseInt(_0x53dc57(0x13c))/0xa*(-parseInt(_0x53dc57(0x138))/0xb)+parseInt(_0x53dc57(0x13a))/0xc;if(_0x2931c8===_0x21dd7b)break;else _0x5120db['push'](_0x5120db['shift']());}catch(_0x44d312){_0x5120db['push'](_0x5120db['shift']());}}}(a23_0x2110,0x1a24b));function a23_0x1d9f(_0x1777a2,_0x551cfd){_0x1777a2=_0x1777a2-0x10c;const _0x211031=a23_0x2110();let _0x1d9f31=_0x211031[_0x1777a2];return _0x1d9f31;}export const SQL_ERROR_TYPE_LABELS={'TABLE_NOT_FOUND':a23_0x2ac05f(0x126),'COLUMN_NOT_FOUND':a23_0x2ac05f(0x119),'AMBIGUOUS_COLUMN':a23_0x2ac05f(0x11e),'SYNTAX_ERROR':'语法错误','TYPE_MISMATCH':a23_0x2ac05f(0x141),'MISSING_WHERE_CLAUSE':a23_0x2ac05f(0x125),'UNSAFE_QUERY':'不安全的查询'};export function createError(_0x4b812a){const _0xab588e=a23_0x2ac05f;return{'error':!![],'code':_0x4b812a[_0xab588e(0x11d)],'message':_0x4b812a[_0xab588e(0x12d)],'status':_0x4b812a[_0xab588e(0x111)],'description':_0x4b812a['description'],'response':_0x4b812a[_0xab588e(0x124)],'suggestedAction':_0x4b812a[_0xab588e(0x136)],'recoverable':_0x4b812a[_0xab588e(0x121)]??!![],'timestamp':new Date()[_0xab588e(0x123)]()};}export function createAuthError(){const _0x8b0e04=a23_0x2ac05f;return createError({'code':'AUTH_REQUIRED','message':'需要登录才能访问\x20Lovrabet\x20数据。请先使用\x20login\x20工具进行登录。','suggestedAction':{'tool':_0x8b0e04(0x135),'description':_0x8b0e04(0x127),'example':_0x8b0e04(0x13f)},'recoverable':!![]});}export function createMissingParamError(_0x2f48ad,_0x206c39){const _0xdefa=a23_0x2ac05f;return createError({'code':_0xdefa(0x149),'message':_0xdefa(0x12a)+_0x2f48ad+(_0x206c39?'\x20('+_0x206c39+')':''),'recoverable':!![]});}export function createDatasetNotFoundError(_0x2a3beb){const _0x2adabc=a23_0x2ac05f;return createError({'code':_0x2adabc(0x131),'message':'数据集不存在:\x20'+_0x2a3beb,'suggestedAction':{'tool':'list_datasets','description':_0x2adabc(0x142),'example':_0x2adabc(0x113)},'recoverable':!![]});}export function createSqlNotFoundError(_0x151001){const _0x363df9=a23_0x2ac05f;return createError({'code':_0x363df9(0x122),'message':'SQL\x20不存在:\x20'+_0x151001,'suggestedAction':{'tool':_0x363df9(0x12c),'description':_0x363df9(0x110),'example':'list_sql_queries({\x20pageSize:\x20999\x20})'},'recoverable':!![]});}export function createSqlValidationError(_0x2f665a){const _0x1adfef=a23_0x2ac05f,_0x42f9d9=_0x2f665a[_0x1adfef(0x11b)][_0x1adfef(0x10c)]>0x0,_0x4dba0a=_0x42f9d9?_0x2f665a[_0x1adfef(0x11b)][0x0]:undefined,_0x3979d6={'type':_0x2f665a[_0x1adfef(0x13d)],'typeLabel':_0x2f665a[_0x1adfef(0x12e)],'location':_0x2f665a[_0x1adfef(0x134)],'severity':_0x2f665a['severity'],'fixSteps':_0x2f665a[_0x1adfef(0x11b)],'suggestions':_0x2f665a[_0x1adfef(0x146)],'canAutoFix':_0x2f665a[_0x1adfef(0x120)],'fixedSql':_0x2f665a[_0x1adfef(0x128)]};return createError({'code':_0x1adfef(0x13b),'message':_0x2f665a[_0x1adfef(0x12e)]+':\x20'+_0x2f665a[_0x1adfef(0x12d)],'status':_0x2f665a[_0x1adfef(0x111)],'description':_0x3979d6,'response':_0x2f665a['response'],'suggestedAction':_0x4dba0a?{'tool':_0x4dba0a[_0x1adfef(0x145)],'description':_0x4dba0a[_0x1adfef(0x10e)],'params':_0x4dba0a['toolParams'],'example':_0x4dba0a['example']}:{'tool':_0x1adfef(0x137),'description':_0x1adfef(0x14a),'params':{'datasetCode':_0x1adfef(0x10d)}},'recoverable':_0x2f665a[_0x1adfef(0x117)]!==_0x1adfef(0x14c)});}export function createStructuredSqlError(_0x43649d){const _0x5aac07=a23_0x2ac05f,_0x23307b=SQL_ERROR_TYPE_LABELS[_0x43649d['type']],_0x1a358d=_0x43649d[_0x5aac07(0x117)]??_0x5aac07(0x14c),_0x19e6b2=[];if(_0x43649d['type']===_0x5aac07(0x11a))_0x19e6b2[_0x5aac07(0x14b)]({'description':_0x5aac07(0x118),'tool':_0x5aac07(0x143),'toolParams':{'pageSize':0x3e7},'example':_0x5aac07(0x113)});else{if(_0x43649d[_0x5aac07(0x13d)]==='COLUMN_NOT_FOUND')_0x19e6b2['push']({'description':_0x5aac07(0x12f),'tool':_0x5aac07(0x137),'toolParams':{'datasetCode':'<dataset-code>'},'example':_0x5aac07(0x144)});else _0x43649d[_0x5aac07(0x13d)]===_0x5aac07(0x130)&&_0x19e6b2[_0x5aac07(0x14b)]({'description':_0x5aac07(0x13e),'example':_0x5aac07(0x12b)});}return{'type':_0x43649d[_0x5aac07(0x13d)],'typeLabel':_0x23307b,'location':_0x43649d[_0x5aac07(0x134)],'message':_0x43649d['message'],'severity':_0x1a358d,'fixSteps':_0x43649d[_0x5aac07(0x11b)]??_0x19e6b2,'suggestions':_0x43649d[_0x5aac07(0x146)],'canAutoFix':_0x43649d[_0x5aac07(0x120)],'fixedSql':_0x43649d[_0x5aac07(0x128)],'status':_0x43649d[_0x5aac07(0x111)],'response':_0x43649d[_0x5aac07(0x124)]};}export function fromLovrabetError(_0x5c036f,_0x2ce201){const _0xa99f3c=a23_0x2ac05f;return createError({'code':mapSdkCodeToMcpCode(_0x5c036f['code']),'message':_0x5c036f[_0xa99f3c(0x12d)],'status':_0x5c036f[_0xa99f3c(0x111)],'description':_0x5c036f[_0xa99f3c(0x10e)],'response':_0x5c036f[_0xa99f3c(0x124)],'suggestedAction':_0x2ce201,'recoverable':_0x5c036f[_0xa99f3c(0x111)]?_0x5c036f[_0xa99f3c(0x111)]<0x1f4:!![]});}function mapSdkCodeToMcpCode(_0x5d3385){const _0x3d7785=a23_0x2ac05f;if(!_0x5d3385)return'UNKNOWN_ERROR';const _0x16c171={'AUTH_REQUIRED':_0x3d7785(0x139),'AUTH_FAILED':_0x3d7785(0x139),'UNAUTHORIZED':_0x3d7785(0x139),'DATASET_NOT_FOUND':_0x3d7785(0x131),'NOT_FOUND':'DATASET_NOT_FOUND','INVALID_PARAMETER':_0x3d7785(0x140),'MISSING_PARAMETER':'PARAMETER_MISSING','SQL_ERROR':_0x3d7785(0x129),'NETWORK_ERROR':_0x3d7785(0x11c),'API_ERROR':_0x3d7785(0x133)};return _0x16c171[_0x5d3385]||_0x3d7785(0x14d);}
|
package/dist/utils/sql-parser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(_0x4e476e,_0x4e8297){const _0x45a414=a24_0x1d10,_0x1c44de=_0x4e476e();while(!![]){try{const _0x25b8c6=-parseInt(_0x45a414(0x1ac))/0x1+parseInt(_0x45a414(0x1c2))/0x2*(parseInt(_0x45a414(0x185))/0x3)+-parseInt(_0x45a414(0x1be))/0x4+parseInt(_0x45a414(0x1b3))/0x5*(parseInt(_0x45a414(0x18b))/0x6)+-parseInt(_0x45a414(0x1ad))/0x7*(parseInt(_0x45a414(0x1af))/0x8)+parseInt(_0x45a414(0x1a0))/0x9*(-parseInt(_0x45a414(0x1ca))/0xa)+-parseInt(_0x45a414(0x18c))/0xb*(-parseInt(_0x45a414(0x17d))/0xc);if(_0x25b8c6===_0x4e8297)break;else _0x1c44de['push'](_0x1c44de['shift']());}catch(_0x39ebc0){_0x1c44de['push'](_0x1c44de['shift']());}}}(a24_0x177e,0xe9b68));export function parseSqlStructure(_0x4810b8){const _0x3d9ad6=a24_0x1d10,_0x2f97b2={'tables':[],'columns':[],'parameters':[],'joins':[]};if(!_0x4810b8||typeof _0x4810b8!=='string')return _0x2f97b2;const _0xf1b182=_0x4810b8['replace'](/#\{[^}]*\}/g,'?')[_0x3d9ad6(0x1b1)](/\$\{[^}]*\}/g,'?')['replace'](/'[^']*'/g,'\x27\x27')['replace'](/--.*$/gm,'')[_0x3d9ad6(0x1b1)](/\/\*[\s\S]*?\*\//g,''),_0x4a1276=_0xf1b182[_0x3d9ad6(0x1c5)](/FROM\s+([^\s,)(]+)/i);if(_0x4a1276){const _0x3d29a9=_0x4a1276[0x1]['replace'](/[`"]/g,'');_0x2f97b2['tables'][_0x3d9ad6(0x17e)](_0x3d29a9);}const _0x3efa70=_0xf1b182['matchAll'](/(?:INNER|LEFT|RIGHT|FULL|CROSS)?\s*JOIN\s+([^\s,)(]+)/gi);for(const _0x43459c of _0x3efa70){const _0x20132b=_0x43459c[0x1][_0x3d9ad6(0x1b1)](/[`"]/g,'');_0x20132b&&!_0x2f97b2['tables'][_0x3d9ad6(0x187)](_0x20132b)&&_0x2f97b2[_0x3d9ad6(0x1a8)][_0x3d9ad6(0x17e)](_0x20132b);}const _0x41018f=_0xf1b182[_0x3d9ad6(0x1c5)](/SELECT\s+([\s\S]+?)\s+FROM/i);if(_0x41018f){const _0x1c9f9e=_0x41018f[0x1][_0x3d9ad6(0x1bc)]();if(_0x1c9f9e!=='*'){const _0x233e1a=splitSqlColumns(_0x1c9f9e);for(const _0x38f103 of _0x233e1a){const _0x1bf4f1=_0x38f103[_0x3d9ad6(0x1bc)]();if(_0x1bf4f1&&!_0x1bf4f1[_0x3d9ad6(0x1c5)](/^\d+$/)){const _0x462591=_0x1bf4f1['split'](/\s+AS\s+/i),_0x2511ab=_0x462591[0x0][_0x3d9ad6(0x1bc)](),_0x1c26cc=_0x462591[0x1]?.[_0x3d9ad6(0x1bc)]();if(_0x2511ab['includes']('.')){const [_0x46e59e,_0x4f7c43]=_0x2511ab[_0x3d9ad6(0x1b9)]('.');_0x2f97b2[_0x3d9ad6(0x17f)]['push']({'table':_0x46e59e[_0x3d9ad6(0x1bc)](),'column':_0x4f7c43[_0x3d9ad6(0x1b1)](/[`"]/g,'')['trim'](),'alias':_0x1c26cc});}else!_0x2511ab['includes']('(')&&_0x2f97b2[_0x3d9ad6(0x17f)][_0x3d9ad6(0x17e)]({'table':'','column':_0x2511ab[_0x3d9ad6(0x1b1)](/[`"]/g,''),'alias':_0x1c26cc});}}}}const _0x1069f5=_0xf1b182[_0x3d9ad6(0x180)](/JOIN\s+(\w+)\s+(?:AS\s+)?(\w+)?\s+ON\s+([\w.]+)\s*=\s*([\w.]+)/gi);for(const _0x451cc1 of _0x1069f5){const [,,,_0x5b50c9,_0x44f581]=_0x451cc1;if(_0x5b50c9&&_0x44f581){const [_0x2063a7,_0x4a1561]=_0x5b50c9['includes']('.')?_0x5b50c9[_0x3d9ad6(0x1b9)]('.'):['',_0x5b50c9],[_0x141276,_0x296aba]=_0x44f581[_0x3d9ad6(0x187)]('.')?_0x44f581['split']('.'):['',_0x44f581];_0x2f97b2['joins']?.['push']({'leftTable':_0x2063a7,'leftColumn':_0x4a1561,'rightTable':_0x141276,'rightColumn':_0x296aba});}}const _0x1aa31c=_0x4810b8[_0x3d9ad6(0x180)](/[#\$]\{(\w+)\}/g),_0x452089=new Set();for(const _0x5a241e of _0x1aa31c){const _0xa9fe08=_0x5a241e[0x1];!_0x452089[_0x3d9ad6(0x1a6)](_0xa9fe08)&&(_0x452089[_0x3d9ad6(0x1a4)](_0xa9fe08),_0x2f97b2['parameters'][_0x3d9ad6(0x17e)]({'name':_0xa9fe08,'type':inferParamType(_0xa9fe08),'example':getExampleValue(_0xa9fe08)}));}return _0x2f97b2;}function splitSqlColumns(_0x41db9a){const _0x5ef93d=a24_0x1d10,_0x423a00=[];let _0x2ccd22='',_0x41d214=0x0;for(let _0x280b8a=0x0;_0x280b8a<_0x41db9a[_0x5ef93d(0x1a3)];_0x280b8a++){const _0x288b4a=_0x41db9a[_0x280b8a];if(_0x288b4a==='(')_0x41d214++,_0x2ccd22+=_0x288b4a;else{if(_0x288b4a===')')_0x41d214--,_0x2ccd22+=_0x288b4a;else _0x288b4a===','&&_0x41d214===0x0?(_0x423a00[_0x5ef93d(0x17e)](_0x2ccd22),_0x2ccd22=''):_0x2ccd22+=_0x288b4a;}}return _0x2ccd22&&_0x423a00[_0x5ef93d(0x17e)](_0x2ccd22),_0x423a00;}function inferParamType(_0x12cfff){const _0x51812e=a24_0x1d10,_0x3565ee=_0x12cfff[_0x51812e(0x1c0)]();if(_0x3565ee[_0x51812e(0x187)]('id')||_0x3565ee[_0x51812e(0x187)]('count')||_0x3565ee[_0x51812e(0x187)]('limit')||_0x3565ee[_0x51812e(0x187)](_0x51812e(0x1ae))||_0x3565ee[_0x51812e(0x187)](_0x51812e(0x1ab))||_0x3565ee['includes'](_0x51812e(0x195))||_0x3565ee[_0x51812e(0x187)](_0x51812e(0x1a1))||_0x3565ee[_0x51812e(0x187)](_0x51812e(0x193)))return _0x51812e(0x19c);return _0x51812e(0x196);}function getExampleValue(_0x46132e){const _0x3c7912=a24_0x1d10,_0x59a2cd=_0x46132e[_0x3c7912(0x1c0)](),_0x45f161=inferParamType(_0x59a2cd);if(_0x45f161===_0x3c7912(0x19c)){if(_0x59a2cd[_0x3c7912(0x187)]('limit')||_0x59a2cd[_0x3c7912(0x187)]('count')||_0x59a2cd[_0x3c7912(0x187)]('size'))return 0xa;if(_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x1ab)))return 0x1;return 0x7b;}if(_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x1b5))||_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x182)))return _0x3c7912(0x1bf);if(_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x18a)))return'1';if(_0x59a2cd['includes'](_0x3c7912(0x18e))||_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x1b2))||_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x188)))return _0x3c7912(0x1ba);return _0x3c7912(0x1c6);}export function validateIsSelectOnly(_0x30b560){const _0x424e4b=a24_0x1d10;if(!_0x30b560||typeof _0x30b560!==_0x424e4b(0x196))return{'valid':![],'reason':_0x424e4b(0x192)};const _0x241801=_0x30b560[_0x424e4b(0x1b1)](/#\{[^}]*\}/g,'?')[_0x424e4b(0x1b1)](/\$\{[^}]*\}/g,'?')['replace'](/@[^(\s]+(\([^)]*\))?/g,''),_0x3577f5=_0x241801[_0x424e4b(0x1bc)](),_0x27d7ea=_0x3577f5['split']('\x0a');let _0x4056c4='';for(const _0x357252 of _0x27d7ea){const _0x2bb2b1=_0x357252['trim']();if(!_0x2bb2b1||_0x2bb2b1[_0x424e4b(0x191)]('--')||_0x2bb2b1['startsWith']('/*'))continue;_0x4056c4=_0x2bb2b1;break;}if(!_0x4056c4[_0x424e4b(0x189)]()[_0x424e4b(0x191)]('SELECT'))return{'valid':![],'reason':'Only\x20SELECT\x20queries\x20are\x20allowed.\x20The\x20SQL\x20must\x20start\x20with\x20SELECT\x20(after\x20any\x20comments).'};const _0x31d524=['INSERT\x5cs+INTO','UPDATE\x5cs+\x5cw+\x5cs+SET',_0x424e4b(0x1b7),_0x424e4b(0x1c9),_0x424e4b(0x1a2),_0x424e4b(0x186),'TRUNCATE',_0x424e4b(0x1a9),_0x424e4b(0x194),'EXEC',_0x424e4b(0x1a5)],_0x44e7aa=_0x3577f5[_0x424e4b(0x189)]();for(const _0x201be6 of _0x31d524){const _0x1e843d=new RegExp(_0x201be6,'i');if(_0x1e843d[_0x424e4b(0x19b)](_0x44e7aa))return{'valid':![],'reason':'Forbidden\x20keyword\x20detected:\x20'+_0x201be6[_0x424e4b(0x1b1)](_0x424e4b(0x1b8),'\x20')+_0x424e4b(0x1aa)};}return{'valid':!![]};}export function extractTableNames(_0x1f6c4e){const _0x214b2e=a24_0x1d10,_0x27a20f=parseSqlStructure(_0x1f6c4e);return _0x27a20f[_0x214b2e(0x1a8)];}export function extractColumnNames(_0x3ad3cf){const _0x4e2fc4=a24_0x1d10,_0x4a8c9e=parseSqlStructure(_0x3ad3cf);return _0x4a8c9e['columns'][_0x4e2fc4(0x1c3)](_0x2e5262=>({'table':_0x2e5262['table'],'column':_0x2e5262[_0x4e2fc4(0x190)]}));}export function extractParameters(_0x3505ad){const _0x4aba92=a24_0x1d10,_0x1593a4=parseSqlStructure(_0x3505ad);return _0x1593a4[_0x4aba92(0x184)];}function a24_0x1d10(_0x1932fb,_0x48bfff){_0x1932fb=_0x1932fb-0x17d;const _0x177e57=a24_0x177e();let _0x1d108f=_0x177e57[_0x1932fb];return _0x1d108f;}export function validateSqlContent(_0x3641d0,_0x4cd170){const _0x64a2d4=a24_0x1d10,_0x135e62=validateIsSelectOnly(_0x3641d0);if(!_0x135e62[_0x64a2d4(0x1a7)])return{'valid':![],'isSelectOnly':![],'errors':[{'type':_0x64a2d4(0x1bd),'location':'SQL_START','message':_0x135e62[_0x64a2d4(0x1c4)]||_0x64a2d4(0x197),'suggestion':_0x64a2d4(0x1b4)}]};const _0x4cb3aa=parseSqlStructure(_0x3641d0),_0x406620=[];if(_0x4cd170){const _0x4cd441=new Map(_0x4cd170[_0x64a2d4(0x1a8)][_0x64a2d4(0x1c3)](_0x1ea0d9=>[_0x1ea0d9[_0x64a2d4(0x1c7)][_0x64a2d4(0x1c0)](),_0x1ea0d9[_0x64a2d4(0x17f)][_0x64a2d4(0x1c3)](_0xe16045=>_0xe16045[_0x64a2d4(0x1c0)]())]));for(const _0x5dd1b4 of _0x4cb3aa[_0x64a2d4(0x1a8)]){const _0x134cbc=_0x5dd1b4[_0x64a2d4(0x1c0)]();!_0x4cd441[_0x64a2d4(0x1a6)](_0x134cbc)&&_0x406620[_0x64a2d4(0x17e)]({'type':_0x64a2d4(0x19a),'location':_0x5dd1b4,'message':_0x64a2d4(0x1c8)+_0x5dd1b4+_0x64a2d4(0x198),'suggestion':'Use\x20list_datasets\x20to\x20find\x20available\x20tables','suggestions':Array[_0x64a2d4(0x19d)](_0x4cd441['keys']())});}for(const _0x111e6a of _0x4cb3aa[_0x64a2d4(0x17f)]){if(_0x111e6a[_0x64a2d4(0x181)]){const _0x7a7014=_0x111e6a[_0x64a2d4(0x181)][_0x64a2d4(0x1c0)](),_0x5b46c5=_0x4cd441[_0x64a2d4(0x18d)](_0x7a7014);if(_0x5b46c5){const _0x3d5186=_0x111e6a[_0x64a2d4(0x190)]['toLowerCase']();!_0x5b46c5[_0x64a2d4(0x187)](_0x3d5186)&&!_0x111e6a[_0x64a2d4(0x190)][_0x64a2d4(0x187)]('*')&&_0x406620[_0x64a2d4(0x17e)]({'type':_0x64a2d4(0x1b6),'location':_0x111e6a['table']+'.'+_0x111e6a[_0x64a2d4(0x190)],'message':_0x64a2d4(0x183)+_0x111e6a[_0x64a2d4(0x190)]+'\x22\x20not\x20found\x20in\x20table\x20\x22'+_0x111e6a['table']+'\x22','suggestion':_0x64a2d4(0x19f),'suggestions':_0x5b46c5[_0x64a2d4(0x1b0)](_0x5a546a=>_0x5a546a[_0x64a2d4(0x187)](_0x111e6a['column'][_0x64a2d4(0x1c0)]())||_0x111e6a[_0x64a2d4(0x190)][_0x64a2d4(0x1c0)]()['includes'](_0x5a546a))});}}}}return{'valid':_0x406620[_0x64a2d4(0x1a3)]===0x0,'isSelectOnly':!![],'parsedStructure':_0x4cb3aa,'errors':_0x406620[_0x64a2d4(0x1a3)]>0x0?_0x406620:undefined};}function a24_0x177e(){const _0x3f44f7=['Invalid\x20SQL','\x22\x20not\x20found\x20in\x20database\x20schema','joins','TABLE_NOT_FOUND','test','number','from','join','Use\x20get_dataset_detail\x20to\x20see\x20available\x20columns','27RcQhes','amount','ALTER\x5cs+(TABLE|DATABASE)','length','add','EXECUTE','has','valid','tables','GRANT','.\x20Only\x20SELECT\x20queries\x20are\x20allowed.','page','786973kNwqXs','2624594cxUdZI','size','8iDAsBv','filter','replace','search','3245530ghOmgz','SQL\x20must\x20be\x20a\x20SELECT\x20statement','date','COLUMN_NOT_FOUND','DELETE\x5cs+FROM','\x5c\x5cs+','split','example','SELECT\x20query','trim','SYNTAX_ERROR','3978080qIvNsL','2024-01-01','toLowerCase','Joins:\x20','300676zgTESO','map','reason','match','value','tableName','Table\x20\x22','DROP\x5cs+(TABLE|INDEX|DATABASE)','2670950JWMARg','9444GPOXBx','push','columns','matchAll','table','time','Column\x20\x22','parameters','3xNFmxb','CREATE\x5cs+(TABLE|INDEX|DATABASE|VIEW)','includes','name','toUpperCase','status','12vGoPNf','34474zifsqR','get','keyword','\x20|\x20','column','startsWith','SQL\x20content\x20cannot\x20be\x20empty','price','REVOKE','num','string'];a24_0x177e=function(){return _0x3f44f7;};return a24_0x177e();}export function generateSqlSummary(_0x48f6f3){const _0xe564d2=a24_0x1d10,_0x2ee958=parseSqlStructure(_0x48f6f3),_0x246d84=[];return _0x2ee958['tables'][_0xe564d2(0x1a3)]>0x0&&_0x246d84['push']('Tables:\x20'+_0x2ee958[_0xe564d2(0x1a8)]['join'](',\x20')),_0x2ee958[_0xe564d2(0x184)]['length']>0x0&&_0x246d84[_0xe564d2(0x17e)]('Params:\x20'+_0x2ee958[_0xe564d2(0x184)]['map'](_0x711fb=>_0x711fb[_0xe564d2(0x188)])['join'](',\x20')),_0x2ee958[_0xe564d2(0x199)]&&_0x2ee958[_0xe564d2(0x199)]['length']>0x0&&_0x246d84['push'](_0xe564d2(0x1c1)+_0x2ee958[_0xe564d2(0x199)][_0xe564d2(0x1a3)]),_0x246d84[_0xe564d2(0x1a3)]>0x0?_0x246d84[_0xe564d2(0x19e)](_0xe564d2(0x18f)):_0xe564d2(0x1bb);}
|
|
1
|
+
(function(_0x455c10,_0x564ad9){const _0x2039b4=a24_0x4d32,_0x39f937=_0x455c10();while(!![]){try{const _0x541606=parseInt(_0x2039b4(0x1c3))/0x1+parseInt(_0x2039b4(0x1c8))/0x2+-parseInt(_0x2039b4(0x1d8))/0x3*(parseInt(_0x2039b4(0x1ce))/0x4)+parseInt(_0x2039b4(0x1de))/0x5+parseInt(_0x2039b4(0x1d2))/0x6+parseInt(_0x2039b4(0x1a2))/0x7*(parseInt(_0x2039b4(0x19f))/0x8)+-parseInt(_0x2039b4(0x1d3))/0x9;if(_0x541606===_0x564ad9)break;else _0x39f937['push'](_0x39f937['shift']());}catch(_0x37f007){_0x39f937['push'](_0x39f937['shift']());}}}(a24_0x1146,0x54788));import{createStructuredSqlError}from'../types/mcp-types.js';export function parseSqlStructure(_0x597296){const _0x54a672=a24_0x4d32,_0x111537={'tables':[],'columns':[],'parameters':[],'joins':[]};if(!_0x597296||typeof _0x597296!==_0x54a672(0x1ca))return _0x111537;const _0x5bc038=_0x597296['replace'](/#\{[^}]*\}/g,'?')['replace'](/\$\{[^}]*\}/g,'?')[_0x54a672(0x1c9)](/'[^']*'/g,'\x27\x27')[_0x54a672(0x1c9)](/--.*$/gm,'')[_0x54a672(0x1c9)](/\/\*[\s\S]*?\*\//g,''),_0x599cb7=_0x5bc038[_0x54a672(0x1bb)](/FROM\s+([^\s,)(]+)/i);if(_0x599cb7){const _0x3fb93c=_0x599cb7[0x1]['replace'](/[`"]/g,'');_0x111537[_0x54a672(0x1b1)][_0x54a672(0x1cb)](_0x3fb93c);}const _0x3774f3=_0x5bc038[_0x54a672(0x1bf)](/(?:INNER|LEFT|RIGHT|FULL|CROSS)?\s*JOIN\s+([^\s,)(]+)/gi);for(const _0x2c1c30 of _0x3774f3){const _0x3e5808=_0x2c1c30[0x1][_0x54a672(0x1c9)](/[`"]/g,'');_0x3e5808&&!_0x111537[_0x54a672(0x1b1)]['includes'](_0x3e5808)&&_0x111537[_0x54a672(0x1b1)][_0x54a672(0x1cb)](_0x3e5808);}const _0x11b8bd=_0x5bc038[_0x54a672(0x1bb)](/SELECT\s+([\s\S]+?)\s+FROM/i);if(_0x11b8bd){const _0x392d3a=_0x11b8bd[0x1][_0x54a672(0x1cd)]();if(_0x392d3a!=='*'){const _0x18c8c0=splitSqlColumns(_0x392d3a);for(const _0x5f03a of _0x18c8c0){const _0x4f6df3=_0x5f03a['trim']();if(_0x4f6df3&&!_0x4f6df3[_0x54a672(0x1bb)](/^\d+$/)){const _0x4d356f=_0x4f6df3[_0x54a672(0x1a7)](/\s+AS\s+/i),_0x1194ab=_0x4d356f[0x0][_0x54a672(0x1cd)](),_0x5c4c91=_0x4d356f[0x1]?.['trim']();if(_0x1194ab['includes']('.')){const [_0x579d0b,_0x3c8603]=_0x1194ab[_0x54a672(0x1a7)]('.');_0x111537[_0x54a672(0x1e0)][_0x54a672(0x1cb)]({'table':_0x579d0b[_0x54a672(0x1cd)](),'column':_0x3c8603['replace'](/[`"]/g,'')[_0x54a672(0x1cd)](),'alias':_0x5c4c91});}else!_0x1194ab[_0x54a672(0x1c6)]('(')&&_0x111537[_0x54a672(0x1e0)][_0x54a672(0x1cb)]({'table':'','column':_0x1194ab[_0x54a672(0x1c9)](/[`"]/g,''),'alias':_0x5c4c91});}}}}const _0x20a658=_0x5bc038[_0x54a672(0x1bf)](/JOIN\s+(\w+)\s+(?:AS\s+)?(\w+)?\s+ON\s+([\w.]+)\s*=\s*([\w.]+)/gi);for(const _0x355274 of _0x20a658){const [,,,_0x1df071,_0x1ef1e8]=_0x355274;if(_0x1df071&&_0x1ef1e8){const [_0xa20428,_0x560d7f]=_0x1df071[_0x54a672(0x1c6)]('.')?_0x1df071[_0x54a672(0x1a7)]('.'):['',_0x1df071],[_0x152f8a,_0x27da2a]=_0x1ef1e8[_0x54a672(0x1c6)]('.')?_0x1ef1e8[_0x54a672(0x1a7)]('.'):['',_0x1ef1e8];_0x111537['joins']?.[_0x54a672(0x1cb)]({'leftTable':_0xa20428,'leftColumn':_0x560d7f,'rightTable':_0x152f8a,'rightColumn':_0x27da2a});}}const _0x5799c9=_0x597296[_0x54a672(0x1bf)](/[#\$]\{(\w+)\}/g),_0xcb51b3=new Set();for(const _0x485127 of _0x5799c9){const _0x356648=_0x485127[0x1];!_0xcb51b3[_0x54a672(0x1d9)](_0x356648)&&(_0xcb51b3[_0x54a672(0x1d7)](_0x356648),_0x111537[_0x54a672(0x1dc)][_0x54a672(0x1cb)]({'name':_0x356648,'type':inferParamType(_0x356648),'example':getExampleValue(_0x356648)}));}return _0x111537;}function splitSqlColumns(_0x326889){const _0x5b4c76=a24_0x4d32,_0x1cb059=[];let _0x5c2450='',_0x2bcbf7=0x0;for(let _0x3e63b5=0x0;_0x3e63b5<_0x326889['length'];_0x3e63b5++){const _0x2780e0=_0x326889[_0x3e63b5];if(_0x2780e0==='(')_0x2bcbf7++,_0x5c2450+=_0x2780e0;else{if(_0x2780e0===')')_0x2bcbf7--,_0x5c2450+=_0x2780e0;else _0x2780e0===','&&_0x2bcbf7===0x0?(_0x1cb059['push'](_0x5c2450),_0x5c2450=''):_0x5c2450+=_0x2780e0;}}return _0x5c2450&&_0x1cb059[_0x5b4c76(0x1cb)](_0x5c2450),_0x1cb059;}function inferParamType(_0x31a86b){const _0x28c3aa=a24_0x4d32,_0xd42c0=_0x31a86b[_0x28c3aa(0x19a)]();if(_0xd42c0[_0x28c3aa(0x1c6)]('id')||_0xd42c0[_0x28c3aa(0x1c6)](_0x28c3aa(0x199))||_0xd42c0[_0x28c3aa(0x1c6)](_0x28c3aa(0x1df))||_0xd42c0[_0x28c3aa(0x1c6)]('size')||_0xd42c0['includes'](_0x28c3aa(0x1a8))||_0xd42c0[_0x28c3aa(0x1c6)](_0x28c3aa(0x1ac))||_0xd42c0[_0x28c3aa(0x1c6)](_0x28c3aa(0x1af))||_0xd42c0[_0x28c3aa(0x1c6)](_0x28c3aa(0x1c7)))return _0x28c3aa(0x1a4);return'string';}function a24_0x4d32(_0x36de73,_0x189674){_0x36de73=_0x36de73-0x197;const _0x1146d0=a24_0x1146();let _0x4d32ba=_0x1146d0[_0x36de73];return _0x4d32ba;}function getExampleValue(_0x35f682){const _0xebc0bc=a24_0x4d32,_0xf1cefd=_0x35f682[_0xebc0bc(0x19a)](),_0x1f95f5=inferParamType(_0xf1cefd);if(_0x1f95f5===_0xebc0bc(0x1a4)){if(_0xf1cefd[_0xebc0bc(0x1c6)]('limit')||_0xf1cefd[_0xebc0bc(0x1c6)](_0xebc0bc(0x199))||_0xf1cefd[_0xebc0bc(0x1c6)]('size'))return 0xa;if(_0xf1cefd[_0xebc0bc(0x1c6)]('page'))return 0x1;return 0x7b;}if(_0xf1cefd[_0xebc0bc(0x1c6)]('date')||_0xf1cefd[_0xebc0bc(0x1c6)](_0xebc0bc(0x1ab)))return'2024-01-01';if(_0xf1cefd[_0xebc0bc(0x1c6)](_0xebc0bc(0x1b9)))return'1';if(_0xf1cefd[_0xebc0bc(0x1c6)]('keyword')||_0xf1cefd[_0xebc0bc(0x1c6)](_0xebc0bc(0x1b2))||_0xf1cefd[_0xebc0bc(0x1c6)](_0xebc0bc(0x198)))return _0xebc0bc(0x1cf);return _0xebc0bc(0x1b5);}export function validateIsSelectOnly(_0x13f754){const _0x2ab1bf=a24_0x4d32;if(!_0x13f754||typeof _0x13f754!==_0x2ab1bf(0x1ca))return{'valid':![],'reason':_0x2ab1bf(0x1c2)};const _0x5df056=_0x13f754[_0x2ab1bf(0x1c9)](/#\{[^}]*\}/g,'?')[_0x2ab1bf(0x1c9)](/\$\{[^}]*\}/g,'?')[_0x2ab1bf(0x1c9)](/@[^(\s]+(\([^)]*\))?/g,''),_0x3789f3=_0x5df056['trim'](),_0x557075=_0x3789f3['split']('\x0a');let _0xbbc22='';for(const _0x9878e4 of _0x557075){const _0x33b6a6=_0x9878e4[_0x2ab1bf(0x1cd)]();if(!_0x33b6a6||_0x33b6a6[_0x2ab1bf(0x1b6)]('--')||_0x33b6a6['startsWith']('/*'))continue;_0xbbc22=_0x33b6a6;break;}if(!_0xbbc22[_0x2ab1bf(0x1c5)]()[_0x2ab1bf(0x1b6)]('SELECT'))return{'valid':![],'reason':'Only\x20SELECT\x20queries\x20are\x20allowed.\x20The\x20SQL\x20must\x20start\x20with\x20SELECT\x20(after\x20any\x20comments).'};const _0x5a3536=[_0x2ab1bf(0x1d5),_0x2ab1bf(0x1b3),_0x2ab1bf(0x1bd),'DROP\x5cs+(TABLE|INDEX|DATABASE)',_0x2ab1bf(0x1d0),_0x2ab1bf(0x1a6),_0x2ab1bf(0x1dd),'GRANT',_0x2ab1bf(0x1aa),'EXEC','EXECUTE'],_0xb7fb99=_0x3789f3[_0x2ab1bf(0x1c5)]();for(const _0x3447f3 of _0x5a3536){const _0x3c4a44=new RegExp(_0x3447f3,'i');if(_0x3c4a44[_0x2ab1bf(0x1a3)](_0xb7fb99))return{'valid':![],'reason':'Forbidden\x20keyword\x20detected:\x20'+_0x3447f3[_0x2ab1bf(0x1c9)](_0x2ab1bf(0x1a9),'\x20')+_0x2ab1bf(0x1b0)};}return{'valid':!![]};}function a24_0x1146(){const _0x204d81=['tableName','amount','.\x20Only\x20SELECT\x20queries\x20are\x20allowed.','tables','search','UPDATE\x5cs+\x5cw+\x5cs+SET','error','value','startsWith','table','get','status','SQL\x20必须以\x20SELECT\x20开头','match','\x20|\x20','DELETE\x5cs+FROM','column','matchAll','\x22\x20中不存在','\x22\x20在表\x20\x22','SQL\x20content\x20cannot\x20be\x20empty','47017LzcRiV','reason','toUpperCase','includes','price','415744TDwzAe','replace','string','push','Params:\x20','trim','8WyvbFa','example','ALTER\x5cs+(TABLE|DATABASE)','filter','1993968nLpDFs','2915955omSdGM','joins','INSERT\x5cs+INTO','TABLE_NOT_FOUND','add','461019QASzlf','has','字段\x20\x22','length','parameters','TRUNCATE','1534495YDChhp','limit','columns','map','确保\x20SQL\x20语句以\x20SELECT\x20关键字开头','name','count','toLowerCase','join','keys','slice','\x22\x20在数据库\x20schema\x20中不存在','221912AAnhnh','Joins:\x20','表\x20\x22','21ryYqRv','test','number','SYNTAX_ERROR','CREATE\x5cs+(TABLE|INDEX|DATABASE|VIEW)','split','page','\x5c\x5cs+','REVOKE','time','num','from'];a24_0x1146=function(){return _0x204d81;};return a24_0x1146();}export function extractTableNames(_0x3a262e){const _0x3784d1=parseSqlStructure(_0x3a262e);return _0x3784d1['tables'];}export function extractColumnNames(_0x5885bd){const _0x1b2c38=a24_0x4d32,_0x226470=parseSqlStructure(_0x5885bd);return _0x226470['columns']['map'](_0x35ca17=>({'table':_0x35ca17[_0x1b2c38(0x1b7)],'column':_0x35ca17[_0x1b2c38(0x1be)]}));}export function extractParameters(_0x4b576a){const _0x7fed95=a24_0x4d32,_0x50f9c1=parseSqlStructure(_0x4b576a);return _0x50f9c1[_0x7fed95(0x1dc)];}export function validateSqlContent(_0x23af3f,_0x33e1a7){const _0xd8e928=a24_0x4d32,_0x7d56b7=validateIsSelectOnly(_0x23af3f);if(!_0x7d56b7['valid'])return{'valid':![],'isSelectOnly':![],'errors':[createStructuredSqlError({'type':_0xd8e928(0x1a5),'location':'SQL_START','message':_0x7d56b7[_0xd8e928(0x1c4)]||_0xd8e928(0x1ba),'severity':_0xd8e928(0x1b4),'fixSteps':[{'description':_0xd8e928(0x197),'example':'SELECT\x20id,\x20name\x20FROM\x20customer\x20WHERE\x20status\x20=\x201'}]})]};const _0x42a834=parseSqlStructure(_0x23af3f),_0x10e56c=[];if(_0x33e1a7){const _0x5c593d=new Map(_0x33e1a7[_0xd8e928(0x1b1)][_0xd8e928(0x1e1)](_0x1216ec=>[_0x1216ec[_0xd8e928(0x1ae)][_0xd8e928(0x19a)](),_0x1216ec[_0xd8e928(0x1e0)][_0xd8e928(0x1e1)](_0x176eda=>_0x176eda[_0xd8e928(0x19a)]())]));for(const _0x3a1ec6 of _0x42a834[_0xd8e928(0x1b1)]){const _0x4b2560=_0x3a1ec6['toLowerCase']();if(!_0x5c593d[_0xd8e928(0x1d9)](_0x4b2560)){const _0x3bfaad=Array['from'](_0x5c593d['keys']())[_0xd8e928(0x1d1)](_0x57da15=>_0x57da15[_0xd8e928(0x1c6)](_0x4b2560)||_0x4b2560[_0xd8e928(0x1c6)](_0x57da15));_0x10e56c[_0xd8e928(0x1cb)](createStructuredSqlError({'type':_0xd8e928(0x1d6),'location':_0x3a1ec6,'message':_0xd8e928(0x1a1)+_0x3a1ec6+_0xd8e928(0x19e),'severity':'error','suggestions':_0x3bfaad['length']>0x0?_0x3bfaad:Array[_0xd8e928(0x1ad)](_0x5c593d[_0xd8e928(0x19c)]())}));}}for(const _0x70e66d of _0x42a834[_0xd8e928(0x1e0)]){if(_0x70e66d[_0xd8e928(0x1b7)]){const _0x46995e=_0x70e66d[_0xd8e928(0x1b7)][_0xd8e928(0x19a)](),_0x11d9c5=_0x5c593d[_0xd8e928(0x1b8)](_0x46995e);if(_0x11d9c5){const _0x1bd284=_0x70e66d[_0xd8e928(0x1be)][_0xd8e928(0x19a)]();if(!_0x11d9c5[_0xd8e928(0x1c6)](_0x1bd284)&&!_0x70e66d['column'][_0xd8e928(0x1c6)]('*')){const _0x3adfc3=_0x11d9c5[_0xd8e928(0x1d1)](_0x5c7eac=>_0x5c7eac[_0xd8e928(0x1c6)](_0x1bd284)||_0x1bd284['includes'](_0x5c7eac));_0x10e56c[_0xd8e928(0x1cb)](createStructuredSqlError({'type':'COLUMN_NOT_FOUND','location':_0x70e66d[_0xd8e928(0x1b7)]+'.'+_0x70e66d['column'],'message':_0xd8e928(0x1da)+_0x70e66d['column']+_0xd8e928(0x1c1)+_0x70e66d['table']+_0xd8e928(0x1c0),'severity':_0xd8e928(0x1b4),'suggestions':_0x3adfc3['length']>0x0?_0x3adfc3:_0x11d9c5[_0xd8e928(0x19d)](0x0,0xa)}));}}}}}return{'valid':_0x10e56c[_0xd8e928(0x1db)]===0x0,'isSelectOnly':!![],'parsedStructure':_0x42a834,'errors':_0x10e56c['length']>0x0?_0x10e56c:undefined};}export function generateSqlSummary(_0x1cce22){const _0xf1504c=a24_0x4d32,_0x1cfa98=parseSqlStructure(_0x1cce22),_0x5d9e38=[];return _0x1cfa98['tables'][_0xf1504c(0x1db)]>0x0&&_0x5d9e38[_0xf1504c(0x1cb)]('Tables:\x20'+_0x1cfa98[_0xf1504c(0x1b1)][_0xf1504c(0x19b)](',\x20')),_0x1cfa98[_0xf1504c(0x1dc)][_0xf1504c(0x1db)]>0x0&&_0x5d9e38[_0xf1504c(0x1cb)](_0xf1504c(0x1cc)+_0x1cfa98[_0xf1504c(0x1dc)][_0xf1504c(0x1e1)](_0x4cfe2a=>_0x4cfe2a[_0xf1504c(0x198)])[_0xf1504c(0x19b)](',\x20')),_0x1cfa98['joins']&&_0x1cfa98[_0xf1504c(0x1d4)][_0xf1504c(0x1db)]>0x0&&_0x5d9e38[_0xf1504c(0x1cb)](_0xf1504c(0x1a0)+_0x1cfa98[_0xf1504c(0x1d4)][_0xf1504c(0x1db)]),_0x5d9e38['length']>0x0?_0x5d9e38[_0xf1504c(0x19b)](_0xf1504c(0x1bc)):'SELECT\x20query';}
|