plugin-elastic-report 0.0.0-stage → 0.1.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/ai/skills/elastic-report/SKILLS.md +32 -0
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/851.488fdbf5bc5b6a36.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +20 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +99 -0
- package/dist/locale/vi-VN.json +99 -0
- package/dist/locale/zh-CN.json +99 -0
- package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
- package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
- package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
- package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
- package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
- package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
- package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
- package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
- package/dist/server/acl-guard.js +107 -0
- package/dist/server/collections/es-report-data-views.js +79 -0
- package/dist/server/collections/es-reports.js +95 -0
- package/dist/server/index.js +58 -0
- package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
- package/dist/server/mcp/ElasticReportToolCatalog.js +417 -0
- package/dist/server/plugin.js +395 -0
- package/dist/server/services/ElasticReportService.js +263 -0
- package/dist/server/services/ElasticsearchConnectionService.js +332 -0
- package/dist/server/services/ReportQueryCompiler.js +858 -0
- package/dist/shared/constants.js +81 -0
- package/dist/shared/types.js +24 -0
- package/package.json +61 -4
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/index.tsx +19 -0
- package/src/client-v2/__tests__/elastic-report.test.tsx +311 -0
- package/src/client-v2/api.ts +224 -0
- package/src/client-v2/components/ElasticBasicCharts.tsx +399 -0
- package/src/client-v2/components/ElasticReportBlock.tsx +160 -0
- package/src/client-v2/components/ElasticReportRenderer.tsx +707 -0
- package/src/client-v2/components/HighlightText.tsx +50 -0
- package/src/client-v2/components/ReportSelect.tsx +72 -0
- package/src/client-v2/index.tsx +14 -0
- package/src/client-v2/locale.ts +23 -0
- package/src/client-v2/models/ElasticReportBlockModel.tsx +85 -0
- package/src/client-v2/pages/ElasticReportManager.tsx +1047 -0
- package/src/client-v2/plugin.tsx +52 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +99 -0
- package/src/locale/vi-VN.json +99 -0
- package/src/locale/zh-CN.json +99 -0
- package/src/server/__tests__/query-compiler.test.ts +231 -0
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +377 -0
- package/src/server/acl-guard.ts +103 -0
- package/src/server/collections/es-report-data-views.ts +58 -0
- package/src/server/collections/es-reports.ts +74 -0
- package/src/server/index.ts +15 -0
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
- package/src/server/mcp/ElasticReportToolCatalog.ts +417 -0
- package/src/server/plugin.ts +431 -0
- package/src/server/services/ElasticReportService.ts +326 -0
- package/src/server/services/ElasticsearchConnectionService.ts +401 -0
- package/src/server/services/ReportQueryCompiler.ts +1017 -0
- package/src/shared/constants.ts +29 -0
- package/src/shared/types.ts +175 -0
- package/README.md +0 -3
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Context } from '@nocobase/actions';
|
|
11
|
+
import { MCP_SERVER_NAME } from '../../shared/constants';
|
|
12
|
+
import type { ElasticReportToolDefinition } from './ElasticReportToolCatalog';
|
|
13
|
+
|
|
14
|
+
interface JsonRpcRequest {
|
|
15
|
+
jsonrpc?: string;
|
|
16
|
+
id?: string | number | null;
|
|
17
|
+
method?: string;
|
|
18
|
+
params?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface JsonRpcResponse {
|
|
22
|
+
jsonrpc: '2.0';
|
|
23
|
+
id: string | number | null;
|
|
24
|
+
result?: unknown;
|
|
25
|
+
error?: {
|
|
26
|
+
code: number;
|
|
27
|
+
message: string;
|
|
28
|
+
data?: unknown;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface McpSdkModules {
|
|
33
|
+
McpServer: new (
|
|
34
|
+
serverInfo: { name: string; version: string },
|
|
35
|
+
options: { capabilities: { tools: Record<string, never> } },
|
|
36
|
+
) => {
|
|
37
|
+
server: {
|
|
38
|
+
setRequestHandler: (
|
|
39
|
+
schema: unknown,
|
|
40
|
+
handler: (request: { params: Record<string, unknown> }) => Promise<unknown>,
|
|
41
|
+
) => void;
|
|
42
|
+
};
|
|
43
|
+
connect: (transport: unknown) => Promise<void>;
|
|
44
|
+
close: () => Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
StreamableHTTPServerTransport: new (options: { sessionIdGenerator?: undefined }) => {
|
|
47
|
+
onerror?: (err: unknown) => void;
|
|
48
|
+
handleRequest: (req: unknown, res: unknown, body: unknown) => Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
CallToolRequestSchema: unknown;
|
|
51
|
+
ListToolsRequestSchema: unknown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let sdkModulesPromise: Promise<McpSdkModules | null> | null = null;
|
|
55
|
+
|
|
56
|
+
function loadOptionalMcpSdk(): Promise<McpSdkModules | null> {
|
|
57
|
+
if (!sdkModulesPromise) {
|
|
58
|
+
sdkModulesPromise = Promise.all([
|
|
59
|
+
import('@modelcontextprotocol/sdk/server/mcp.js'),
|
|
60
|
+
import('@modelcontextprotocol/sdk/server/streamableHttp.js'),
|
|
61
|
+
import('@modelcontextprotocol/sdk/types.js'),
|
|
62
|
+
])
|
|
63
|
+
.then(([mcpMod, httpMod, typesMod]) => ({
|
|
64
|
+
McpServer: mcpMod.McpServer as unknown as McpSdkModules['McpServer'],
|
|
65
|
+
StreamableHTTPServerTransport:
|
|
66
|
+
httpMod.StreamableHTTPServerTransport as unknown as McpSdkModules['StreamableHTTPServerTransport'],
|
|
67
|
+
CallToolRequestSchema: typesMod.CallToolRequestSchema,
|
|
68
|
+
ListToolsRequestSchema: typesMod.ListToolsRequestSchema,
|
|
69
|
+
}))
|
|
70
|
+
.catch(() => null);
|
|
71
|
+
}
|
|
72
|
+
return sdkModulesPromise;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
76
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function serializeToolResult(value: unknown): string {
|
|
80
|
+
if (typeof value === 'string') return value;
|
|
81
|
+
try {
|
|
82
|
+
return JSON.stringify(value, null, 2);
|
|
83
|
+
} catch {
|
|
84
|
+
return String(value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class ElasticReportMcpServer {
|
|
89
|
+
private readonly toolMap: Map<string, ElasticReportToolDefinition>;
|
|
90
|
+
|
|
91
|
+
constructor(
|
|
92
|
+
private readonly options: {
|
|
93
|
+
version: string;
|
|
94
|
+
tools: ElasticReportToolDefinition[];
|
|
95
|
+
logger?: { error?: (...args: unknown[]) => void };
|
|
96
|
+
},
|
|
97
|
+
) {
|
|
98
|
+
this.toolMap = new Map(options.tools.map((tool) => [tool.name, tool]));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getToolsMetadata() {
|
|
102
|
+
return this.options.tools.map((tool) => ({
|
|
103
|
+
name: tool.name,
|
|
104
|
+
description: tool.description,
|
|
105
|
+
inputSchema: tool.inputSchema,
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async handleRequest(ctx: Context): Promise<void> {
|
|
110
|
+
const method = (ctx.method || 'POST').toUpperCase();
|
|
111
|
+
|
|
112
|
+
if (method === 'GET') {
|
|
113
|
+
const accept = String(ctx.request?.headers?.accept || '');
|
|
114
|
+
if (accept.includes('text/event-stream')) {
|
|
115
|
+
// Stateless Streamable HTTP MCP servers return 405 on standalone SSE GET streams per MCP spec.
|
|
116
|
+
ctx.withoutDataWrapping = true;
|
|
117
|
+
ctx.status = 405;
|
|
118
|
+
ctx.set('Allow', 'POST');
|
|
119
|
+
ctx.body = {
|
|
120
|
+
jsonrpc: '2.0',
|
|
121
|
+
error: { code: -32000, message: 'Method not allowed: stateless Streamable HTTP MCP endpoint' },
|
|
122
|
+
id: null,
|
|
123
|
+
};
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
ctx.withoutDataWrapping = true;
|
|
127
|
+
ctx.status = 200;
|
|
128
|
+
ctx.type = 'application/json';
|
|
129
|
+
ctx.body = {
|
|
130
|
+
name: MCP_SERVER_NAME,
|
|
131
|
+
version: this.options.version,
|
|
132
|
+
protocol: 'mcp-streamable-http',
|
|
133
|
+
tools: this.getToolsMetadata(),
|
|
134
|
+
};
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (method !== 'POST') {
|
|
139
|
+
ctx.withoutDataWrapping = true;
|
|
140
|
+
ctx.status = 405;
|
|
141
|
+
ctx.set('Allow', 'GET, POST');
|
|
142
|
+
ctx.body = {
|
|
143
|
+
jsonrpc: '2.0',
|
|
144
|
+
error: { code: -32000, message: `Unsupported HTTP method: ${method}` },
|
|
145
|
+
id: null,
|
|
146
|
+
};
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const accept = String(ctx.request?.headers?.accept || '');
|
|
151
|
+
const prefersEventStream = accept.includes('text/event-stream') && accept.includes('application/json');
|
|
152
|
+
|
|
153
|
+
if (prefersEventStream) {
|
|
154
|
+
const sdk = await loadOptionalMcpSdk();
|
|
155
|
+
if (sdk && ctx.req && ctx.res && typeof ctx.res.writeHead === 'function') {
|
|
156
|
+
await this.handleWithSdk(sdk, ctx);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await this.handleStatelessJsonRpc(ctx);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private async handleWithSdk(sdk: McpSdkModules, ctx: Context): Promise<void> {
|
|
165
|
+
const server = new sdk.McpServer(
|
|
166
|
+
{ name: MCP_SERVER_NAME, version: this.options.version },
|
|
167
|
+
{ capabilities: { tools: {} } },
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
server.server.setRequestHandler(sdk.ListToolsRequestSchema, async () => ({
|
|
171
|
+
tools: this.getToolsMetadata(),
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
server.server.setRequestHandler(sdk.CallToolRequestSchema, async (request) => {
|
|
175
|
+
const toolName = typeof request.params?.name === 'string' ? request.params.name : '';
|
|
176
|
+
const rawArgs = isRecord(request.params?.arguments) ? request.params.arguments : {};
|
|
177
|
+
const tool = this.toolMap.get(toolName);
|
|
178
|
+
if (!tool) {
|
|
179
|
+
return {
|
|
180
|
+
content: [{ type: 'text', text: `Unknown tool: ${toolName}` }],
|
|
181
|
+
isError: true,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const output = await tool.execute(rawArgs, ctx);
|
|
186
|
+
return {
|
|
187
|
+
content: [{ type: 'text', text: serializeToolResult(output) }],
|
|
188
|
+
isError: false,
|
|
189
|
+
};
|
|
190
|
+
} catch (error) {
|
|
191
|
+
return {
|
|
192
|
+
content: [{ type: 'text', text: error instanceof Error ? error.message : String(error) }],
|
|
193
|
+
isError: true,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const transport = new sdk.StreamableHTTPServerTransport({
|
|
199
|
+
sessionIdGenerator: undefined,
|
|
200
|
+
});
|
|
201
|
+
transport.onerror = (err) => {
|
|
202
|
+
this.options.logger?.error?.('[plugin-elastic-report] MCP transport error:', err);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
await server.connect(transport);
|
|
206
|
+
try {
|
|
207
|
+
await transport.handleRequest(ctx.req, ctx.res, ctx.request.body ?? {});
|
|
208
|
+
} finally {
|
|
209
|
+
await server.close();
|
|
210
|
+
}
|
|
211
|
+
ctx.respond = false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private async handleStatelessJsonRpc(ctx: Context): Promise<void> {
|
|
215
|
+
ctx.withoutDataWrapping = true;
|
|
216
|
+
ctx.type = 'application/json';
|
|
217
|
+
|
|
218
|
+
const payload = ctx.request?.body;
|
|
219
|
+
if (Array.isArray(payload)) {
|
|
220
|
+
if (payload.length === 0) {
|
|
221
|
+
ctx.status = 400;
|
|
222
|
+
ctx.body = {
|
|
223
|
+
jsonrpc: '2.0',
|
|
224
|
+
id: null,
|
|
225
|
+
error: { code: -32600, message: 'Invalid Request: empty batch' },
|
|
226
|
+
};
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const responses: JsonRpcResponse[] = [];
|
|
230
|
+
for (const entry of payload) {
|
|
231
|
+
const res = await this.dispatchRpcMessage(entry, ctx);
|
|
232
|
+
if (res) responses.push(res);
|
|
233
|
+
}
|
|
234
|
+
if (responses.length === 0) {
|
|
235
|
+
ctx.status = 202;
|
|
236
|
+
ctx.body = '';
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
ctx.status = 200;
|
|
240
|
+
ctx.body = responses;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!isRecord(payload)) {
|
|
245
|
+
ctx.status = 400;
|
|
246
|
+
ctx.body = {
|
|
247
|
+
jsonrpc: '2.0',
|
|
248
|
+
id: null,
|
|
249
|
+
error: { code: -32600, message: 'Invalid JSON-RPC request payload' },
|
|
250
|
+
};
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const response = await this.dispatchRpcMessage(payload, ctx);
|
|
255
|
+
if (!response) {
|
|
256
|
+
ctx.status = 202;
|
|
257
|
+
ctx.body = '';
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
ctx.status = 200;
|
|
261
|
+
ctx.body = response;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private async dispatchRpcMessage(raw: unknown, ctx: Context): Promise<JsonRpcResponse | null> {
|
|
265
|
+
if (!isRecord(raw)) {
|
|
266
|
+
return {
|
|
267
|
+
jsonrpc: '2.0',
|
|
268
|
+
id: null,
|
|
269
|
+
error: { code: -32600, message: 'Invalid Request' },
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const req = raw as JsonRpcRequest;
|
|
274
|
+
const hasId = Object.prototype.hasOwnProperty.call(raw, 'id') && req.id !== undefined;
|
|
275
|
+
const id: string | number | null =
|
|
276
|
+
typeof req.id === 'string' || typeof req.id === 'number' || req.id === null ? req.id : null;
|
|
277
|
+
const method = typeof req.method === 'string' ? req.method : '';
|
|
278
|
+
|
|
279
|
+
if (!hasId && method.startsWith('notifications/')) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (!method) {
|
|
284
|
+
return {
|
|
285
|
+
jsonrpc: '2.0',
|
|
286
|
+
id,
|
|
287
|
+
error: { code: -32600, message: 'Invalid Request: missing method' },
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
switch (method) {
|
|
292
|
+
case 'initialize': {
|
|
293
|
+
const requestedProtocol =
|
|
294
|
+
isRecord(req.params) && typeof req.params.protocolVersion === 'string'
|
|
295
|
+
? req.params.protocolVersion
|
|
296
|
+
: '2025-03-26';
|
|
297
|
+
return {
|
|
298
|
+
jsonrpc: '2.0',
|
|
299
|
+
id,
|
|
300
|
+
result: {
|
|
301
|
+
protocolVersion: requestedProtocol,
|
|
302
|
+
capabilities: {
|
|
303
|
+
tools: {},
|
|
304
|
+
},
|
|
305
|
+
serverInfo: {
|
|
306
|
+
name: MCP_SERVER_NAME,
|
|
307
|
+
version: this.options.version,
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
case 'ping':
|
|
314
|
+
return {
|
|
315
|
+
jsonrpc: '2.0',
|
|
316
|
+
id,
|
|
317
|
+
result: {},
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
case 'tools/list':
|
|
321
|
+
return {
|
|
322
|
+
jsonrpc: '2.0',
|
|
323
|
+
id,
|
|
324
|
+
result: {
|
|
325
|
+
tools: this.getToolsMetadata(),
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
case 'tools/call': {
|
|
330
|
+
const params = isRecord(req.params) ? req.params : {};
|
|
331
|
+
const toolName = typeof params.name === 'string' ? params.name : '';
|
|
332
|
+
const toolArgs = isRecord(params.arguments) ? params.arguments : {};
|
|
333
|
+
const tool = this.toolMap.get(toolName);
|
|
334
|
+
if (!tool) {
|
|
335
|
+
return {
|
|
336
|
+
jsonrpc: '2.0',
|
|
337
|
+
id,
|
|
338
|
+
error: {
|
|
339
|
+
code: -32602,
|
|
340
|
+
message: `Unknown tool: ${toolName}`,
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
try {
|
|
346
|
+
const output = await tool.execute(toolArgs, ctx);
|
|
347
|
+
return {
|
|
348
|
+
jsonrpc: '2.0',
|
|
349
|
+
id,
|
|
350
|
+
result: {
|
|
351
|
+
content: [
|
|
352
|
+
{
|
|
353
|
+
type: 'text',
|
|
354
|
+
text: serializeToolResult(output),
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
isError: false,
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
} catch (error) {
|
|
361
|
+
const errStatus = (error as { status?: number } | undefined)?.status;
|
|
362
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
363
|
+
return {
|
|
364
|
+
jsonrpc: '2.0',
|
|
365
|
+
id,
|
|
366
|
+
result: {
|
|
367
|
+
content: [
|
|
368
|
+
{
|
|
369
|
+
type: 'text',
|
|
370
|
+
text: errStatus ? `[${errStatus}] ${message}` : message,
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
isError: true,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
default:
|
|
380
|
+
if (!hasId) return null;
|
|
381
|
+
return {
|
|
382
|
+
jsonrpc: '2.0',
|
|
383
|
+
id,
|
|
384
|
+
error: {
|
|
385
|
+
code: -32601,
|
|
386
|
+
message: `Method not found: ${method}`,
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|