@somebeach/a2abench-mcp 0.1.5
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 +9 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +92 -0
- package/package.json +31 -0
package/README.md
ADDED
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'dotenv/config';
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
const API_BASE_URL = process.env.API_BASE_URL ?? 'http://localhost:3000';
|
|
6
|
+
const PUBLIC_BASE_URL = process.env.PUBLIC_BASE_URL ?? API_BASE_URL;
|
|
7
|
+
const API_KEY = process.env.API_KEY ?? '';
|
|
8
|
+
const server = new McpServer({
|
|
9
|
+
name: 'A2ABench',
|
|
10
|
+
version: '0.1.0'
|
|
11
|
+
});
|
|
12
|
+
async function apiGet(path, params) {
|
|
13
|
+
const url = new URL(path, API_BASE_URL);
|
|
14
|
+
if (params) {
|
|
15
|
+
Object.entries(params).forEach(([key, value]) => url.searchParams.set(key, value));
|
|
16
|
+
}
|
|
17
|
+
const headers = { accept: 'application/json' };
|
|
18
|
+
if (API_KEY) {
|
|
19
|
+
headers.authorization = `Bearer ${API_KEY}`;
|
|
20
|
+
}
|
|
21
|
+
const response = await fetch(url, { headers });
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
server.registerTool('search', {
|
|
25
|
+
title: 'Search questions',
|
|
26
|
+
description: 'Search questions by keyword and return canonical URLs.',
|
|
27
|
+
inputSchema: {
|
|
28
|
+
query: z.string().min(1)
|
|
29
|
+
}
|
|
30
|
+
}, async ({ query }) => {
|
|
31
|
+
const response = await apiGet('/api/v1/search', { q: query });
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
return {
|
|
34
|
+
content: [
|
|
35
|
+
{
|
|
36
|
+
type: 'text',
|
|
37
|
+
text: JSON.stringify({ results: [] })
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const data = (await response.json());
|
|
43
|
+
const results = (data.results ?? []).map((item) => ({
|
|
44
|
+
id: item.id,
|
|
45
|
+
title: item.title,
|
|
46
|
+
url: `${PUBLIC_BASE_URL}/q/${item.id}`
|
|
47
|
+
}));
|
|
48
|
+
return {
|
|
49
|
+
content: [
|
|
50
|
+
{
|
|
51
|
+
type: 'text',
|
|
52
|
+
text: JSON.stringify({ results })
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
server.registerTool('fetch', {
|
|
58
|
+
title: 'Fetch question thread',
|
|
59
|
+
description: 'Fetch a question and its answers by id.',
|
|
60
|
+
inputSchema: {
|
|
61
|
+
id: z.string().min(1)
|
|
62
|
+
}
|
|
63
|
+
}, async ({ id }) => {
|
|
64
|
+
const response = await apiGet(`/api/v1/questions/${id}`);
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
return {
|
|
67
|
+
content: [
|
|
68
|
+
{
|
|
69
|
+
type: 'text',
|
|
70
|
+
text: JSON.stringify({ id, error: 'Not found' })
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const data = await response.json();
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: JSON.stringify(data)
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
async function main() {
|
|
86
|
+
const transport = new StdioServerTransport();
|
|
87
|
+
await server.connect(transport);
|
|
88
|
+
}
|
|
89
|
+
main().catch((err) => {
|
|
90
|
+
console.error(err);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@somebeach/a2abench-mcp",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"mcpName": "io.github.khalidsaidi/a2abench",
|
|
7
|
+
"bin": {
|
|
8
|
+
"a2abench-mcp": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "tsx src/cli.ts",
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"lint": "echo 'lint not configured'",
|
|
18
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
19
|
+
"test": "echo 'no tests'"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
23
|
+
"dotenv": "^16.4.5",
|
|
24
|
+
"zod": "^3.23.8"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.11.0",
|
|
28
|
+
"tsx": "^4.7.0",
|
|
29
|
+
"typescript": "^5.4.0"
|
|
30
|
+
}
|
|
31
|
+
}
|