@attackforge/mcp-server 0.2.0
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/LICENSE +7 -0
- package/dist/index.js +67 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 AttackForge
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
if (!process.env.AF_HOSTNAME) {
|
|
7
|
+
throw new Error('Environment variable AF_HOSTNAME is required');
|
|
8
|
+
}
|
|
9
|
+
if (!process.env.AF_USER_KEY) {
|
|
10
|
+
throw new Error('Environment variable AF_USER_KEY is required');
|
|
11
|
+
}
|
|
12
|
+
let packageJson;
|
|
13
|
+
try {
|
|
14
|
+
const filePath = new URL('../package.json', import.meta.url);
|
|
15
|
+
const contents = await readFile(filePath, { encoding: 'utf8' });
|
|
16
|
+
packageJson = JSON.parse(contents);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
throw new Error('Failed to parse package.json');
|
|
20
|
+
}
|
|
21
|
+
const mcpServer = new McpServer({
|
|
22
|
+
name: packageJson.name,
|
|
23
|
+
version: packageJson.version,
|
|
24
|
+
}, {
|
|
25
|
+
capabilities: {
|
|
26
|
+
tools: {
|
|
27
|
+
listChanged: false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
mcpServer.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
32
|
+
const url = new URL('/mcp/tools/call', `https://${process.env.AF_HOSTNAME}`);
|
|
33
|
+
if (process.env.AF_PORT) {
|
|
34
|
+
url.port = process.env.AF_PORT;
|
|
35
|
+
}
|
|
36
|
+
const response = await fetch(url, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
body: JSON.stringify(request),
|
|
39
|
+
headers: {
|
|
40
|
+
'content-type': 'application/json',
|
|
41
|
+
'x-user-key': process.env.AF_USER_KEY,
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (response.status === 200) {
|
|
45
|
+
return await response.json();
|
|
46
|
+
}
|
|
47
|
+
throw new Error('Tool not found');
|
|
48
|
+
});
|
|
49
|
+
mcpServer.server.setRequestHandler(ListToolsRequestSchema, async (request) => {
|
|
50
|
+
const url = new URL('/mcp/tools/list', `https://${process.env.AF_HOSTNAME}`);
|
|
51
|
+
if (process.env.AF_PORT) {
|
|
52
|
+
url.port = process.env.AF_PORT;
|
|
53
|
+
}
|
|
54
|
+
const response = await fetch(url, {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
body: JSON.stringify(request),
|
|
57
|
+
headers: {
|
|
58
|
+
'content-type': 'application/json',
|
|
59
|
+
'x-user-key': process.env.AF_USER_KEY,
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (response.status === 200) {
|
|
63
|
+
return await response.json();
|
|
64
|
+
}
|
|
65
|
+
throw new Error('Unexpected response');
|
|
66
|
+
});
|
|
67
|
+
mcpServer.connect(new StdioServerTransport());
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@attackforge/mcp-server",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "AttackForge MCP Server",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"af-mcp-server": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc && shx chmod +x dist/index.js",
|
|
15
|
+
"clean": "rm -rf dist",
|
|
16
|
+
"prepare": "npm run rebuild",
|
|
17
|
+
"rebuild": "npm run clean && npm run build"
|
|
18
|
+
},
|
|
19
|
+
"author": "AttackForge",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.16.5",
|
|
23
|
+
"shx": "^0.4.0",
|
|
24
|
+
"typescript": "^5.8.3"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@modelcontextprotocol/sdk": "^1.21.0",
|
|
28
|
+
"@tsconfig/node22": "^22.0.2"
|
|
29
|
+
}
|
|
30
|
+
}
|