0xray 2.1.1 → 2.1.3

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.
Files changed (254) hide show
  1. package/.opencode/codex.codex +1 -1
  2. package/.opencode/commands/dependency-audit.md +3 -3
  3. package/.opencode/enforcer-config.json +2 -2
  4. package/AGENTS.md +3 -2
  5. package/README.md +12 -11
  6. package/dist/AGENTS.md +3 -2
  7. package/dist/CHANGELOG.md +26 -0
  8. package/dist/README.md +12 -11
  9. package/dist/agents/code-reviewer.js +1 -1
  10. package/dist/analytics/routing-refiner.js +1 -1
  11. package/dist/cli/index.js +11 -1
  12. package/dist/cli/server.js +3 -3
  13. package/dist/core/activity-logger.d.ts +2 -2
  14. package/dist/core/activity-logger.js +4 -4
  15. package/dist/core/boot-orchestrator.d.ts +1 -1
  16. package/dist/core/boot-orchestrator.js +13 -28
  17. package/dist/core/bridge.mjs +3 -3
  18. package/dist/core/codex-formatter.js +2 -2
  19. package/dist/core/codex-injector.d.ts +0 -1
  20. package/dist/core/codex-injector.js +2 -3
  21. package/dist/core/config-loader.d.ts +1 -1
  22. package/dist/core/config-loader.js +1 -1
  23. package/dist/core/config-paths.d.ts +0 -2
  24. package/dist/core/config-paths.js +7 -8
  25. package/dist/core/context-loader.d.ts +1 -1
  26. package/dist/core/context-loader.js +1 -1
  27. package/dist/core/errors.d.ts +3 -0
  28. package/dist/core/errors.js +10 -0
  29. package/dist/core/features-config.js +1 -1
  30. package/dist/core/framework-logger.d.ts +3 -3
  31. package/dist/core/framework-logger.js +17 -9
  32. package/dist/core/index.d.ts +2 -2
  33. package/dist/core/index.js +4 -2
  34. package/dist/core/logging-config.d.ts +2 -1
  35. package/dist/core/logging-config.js +7 -7
  36. package/dist/enforcement/loaders/codex-loader.js +1 -1
  37. package/dist/execution/opencode-cli-invoker.js +5 -5
  38. package/dist/governance/governance-service.js +1 -1
  39. package/dist/index.d.ts +3 -3
  40. package/dist/index.js +3 -3
  41. package/dist/inference/inference-cycle.d.ts +1 -1
  42. package/dist/inference/inference-cycle.js +10 -10
  43. package/dist/integrations/base/Integration.js +1 -1
  44. package/dist/integrations/base/registry.js +19 -19
  45. package/dist/integrations/grok/grok-cli.js +17 -17
  46. package/dist/integrations/grok/hooks/pre-tool-use.js +1 -1
  47. package/dist/integrations/hermes-agent/bridge.mjs +1 -1
  48. package/dist/integrations/openclaw/api-server.d.ts +0 -1
  49. package/dist/integrations/openclaw/api-server.js +7 -10
  50. package/dist/integrations/openclaw/client.d.ts +0 -1
  51. package/dist/integrations/openclaw/client.js +22 -24
  52. package/dist/integrations/openclaw/hooks/xray-hooks.d.ts +0 -1
  53. package/dist/integrations/openclaw/hooks/xray-hooks.js +17 -18
  54. package/dist/integrations/plugins/plugin-registry.js +5 -5
  55. package/dist/mcps/architect-tools.server.d.ts +2 -4
  56. package/dist/mcps/architect-tools.server.js +112 -195
  57. package/dist/mcps/auto-format.server.d.ts +2 -4
  58. package/dist/mcps/auto-format.server.js +49 -95
  59. package/dist/mcps/boot-orchestrator.server.d.ts +2 -4
  60. package/dist/mcps/boot-orchestrator.server.js +73 -105
  61. package/dist/mcps/config/server-config-registry.js +3 -3
  62. package/dist/mcps/enforcer-tools.server.d.ts +2 -4
  63. package/dist/mcps/enforcer-tools.server.js +202 -285
  64. package/dist/mcps/estimation.server.d.ts +2 -4
  65. package/dist/mcps/estimation.server.js +63 -107
  66. package/dist/mcps/framework-compliance-audit.server.d.ts +2 -4
  67. package/dist/mcps/framework-compliance-audit.server.js +53 -82
  68. package/dist/mcps/framework-help.server.d.ts +2 -4
  69. package/dist/mcps/framework-help.server.js +63 -101
  70. package/dist/mcps/governance.server.js +2 -2
  71. package/dist/mcps/knowledge-skills/api-design.server.d.ts +2 -4
  72. package/dist/mcps/knowledge-skills/api-design.server.js +35 -67
  73. package/dist/mcps/knowledge-skills/architecture-patterns.server.d.ts +2 -10
  74. package/dist/mcps/knowledge-skills/architecture-patterns.server.js +35 -74
  75. package/dist/mcps/knowledge-skills/bug-triage-specialist.server.d.ts +2 -4
  76. package/dist/mcps/knowledge-skills/bug-triage-specialist.server.js +143 -162
  77. package/dist/mcps/knowledge-skills/code-analyzer.server.d.ts +3 -4
  78. package/dist/mcps/knowledge-skills/code-analyzer.server.js +20 -45
  79. package/dist/mcps/knowledge-skills/code-review.server.d.ts +2 -4
  80. package/dist/mcps/knowledge-skills/code-review.server.js +109 -143
  81. package/dist/mcps/knowledge-skills/content-creator.server.d.ts +2 -4
  82. package/dist/mcps/knowledge-skills/content-creator.server.js +205 -226
  83. package/dist/mcps/knowledge-skills/database-design.server.d.ts +2 -4
  84. package/dist/mcps/knowledge-skills/database-design.server.js +117 -151
  85. package/dist/mcps/knowledge-skills/devops-deployment.server.d.ts +2 -4
  86. package/dist/mcps/knowledge-skills/devops-deployment.server.js +71 -160
  87. package/dist/mcps/knowledge-skills/git-workflow.server.d.ts +2 -4
  88. package/dist/mcps/knowledge-skills/git-workflow.server.js +36 -68
  89. package/dist/mcps/knowledge-skills/growth-strategist.server.d.ts +2 -4
  90. package/dist/mcps/knowledge-skills/growth-strategist.server.js +303 -324
  91. package/dist/mcps/knowledge-skills/log-monitor.server.d.ts +2 -4
  92. package/dist/mcps/knowledge-skills/log-monitor.server.js +141 -160
  93. package/dist/mcps/knowledge-skills/mobile-development.server.d.ts +2 -4
  94. package/dist/mcps/knowledge-skills/mobile-development.server.js +92 -209
  95. package/dist/mcps/knowledge-skills/multimodal-looker.server.d.ts +2 -4
  96. package/dist/mcps/knowledge-skills/multimodal-looker.server.js +123 -159
  97. package/dist/mcps/knowledge-skills/performance-optimization.server.d.ts +2 -5
  98. package/dist/mcps/knowledge-skills/performance-optimization.server.js +155 -296
  99. package/dist/mcps/knowledge-skills/project-analysis.server.d.ts +2 -4
  100. package/dist/mcps/knowledge-skills/project-analysis.server.js +75 -226
  101. package/dist/mcps/knowledge-skills/refactoring-strategies.server.d.ts +2 -4
  102. package/dist/mcps/knowledge-skills/refactoring-strategies.server.js +63 -156
  103. package/dist/mcps/knowledge-skills/security-audit.server.d.ts +2 -4
  104. package/dist/mcps/knowledge-skills/security-audit.server.js +102 -136
  105. package/dist/mcps/knowledge-skills/seo-consultant.server.d.ts +2 -4
  106. package/dist/mcps/knowledge-skills/seo-consultant.server.js +80 -203
  107. package/dist/mcps/knowledge-skills/session-management.server.d.ts +2 -4
  108. package/dist/mcps/knowledge-skills/session-management.server.js +50 -203
  109. package/dist/mcps/knowledge-skills/skill-invocation.server.d.ts +2 -4
  110. package/dist/mcps/knowledge-skills/skill-invocation.server.js +168 -347
  111. package/dist/mcps/knowledge-skills/strategist.server.d.ts +2 -11
  112. package/dist/mcps/knowledge-skills/strategist.server.js +72 -122
  113. package/dist/mcps/knowledge-skills/tech-writer.server.d.ts +2 -4
  114. package/dist/mcps/knowledge-skills/tech-writer.server.js +87 -300
  115. package/dist/mcps/knowledge-skills/testing-best-practices.server.d.ts +2 -4
  116. package/dist/mcps/knowledge-skills/testing-best-practices.server.js +147 -182
  117. package/dist/mcps/knowledge-skills/testing-strategy.server.d.ts +2 -4
  118. package/dist/mcps/knowledge-skills/testing-strategy.server.js +78 -153
  119. package/dist/mcps/knowledge-skills/ui-ux-design.server.d.ts +2 -5
  120. package/dist/mcps/knowledge-skills/ui-ux-design.server.js +90 -399
  121. package/dist/mcps/lint.server.d.ts +2 -4
  122. package/dist/mcps/lint.server.js +51 -92
  123. package/dist/mcps/mcp-client.js +2 -2
  124. package/dist/mcps/model-health-check.server.d.ts +2 -4
  125. package/dist/mcps/model-health-check.server.js +32 -60
  126. package/dist/mcps/performance-analysis.server.d.ts +2 -4
  127. package/dist/mcps/performance-analysis.server.js +57 -88
  128. package/dist/mcps/processor-pipeline.server.d.ts +2 -4
  129. package/dist/mcps/processor-pipeline.server.js +69 -100
  130. package/dist/mcps/registry.json +1 -1
  131. package/dist/mcps/researcher.server.d.ts +3 -5
  132. package/dist/mcps/researcher.server.js +81 -154
  133. package/dist/mcps/security-scan.server.d.ts +2 -4
  134. package/dist/mcps/security-scan.server.js +54 -96
  135. package/dist/mcps/shared/knowledge-skill-base.d.ts +14 -0
  136. package/dist/mcps/shared/knowledge-skill-base.js +45 -0
  137. package/dist/{security → mcps/shared}/security-scanner.js +1 -1
  138. package/dist/mcps/state-manager.server.d.ts +2 -4
  139. package/dist/mcps/state-manager.server.js +115 -160
  140. package/dist/orchestrator/orchestrator.d.ts +1 -1
  141. package/dist/orchestrator/orchestrator.js +1 -1
  142. package/dist/orchestrator/universal-registry-bridge.js +1 -1
  143. package/dist/plugin/xray-codex-injection.d.ts +1 -1
  144. package/dist/plugin/xray-codex-injection.js +1 -1
  145. package/dist/postprocessor/PostProcessor.d.ts +4 -44
  146. package/dist/postprocessor/PostProcessor.js +39 -553
  147. package/dist/postprocessor/analysis/CodeChangeAnalyzer.d.ts +11 -0
  148. package/dist/postprocessor/analysis/CodeChangeAnalyzer.js +50 -0
  149. package/dist/postprocessor/compliance/ArchitecturalComplianceChecker.d.ts +11 -0
  150. package/dist/postprocessor/compliance/ArchitecturalComplianceChecker.js +356 -0
  151. package/dist/postprocessor/config/ProcessorConfigLoader.d.ts +44 -0
  152. package/dist/postprocessor/config/ProcessorConfigLoader.js +21 -0
  153. package/dist/postprocessor/reporting/PostProcessorReporter.d.ts +19 -0
  154. package/dist/postprocessor/reporting/PostProcessorReporter.js +96 -0
  155. package/dist/postprocessor/triggers/GitHookTrigger.js +11 -11
  156. package/dist/processors/implementations/refactoring-logging-processor-wrapper.d.ts +32 -0
  157. package/dist/processors/implementations/refactoring-logging-processor-wrapper.js +95 -1
  158. package/dist/processors/processor-manager.js +346 -314
  159. package/dist/reporting/report-formatter.js +1 -1
  160. package/dist/security/security-hardener.d.ts +69 -2
  161. package/dist/security/security-hardener.js +129 -1
  162. package/dist/skills/registry.json +1 -1
  163. package/dist/state/index.d.ts +3 -5
  164. package/dist/state/index.js +1 -7
  165. package/dist/state/state-manager.d.ts +1 -1
  166. package/dist/state/state-manager.js +2 -3
  167. package/package.json +14 -10
  168. package/scripts/node/setup.cjs +32 -0
  169. package/scripts/node/universal-version-manager.js +11 -11
  170. package/src/mcps/architect-tools.server.ts +112 -215
  171. package/src/mcps/auto-format.server.ts +50 -110
  172. package/src/mcps/boot-orchestrator.server.ts +75 -121
  173. package/src/mcps/config/__tests__/server-config-registry.test.ts +21 -12
  174. package/src/mcps/config/server-config-registry.ts +3 -3
  175. package/src/mcps/enforcer-tools.server.ts +212 -310
  176. package/src/mcps/estimation.server.ts +62 -122
  177. package/src/mcps/framework-compliance-audit.server.ts +52 -97
  178. package/src/mcps/framework-help.server.ts +64 -114
  179. package/src/mcps/governance.server.ts +2 -2
  180. package/src/mcps/knowledge-skills/api-design.server.ts +32 -77
  181. package/src/mcps/knowledge-skills/architecture-patterns.server.ts +31 -87
  182. package/src/mcps/knowledge-skills/bug-triage-specialist.server.ts +165 -193
  183. package/src/mcps/knowledge-skills/code-analyzer.server.ts +20 -55
  184. package/src/mcps/knowledge-skills/code-review.server.ts +114 -161
  185. package/src/mcps/knowledge-skills/content-creator.server.ts +218 -255
  186. package/src/mcps/knowledge-skills/database-design.server.ts +118 -165
  187. package/src/mcps/knowledge-skills/devops-deployment.server.ts +67 -172
  188. package/src/mcps/knowledge-skills/git-workflow.server.ts +32 -77
  189. package/src/mcps/knowledge-skills/growth-strategist.server.ts +324 -361
  190. package/src/mcps/knowledge-skills/log-monitor.server.ts +160 -187
  191. package/src/mcps/knowledge-skills/mobile-development.server.ts +89 -223
  192. package/src/mcps/knowledge-skills/multimodal-looker.server.ts +128 -175
  193. package/src/mcps/knowledge-skills/performance-optimization.server.ts +156 -329
  194. package/src/mcps/knowledge-skills/project-analysis.server.ts +72 -248
  195. package/src/mcps/knowledge-skills/refactoring-strategies.server.ts +59 -171
  196. package/src/mcps/knowledge-skills/security-audit.server.ts +104 -151
  197. package/src/mcps/knowledge-skills/seo-consultant.server.ts +80 -220
  198. package/src/mcps/knowledge-skills/session-management.server.ts +51 -232
  199. package/src/mcps/knowledge-skills/skill-invocation.server.ts +165 -372
  200. package/src/mcps/knowledge-skills/strategist.server.ts +72 -143
  201. package/src/mcps/knowledge-skills/tech-writer.server.ts +85 -350
  202. package/src/mcps/knowledge-skills/testing-best-practices.server.ts +146 -195
  203. package/src/mcps/knowledge-skills/testing-strategy.server.ts +75 -161
  204. package/src/mcps/knowledge-skills/ui-ux-design.server.ts +93 -487
  205. package/src/mcps/lint.server.ts +53 -107
  206. package/src/mcps/mcp-client.ts +2 -2
  207. package/src/mcps/model-health-check.server.ts +34 -71
  208. package/src/mcps/performance-analysis.server.ts +60 -104
  209. package/src/mcps/processor-pipeline.server.ts +72 -110
  210. package/src/mcps/registry.json +1 -1
  211. package/src/mcps/researcher.server.ts +88 -177
  212. package/src/mcps/security-scan.server.ts +55 -104
  213. package/src/mcps/shared/knowledge-skill-base.ts +62 -0
  214. package/src/mcps/shared/prompt-security-validator.ts +199 -0
  215. package/src/mcps/shared/security-scanner.ts +599 -0
  216. package/src/mcps/state-manager.server.ts +117 -175
  217. package/src/opencode/codex.codex +1 -1
  218. package/src/opencode/commands/dependency-audit.md +3 -3
  219. package/src/opencode/enforcer-config.json +2 -2
  220. package/src/skills/registry.json +1 -1
  221. package/xray/agents_template.md +109 -0
  222. package/xray/codex.json +598 -0
  223. package/xray/config.json +26 -0
  224. package/xray/features.json +132 -0
  225. package/xray/integrations.json +23 -0
  226. package/xray/routing-mappings.json +752 -0
  227. package/xray/workflow_state.json +28 -0
  228. package/dist/integrations/hermes-agent/__pycache__/__init__.cpython-313.pyc +0 -0
  229. package/dist/integrations/hermes-agent/__pycache__/conftest.cpython-313-pytest-9.0.2.pyc +0 -0
  230. package/dist/integrations/hermes-agent/__pycache__/schemas.cpython-313.pyc +0 -0
  231. package/dist/integrations/hermes-agent/__pycache__/test_plugin.cpython-313-pytest-9.0.2.pyc +0 -0
  232. package/dist/integrations/hermes-agent/__pycache__/test_plugin.cpython-313.pyc +0 -0
  233. package/dist/integrations/hermes-agent/__pycache__/tools.cpython-313.pyc +0 -0
  234. package/dist/integrations/hermes-agent/conftest.py +0 -14
  235. package/dist/integrations/hermes-agent/test_plugin.py +0 -1103
  236. package/dist/processors/implementations/refactoring-logging-processor.d.ts +0 -31
  237. package/dist/processors/implementations/refactoring-logging-processor.js +0 -96
  238. package/dist/processors/implementations/session-capture-processor.d.ts +0 -14
  239. package/dist/processors/implementations/session-capture-processor.js +0 -37
  240. package/dist/scripts/activate-kernel-pipeline.d.ts +0 -7
  241. package/dist/scripts/activate-kernel-pipeline.js +0 -101
  242. package/dist/security/index.d.ts +0 -13
  243. package/dist/security/index.js +0 -13
  244. package/dist/security/security-agent-coordinator.d.ts +0 -72
  245. package/dist/security/security-agent-coordinator.js +0 -204
  246. package/dist/security/security-auditor.d.ts +0 -56
  247. package/dist/security/security-auditor.js +0 -584
  248. package/dist/security/security-hardening-system.d.ts +0 -239
  249. package/dist/security/security-hardening-system.js +0 -727
  250. package/dist/security/security-orchestration-layer.d.ts +0 -119
  251. package/dist/security/security-orchestration-layer.js +0 -496
  252. /package/dist/{security → mcps/shared}/prompt-security-validator.d.ts +0 -0
  253. /package/dist/{security → mcps/shared}/prompt-security-validator.js +0 -0
  254. /package/dist/{security → mcps/shared}/security-scanner.d.ts +0 -0
@@ -4,12 +4,6 @@
4
4
  * Automated security vulnerability scanning with dependency and code analysis
5
5
  */
6
6
 
7
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
8
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9
- import {
10
- CallToolRequestSchema,
11
- ListToolsRequestSchema,
12
- } from "@modelcontextprotocol/sdk/types.js";
13
7
  import { execFileSync } from "child_process";
14
8
  import fs from "fs";
15
9
  import path from "path";
@@ -19,6 +13,7 @@ import {
19
13
  type LanguageConfig,
20
14
  } from "../utils/language-detector.js";
21
15
  import { frameworkLogger } from "../core/framework-logger.js";
16
+ import { XrayKnowledgeSkillBase } from "./shared/knowledge-skill-base.js";
22
17
 
23
18
  interface SecurityScanArgs {
24
19
  scope?: string;
@@ -39,107 +34,68 @@ interface SecuritySummaryResults {
39
34
  summary: string;
40
35
  }
41
36
 
42
- class XraySecurityScanServer {
43
- private server: Server;
44
-
37
+ class XraySecurityScanServer extends XrayKnowledgeSkillBase {
45
38
  constructor() {
46
- this.server = new Server(
47
- {
48
- name: "security-scan", version: "2.0.1",
49
- },
39
+ super("security-scan", "2.0.1");
40
+
41
+ this.tools = [
50
42
  {
51
- capabilities: {
52
- tools: {},
43
+ name: "security-scan",
44
+ description:
45
+ "Comprehensive security vulnerability scanning with dependency and code analysis",
46
+ inputSchema: {
47
+ type: "object",
48
+ properties: {
49
+ scope: {
50
+ type: "string",
51
+ enum: ["dependencies", "code", "full"],
52
+ default: "full",
53
+ description: "Scope of security scan",
54
+ },
55
+ auditLevel: {
56
+ type: "string",
57
+ enum: ["info", "low", "moderate", "high", "critical"],
58
+ default: "moderate",
59
+ description: "Audit level for vulnerability detection",
60
+ },
61
+ includeOutdated: {
62
+ type: "boolean",
63
+ default: true,
64
+ description: "Include outdated package analysis",
65
+ },
66
+ },
53
67
  },
54
68
  },
55
- );
56
-
57
- this.setupToolHandlers();
58
- frameworkLogger.log("mcps/security-scan", "initialize", "info");
59
- }
60
-
61
- private setupToolHandlers() {
62
- // List available tools
63
- this.server.setRequestHandler(ListToolsRequestSchema, async () => {
64
- return {
65
- tools: [
66
- {
67
- name: "security-scan",
68
- description:
69
- "Comprehensive security vulnerability scanning with dependency and code analysis",
70
- inputSchema: {
71
- type: "object",
72
- properties: {
73
- scope: {
74
- type: "string",
75
- enum: ["dependencies", "code", "full"],
76
- default: "full",
77
- description: "Scope of security scan",
78
- },
79
- auditLevel: {
80
- type: "string",
81
- enum: ["info", "low", "moderate", "high", "critical"],
82
- default: "moderate",
83
- description: "Audit level for vulnerability detection",
84
- },
85
- includeOutdated: {
86
- type: "boolean",
87
- default: true,
88
- description: "Include outdated package analysis",
89
- },
90
- },
69
+ {
70
+ name: "dependency-audit",
71
+ description:
72
+ "Audit third-party dependencies for security vulnerabilities",
73
+ inputSchema: {
74
+ type: "object",
75
+ properties: {
76
+ packageManager: {
77
+ type: "string",
78
+ enum: ["npm", "yarn", "pnpm", "auto"],
79
+ default: "auto",
80
+ description: "Package manager to use",
91
81
  },
92
- },
93
- {
94
- name: "dependency-audit",
95
- description:
96
- "Audit third-party dependencies for security vulnerabilities",
97
- inputSchema: {
98
- type: "object",
99
- properties: {
100
- packageManager: {
101
- type: "string",
102
- enum: ["npm", "yarn", "pnpm", "auto"],
103
- default: "auto",
104
- description: "Package manager to use",
105
- },
106
- auditLevel: {
107
- type: "string",
108
- enum: ["info", "low", "moderate", "high", "critical"],
109
- default: "moderate",
110
- },
111
- },
82
+ auditLevel: {
83
+ type: "string",
84
+ enum: ["info", "low", "moderate", "high", "critical"],
85
+ default: "moderate",
112
86
  },
113
87
  },
114
- ],
115
- };
116
- });
88
+ },
89
+ },
90
+ ];
117
91
 
118
- // Handle tool calls
119
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
120
- const { name, arguments: args } = request.params;
92
+ this.handlers = {
93
+ "security-scan": async (args) => this.handleSecurityScan(args),
94
+ "dependency-audit": async (args) => this.handleDependencyAudit(args),
95
+ };
121
96
 
122
- try {
123
- switch (name) {
124
- case "security-scan":
125
- return await this.handleSecurityScan(args);
126
- case "dependency-audit":
127
- return await this.handleDependencyAudit(args);
128
- default:
129
- throw new Error(`Unknown tool: ${name}`);
130
- }
131
- } catch (error) {
132
- frameworkLogger.log("mcps/security-scan", "tool-handler", "error", { tool: name, error: String(error) });
133
- return {
134
- content: [
135
- {
136
- type: "text",
137
- text: `Error executing tool "${name}": ${error instanceof Error ? error.message : String(error)}`,
138
- },
139
- ],
140
- };
141
- }
142
- });
97
+ this.setupToolHandlers();
98
+ frameworkLogger.log("mcps/security-scan", "initialize", "info");
143
99
  }
144
100
 
145
101
  private async handleSecurityScan(args: unknown) {
@@ -635,17 +591,12 @@ ${results.recommendations.map((r) => `• ${r}`).join("\n") || "No recommendatio
635
591
  - Recommendations: ${recCount}`;
636
592
  }
637
593
 
638
- async run() {
639
- const transport = new StdioServerTransport();
640
- await this.server.connect(transport);
641
- frameworkLogger.log("mcps/security-scan", "start", "info");
642
- }
643
594
  }
644
595
 
645
596
  // Start the server if run directly
646
597
  if (import.meta.url === `file://${process.argv[1]}`) {
647
598
  const server = new XraySecurityScanServer();
648
- server.run().catch((error) => frameworkLogger.log("mcps/security-scan", "run", "error", { error: String(error) }));
599
+ server.run("security-scan").catch((error) => frameworkLogger.log("mcps/security-scan", "run", "error", { error: String(error) }));
649
600
  }
650
601
 
651
602
  export { XraySecurityScanServer };
@@ -0,0 +1,62 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import {
4
+ CallToolRequestSchema,
5
+ ListToolsRequestSchema,
6
+ } from "@modelcontextprotocol/sdk/types.js";
7
+ import { frameworkLogger } from "../../core/framework-logger.js";
8
+ import { createGracefulShutdown } from "../../utils/shutdown-handler.js";
9
+
10
+ export interface ToolDefinition {
11
+ name: string;
12
+ description: string;
13
+ inputSchema: object;
14
+ }
15
+
16
+ export class XrayKnowledgeSkillBase {
17
+ protected tools: ToolDefinition[] = [];
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ protected handlers: Record<string, (args: unknown) => Promise<any>> = {};
20
+
21
+ protected server: Server;
22
+
23
+ constructor(serverName: string, version = "2.0.1") {
24
+ this.server = new Server(
25
+ { name: serverName, version },
26
+ { capabilities: { tools: {} } },
27
+ );
28
+ }
29
+
30
+ protected setupToolHandlers(): void {
31
+ this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
32
+ tools: this.tools.map((t) => ({
33
+ name: t.name,
34
+ description: t.description,
35
+ inputSchema: t.inputSchema,
36
+ })),
37
+ }));
38
+
39
+ this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
40
+ const { name, arguments: args } = request.params;
41
+ const handler = this.handlers[name];
42
+ if (!handler) {
43
+ throw new Error(`Unknown tool: ${name}`);
44
+ }
45
+ try {
46
+ return await handler(args);
47
+ } catch (error) {
48
+ return {
49
+ content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }],
50
+ isError: true,
51
+ };
52
+ }
53
+ });
54
+ }
55
+
56
+ async run(serverName: string): Promise<void> {
57
+ const transport = new StdioServerTransport();
58
+ await this.server.connect(transport);
59
+ createGracefulShutdown({ serverName, server: this.server });
60
+ await frameworkLogger.log(serverName, "server-started", "success");
61
+ }
62
+ }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * 0xRay Framework - AI Prompt Security Validator
3
+ *
4
+ * Specialized security validation for AI agent prompts and responses
5
+ * Prevents prompt injection, system prompt override, and malicious inputs
6
+ */
7
+
8
+ export interface PromptSecurityConfig {
9
+ enabled: boolean;
10
+ maxPromptLength: number;
11
+ allowedPatterns: RegExp[];
12
+ blockedPatterns: RegExp[];
13
+ sanitizeLevel: "basic" | "strict" | "paranoid";
14
+ }
15
+
16
+ export interface SecurityValidationResult {
17
+ isSafe: boolean;
18
+ violations: string[];
19
+ sanitizedPrompt?: string | undefined;
20
+ riskLevel: "low" | "medium" | "high" | "critical";
21
+ }
22
+
23
+ export class PromptSecurityValidator {
24
+ private config: PromptSecurityConfig;
25
+
26
+ constructor(config: Partial<PromptSecurityConfig> = {}) {
27
+ this.config = {
28
+ enabled: true,
29
+ maxPromptLength: 10000,
30
+ allowedPatterns: [],
31
+ blockedPatterns: [
32
+ /system\s+prompt\s*[:=]/gi,
33
+ /ignore\s+previous\s+instructions/gi,
34
+ /you\s+are\s+now\s+/gi,
35
+ /forget\s+your\s+previous\s+/gi,
36
+ /override\s+(your\s+)?instructions/gi,
37
+ /jailbreak/gi,
38
+ /dan.*mode/gi,
39
+ ],
40
+ sanitizeLevel: "strict",
41
+ ...config,
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Validate AI prompt for security issues
47
+ */
48
+ validatePrompt(prompt: string): SecurityValidationResult {
49
+ if (!this.config.enabled) {
50
+ return { isSafe: true, violations: [], riskLevel: "low" };
51
+ }
52
+
53
+ const violations: string[] = [];
54
+ let riskLevel: SecurityValidationResult["riskLevel"] = "low";
55
+
56
+ // Length check
57
+ if (prompt.length > this.config.maxPromptLength) {
58
+ violations.push(
59
+ `Prompt too long: ${prompt.length} > ${this.config.maxPromptLength}`,
60
+ );
61
+ riskLevel = "medium";
62
+ }
63
+
64
+ // Blocked pattern check
65
+ for (const pattern of this.config.blockedPatterns) {
66
+ if (pattern.test(prompt)) {
67
+ violations.push(`Blocked pattern detected: ${pattern.source}`);
68
+ riskLevel = "high";
69
+ }
70
+ }
71
+
72
+ // Advanced pattern analysis
73
+ if (this.containsSystemPromptOverride(prompt)) {
74
+ violations.push("Potential system prompt override attempt");
75
+ riskLevel = "critical";
76
+ }
77
+
78
+ if (this.containsInjectionAttempts(prompt)) {
79
+ violations.push("Potential prompt injection detected");
80
+ riskLevel = "high";
81
+ }
82
+
83
+ const isSafe = violations.length === 0;
84
+ const sanitizedPrompt = isSafe ? undefined : this.sanitizePrompt(prompt);
85
+
86
+ return {
87
+ isSafe,
88
+ violations,
89
+ sanitizedPrompt,
90
+ riskLevel,
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Check for system prompt override attempts
96
+ */
97
+ private containsSystemPromptOverride(prompt: string): boolean {
98
+ const overrideIndicators = [
99
+ "you are now",
100
+ "act as if",
101
+ "pretend to be",
102
+ "role-play as",
103
+ "from now on you are",
104
+ "ignore your system",
105
+ "override your",
106
+ "new personality",
107
+ "different role",
108
+ ];
109
+
110
+ const lowerPrompt = prompt.toLowerCase();
111
+ return overrideIndicators.some((indicator) =>
112
+ lowerPrompt.includes(indicator),
113
+ );
114
+ }
115
+
116
+ /**
117
+ * Check for prompt injection attempts
118
+ */
119
+ private containsInjectionAttempts(prompt: string): boolean {
120
+ const injectionIndicators = [
121
+ "ignore previous",
122
+ "forget instructions",
123
+ "start over",
124
+ "new conversation",
125
+ "reset context",
126
+ "clear memory",
127
+ "delete history",
128
+ ];
129
+
130
+ const lowerPrompt = prompt.toLowerCase();
131
+ return injectionIndicators.some((indicator) =>
132
+ lowerPrompt.includes(indicator),
133
+ );
134
+ }
135
+
136
+ /**
137
+ * Sanitize prompt by removing dangerous patterns
138
+ */
139
+ private sanitizePrompt(prompt: string): string {
140
+ let sanitized = prompt;
141
+
142
+ // Remove blocked patterns
143
+ for (const pattern of this.config.blockedPatterns) {
144
+ sanitized = sanitized.replace(pattern, "[REDACTED]");
145
+ }
146
+
147
+ // Additional sanitization based on level
148
+ if (
149
+ this.config.sanitizeLevel === "strict" ||
150
+ this.config.sanitizeLevel === "paranoid"
151
+ ) {
152
+ // Remove potential code execution
153
+ sanitized = sanitized.replace(/```[\s\S]*?```/g, "[CODE_BLOCK_REMOVED]");
154
+
155
+ // Remove potential file system access
156
+ sanitized = sanitized.replace(/(?:\/|\\)\.\.(?:\/|\\)/g, "/");
157
+
158
+ // Remove potential command injection
159
+ sanitized = sanitized.replace(/[;&|`$()]/g, "");
160
+ }
161
+
162
+ if (this.config.sanitizeLevel === "paranoid") {
163
+ // Extreme sanitization - only allow alphanumeric, spaces, and basic punctuation
164
+ sanitized = sanitized.replace(/[^a-zA-Z0-9\s.,!?-]/g, "");
165
+ }
166
+
167
+ return sanitized;
168
+ }
169
+
170
+ /**
171
+ * Validate agent response for safety
172
+ */
173
+ validateResponse(response: string): SecurityValidationResult {
174
+ // Similar validation but focused on response safety
175
+ const violations: string[] = [];
176
+
177
+ // Check for potentially harmful content
178
+ if (
179
+ response.includes("system prompt") ||
180
+ response.includes("internal instructions")
181
+ ) {
182
+ violations.push("Response contains sensitive system information");
183
+ }
184
+
185
+ // Check for code execution attempts
186
+ if (/eval\s*\(|Function\s*\(/.test(response)) {
187
+ violations.push("Response contains potential code execution");
188
+ }
189
+
190
+ return {
191
+ isSafe: violations.length === 0,
192
+ violations,
193
+ riskLevel: violations.length > 0 ? "medium" : "low",
194
+ };
195
+ }
196
+ }
197
+
198
+ // Export singleton instance
199
+ export const promptSecurityValidator = new PromptSecurityValidator();