@0xmonaco/mcp-server 0.1.1 → 0.3.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/CHANGELOG.md +7 -11
- package/bin/cli.js +38 -35
- package/package.json +2 -2
- package/src/connect.js +37 -37
- package/src/index.js +41 -41
- package/src/initialize.js +6 -6
- package/src/search.d.ts +1 -3
- package/src/search.js +104 -104
- package/src/tools/helpers.d.ts +5 -16
- package/src/tools/helpers.js +241 -241
- package/src/tools/index.d.ts +1 -4
- package/src/tools/index.js +175 -175
- package/src/tools/zod.d.ts +2 -9
- package/src/tools/zod.js +176 -176
- package/src/tools.json +6 -6
- package/src/utils.d.ts +3 -12
- package/src/utils.js +52 -52
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
# @0xmonaco/mcp-server
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- ce9ff98: Initial 0.1.0 release - Early development version
|
|
3
|
+
## 0.3.0
|
|
8
4
|
|
|
9
|
-
##
|
|
5
|
+
## 0.1.5
|
|
10
6
|
|
|
11
|
-
###
|
|
7
|
+
### Patch Changes
|
|
12
8
|
|
|
13
|
-
-
|
|
9
|
+
- 5afd153: Release v0.1.5
|
|
14
10
|
|
|
15
|
-
## 1.
|
|
11
|
+
## 0.1.1
|
|
16
12
|
|
|
17
|
-
###
|
|
13
|
+
### Patch Changes
|
|
18
14
|
|
|
19
|
-
-
|
|
15
|
+
- ce9ff98: Initial 0.1.0 release - Early development version
|
package/bin/cli.js
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { fileURLToPath } from
|
|
4
|
-
import { dirname, resolve } from
|
|
5
|
-
import { spawn } from
|
|
6
|
-
import { createRequire } from
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
7
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = dirname(__filename);
|
|
10
10
|
const require = createRequire(import.meta.url);
|
|
11
11
|
|
|
12
12
|
// Path to the main MCP server
|
|
13
|
-
const scriptPath = resolve(__dirname,
|
|
13
|
+
const scriptPath = resolve(__dirname, "../src/index.js");
|
|
14
14
|
|
|
15
15
|
try {
|
|
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
|
-
|
|
16
|
+
// Check if the built files exist
|
|
17
|
+
require.resolve(scriptPath);
|
|
18
|
+
|
|
19
|
+
// Execute the server
|
|
20
|
+
const server = spawn("node", [scriptPath], {
|
|
21
|
+
stdio: "inherit",
|
|
22
|
+
shell: false,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
server.on("error", (err) => {
|
|
26
|
+
console.error("Failed to start server:", err);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Handle clean shutdown
|
|
31
|
+
const cleanup = () => {
|
|
32
|
+
if (!server.killed) {
|
|
33
|
+
server.kill();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
process.on("SIGINT", cleanup);
|
|
38
|
+
process.on("SIGTERM", cleanup);
|
|
39
|
+
process.on("exit", cleanup);
|
|
41
40
|
} catch (error) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
console.error(
|
|
42
|
+
"Error: Server files not found. The package may not be built correctly.",
|
|
43
|
+
);
|
|
44
|
+
console.error(
|
|
45
|
+
"Please try reinstalling the package or contact the maintainers.",
|
|
46
|
+
);
|
|
47
|
+
console.error(error);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server for the Monaco documentation",
|
|
6
6
|
"engines": {
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"start": "tsx src/index.js",
|
|
22
|
-
"test": "jest"
|
|
22
|
+
"test": "jest --pass-with-no-tests"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/connect.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
var __awaiter =
|
|
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
|
-
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
34
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
35
35
|
export function connectServer(server) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const transport = new StdioServerTransport();
|
|
38
|
+
yield server.connect(transport);
|
|
39
|
+
console.error("MCP Server running on stdio");
|
|
40
|
+
});
|
|
41
41
|
}
|
package/src/index.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
1
|
var __awaiter =
|
|
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
|
-
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
34
|
import { connectServer } from "./connect.js";
|
|
35
35
|
import { initialize } from "./initialize.js";
|
|
36
36
|
import { createSearchTool } from "./search.js";
|
|
37
37
|
import { createTools } from "./tools/index.js";
|
|
38
38
|
function main() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const server = initialize();
|
|
41
|
+
const existingTools = new Set();
|
|
42
|
+
yield createSearchTool(server);
|
|
43
|
+
yield createTools(server, existingTools);
|
|
44
|
+
yield connectServer(server);
|
|
45
|
+
});
|
|
46
46
|
}
|
|
47
47
|
main().catch((error) => {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
console.error("Fatal error in trying to initialize MCP server: ", error);
|
|
49
|
+
process.exit(1);
|
|
50
50
|
});
|
package/src/initialize.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { SERVER_NAME, SERVER_VERSION } from "../settings.js";
|
|
3
3
|
export function initialize() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
console.error("Initializing MCP Server...");
|
|
5
|
+
const server = new McpServer({
|
|
6
|
+
name: SERVER_NAME,
|
|
7
|
+
version: SERVER_VERSION,
|
|
8
|
+
});
|
|
9
|
+
return server;
|
|
10
10
|
}
|
package/src/search.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { InitializationConfiguration } from "./types.js";
|
|
3
|
-
export declare function fetchSearchConfigurationAndTools(
|
|
4
|
-
subdomain: string,
|
|
5
|
-
): Promise<InitializationConfiguration>;
|
|
3
|
+
export declare function fetchSearchConfigurationAndTools(subdomain: string): Promise<InitializationConfiguration>;
|
|
6
4
|
export declare function createSearchTool(server: McpServer): Promise<void>;
|
package/src/search.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
var __awaiter =
|
|
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
|
-
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
34
|
import axios from "axios";
|
|
35
35
|
import { TrieveSDK } from "trieve-ts-sdk";
|
|
36
36
|
import { z } from "zod";
|
|
@@ -39,80 +39,80 @@ import { SERVER_URL } from "./config.readonly.js";
|
|
|
39
39
|
import { formatErr, throwOnAxiosError } from "./utils.js";
|
|
40
40
|
const DEFAULT_BASE_URL = "https://api.mintlifytrieve.com";
|
|
41
41
|
export function fetchSearchConfigurationAndTools(subdomain) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
try {
|
|
44
|
+
const response = yield axios.get(
|
|
45
|
+
`${SERVER_URL}/api/mcp/config/${subdomain}`,
|
|
46
|
+
{
|
|
47
|
+
validateStatus() {
|
|
48
|
+
return true;
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
throwOnAxiosError(response, "Failed to fetch MCP config");
|
|
53
|
+
return response.data;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
formatErr(err).replace(
|
|
57
|
+
"Request failed with status code 404",
|
|
58
|
+
`${subdomain} not found`,
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
63
|
}
|
|
64
64
|
function search(query, config) {
|
|
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
|
-
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const trieve = new TrieveSDK({
|
|
67
|
+
apiKey: config.trieveApiKey,
|
|
68
|
+
datasetId: config.trieveDatasetId,
|
|
69
|
+
baseUrl: DEFAULT_BASE_URL,
|
|
70
|
+
});
|
|
71
|
+
const data = yield trieve.autocomplete({
|
|
72
|
+
page_size: 10,
|
|
73
|
+
query,
|
|
74
|
+
search_type: "fulltext",
|
|
75
|
+
extend_results: true,
|
|
76
|
+
score_threshold: 1,
|
|
77
|
+
});
|
|
78
|
+
if (data.chunks === undefined || data.chunks.length === 0) {
|
|
79
|
+
throw new Error("No results found");
|
|
80
|
+
}
|
|
81
|
+
return data.chunks.map((result) => {
|
|
82
|
+
const { chunk } = result;
|
|
83
|
+
// TODO: Append custom domain to the link
|
|
84
|
+
return {
|
|
85
|
+
title: chunk.metadata.title,
|
|
86
|
+
content: chunk.chunk_html,
|
|
87
|
+
link: chunk.link,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
91
|
}
|
|
92
92
|
export function createSearchTool(server) {
|
|
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
|
-
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const config = yield fetchSearchConfigurationAndTools(SUBDOMAIN);
|
|
95
|
+
server.tool(
|
|
96
|
+
"search",
|
|
97
|
+
`Search across the ${config.name} documentation to fetch relevant context for a given query`,
|
|
98
|
+
{
|
|
99
|
+
query: z.string(),
|
|
100
|
+
},
|
|
101
|
+
(_a) =>
|
|
102
|
+
__awaiter(this, [_a], void 0, function* ({ query }) {
|
|
103
|
+
const results = yield search(query, config);
|
|
104
|
+
const content = results.map((result) => {
|
|
105
|
+
const { title, content, link } = result;
|
|
106
|
+
const text = `Title: ${title}\nContent: ${content}\nLink: ${link}`;
|
|
107
|
+
return {
|
|
108
|
+
type: "text",
|
|
109
|
+
text,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
content,
|
|
114
|
+
};
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
118
|
}
|
package/src/tools/helpers.d.ts
CHANGED
|
@@ -6,22 +6,11 @@ import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
|
6
6
|
import { ServerParams, ToolWithEndpoint } from "../types.js";
|
|
7
7
|
import { NestedRecord, SimpleRecord } from "../utils.js";
|
|
8
8
|
export declare function convertStrToTitle(str: string): string;
|
|
9
|
-
export declare function findNextIteration(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
):
|
|
13
|
-
export declare function
|
|
14
|
-
spec: OpenAPI.Document,
|
|
15
|
-
): Endpoint<DataSchemaArray>[];
|
|
16
|
-
export declare function convertEndpointToTool(
|
|
17
|
-
endpoint: Endpoint<DataSchemaArray>,
|
|
18
|
-
): Omit<Tool, "inputSchema">;
|
|
19
|
-
export declare function getMcpToolsAndEndpointsFromOpenApiSpec(
|
|
20
|
-
spec: OpenAPI.Document,
|
|
21
|
-
): ToolWithEndpoint[];
|
|
22
|
-
export declare function getEndpointsFromOpenApi(
|
|
23
|
-
specification: OpenAPI.Document,
|
|
24
|
-
): Endpoint<DataSchemaArray>[];
|
|
9
|
+
export declare function findNextIteration(set: Set<string>, str: string): number;
|
|
10
|
+
export declare function getMcpEnabledEndpointsFromOpenApiSpec(spec: OpenAPI.Document): Endpoint<DataSchemaArray>[];
|
|
11
|
+
export declare function convertEndpointToTool(endpoint: Endpoint<DataSchemaArray>): Omit<Tool, "inputSchema">;
|
|
12
|
+
export declare function getMcpToolsAndEndpointsFromOpenApiSpec(spec: OpenAPI.Document): ToolWithEndpoint[];
|
|
13
|
+
export declare function getEndpointsFromOpenApi(specification: OpenAPI.Document): Endpoint<DataSchemaArray>[];
|
|
25
14
|
export declare function loadEnv(key: string): SimpleRecord;
|
|
26
15
|
export declare function convertSecurityParameterSection(
|
|
27
16
|
securityParameters: SecurityParameterGroup,
|