-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
172 lines (154 loc) · 5.58 KB
/
index.js
File metadata and controls
172 lines (154 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env node
// @prooflayer/security-scanner
// Lightweight, zero-Python MCP security scanner for AI coding agents
// MIT License | https://github.com/sinewaveai/agent-security-scanner-mcp
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
import { getVersion } from './src/utils.js';
import { loadPackageLists } from './src/check-package.js';
// Import tool handlers
import { scanSecurity, scanSecuritySchema } from './src/scan-security.js';
import { fixSecurity, fixSecuritySchema } from './src/fix-security.js';
import { checkPackage, checkPackageSchema } from './src/check-package.js';
import { scanPackages, scanPackagesSchema } from './src/scan-packages.js';
import { scanAgentPrompt, scanAgentPromptSchema } from './src/scan-prompt.js';
import { scanAgentAction, scanAgentActionSchema } from './src/scan-action.js';
import { scanMcpServer, scanMcpServerSchema } from './src/scan-mcp.js';
// Initialize MCP server
const server = new Server(
{
name: "@prooflayer/security-scanner",
version: getVersion(),
},
{
capabilities: {
tools: {},
},
}
);
// Load package lists on startup (4.3M+ packages)
console.error(`[@prooflayer/security-scanner v${getVersion()}] Loading package verification data...`);
loadPackageLists();
console.error(`[@prooflayer/security-scanner] Ready. Engine: regex (zero-Python)`);
// Register MCP tools
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "scan_security",
description: "Scan code for security vulnerabilities using 1700+ YAML rules. Detects SQL injection, XSS, secrets, command injection, and 30+ vulnerability types. Returns findings with severity, line numbers, and auto-fix suggestions.",
inputSchema: {
type: "object",
properties: scanSecuritySchema,
required: ["file_path"]
}
},
{
name: "fix_security",
description: "Generate secure code fixes for vulnerabilities. Provides language-specific remediation for detected issues with explanations.",
inputSchema: {
type: "object",
properties: fixSecuritySchema,
required: ["file_path"]
}
},
{
name: "check_package",
description: "Verify if a package exists in official registries (npm, PyPI, RubyGems, crates.io, CPAN, pub.dev, raku.land). Detects package hallucination and typosquatting. Covers 4.3M+ real packages.",
inputSchema: {
type: "object",
properties: checkPackageSchema,
required: ["package_name", "ecosystem"]
}
},
{
name: "scan_packages",
description: "Scan all package imports in a file for hallucination and typosquatting. Returns verification status for each dependency.",
inputSchema: {
type: "object",
properties: scanPackagesSchema,
required: ["file_path", "ecosystem"]
}
},
{
name: "scan_agent_prompt",
description: "Detect prompt injection, jailbreaks, and social engineering in AI agent prompts. Covers 40+ attack patterns including base64 encoding, role manipulation, and exfiltration attempts.",
inputSchema: {
type: "object",
properties: scanAgentPromptSchema,
required: ["prompt"]
}
},
{
name: "scan_agent_action",
description: "Pre-execution safety check for agent actions (bash, file operations, HTTP requests). Returns ALLOW/WARN/BLOCK with risk assessment.",
inputSchema: {
type: "object",
properties: scanAgentActionSchema,
required: ["action_type", "action_details"]
}
},
{
name: "scan_mcp_server",
description: "Audit MCP server source code for security vulnerabilities, tool name spoofing, description injection, unicode poisoning, and rug pull detection. Returns A-F security grade.",
inputSchema: {
type: "object",
properties: scanMcpServerSchema,
required: ["server_path"]
}
}
]
};
});
// Handle tool execution
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
try {
switch (name) {
case "scan_security":
return await scanSecurity(args);
case "fix_security":
return await fixSecurity(args);
case "check_package":
return await checkPackage(args);
case "scan_packages":
return await scanPackages(args);
case "scan_agent_prompt":
return await scanAgentPrompt(args);
case "scan_agent_action":
return await scanAgentAction(args);
case "scan_mcp_server":
return await scanMcpServer(args);
default:
return {
content: [{ type: "text", text: JSON.stringify({ error: `Unknown tool: ${name}` }) }]
};
}
} catch (error) {
return {
content: [{
type: "text",
text: JSON.stringify({
error: error.message,
tool: name,
timestamp: new Date().toISOString()
})
}],
isError: true
};
}
});
// Start server
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("[@prooflayer/security-scanner] MCP server running on stdio");
}
main().catch((error) => {
console.error("Fatal error:", error);
process.exit(1);
});