Skip to content

Commit 439ea65

Browse files
committed
quick command to download the language docs for local grepping
1 parent 93d734b commit 439ea65

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

mcp/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ node_modules
1515

1616
#!.yarn/cache
1717
.pnp.*
18+
.cache

mcp/server.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
22
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
33
import { z } from "zod";
44
import { execFileSync, ExecFileSyncOptions } from "child_process";
5+
import * as fs from "fs";
6+
import * as path from "path";
57

68
// Create an MCP server
79
const server = new McpServer({
@@ -108,9 +110,57 @@ server.tool(
108110
}
109111
);
110112

113+
server.tool(
114+
"language_docs_file_path",
115+
{},
116+
{
117+
destructiveHint: false,
118+
idempotentHint: true,
119+
readOnlyHint: true,
120+
title: `Gets the path to a markdown file containing the full language docs for ReScript the language, including examples.
121+
122+
- **Always** use this to grep or search as needed when you have questions about ReScript the language.`,
123+
},
124+
async () => {
125+
try {
126+
const cacheDir = path.resolve(__dirname, ".cache");
127+
const docsFileName = "rescript-lang-docs-12.0.0.md";
128+
const docsFilePath = path.join(cacheDir, docsFileName);
129+
130+
if (!fs.existsSync(cacheDir)) {
131+
fs.mkdirSync(cacheDir, { recursive: true });
132+
}
133+
134+
if (!fs.existsSync(docsFilePath)) {
135+
const res = await fetch(
136+
"https://rescript-lang.org/llms/manual/v12.0.0/llm-full.txt"
137+
);
138+
const text = await res.text();
139+
fs.writeFileSync(docsFilePath, text);
140+
}
141+
142+
return {
143+
content: [{ type: "text", text: docsFilePath }],
144+
};
145+
} catch (e) {
146+
return {
147+
content: [
148+
{ type: "text", text: `Error getting language docs file path: ${e}` },
149+
],
150+
};
151+
}
152+
}
153+
);
154+
111155
// Main function to start the server
112156
async function main() {
113157
try {
158+
// Clear the cache directory
159+
fs.rmSync(path.resolve(__dirname, ".cache"), {
160+
recursive: true,
161+
force: true,
162+
});
163+
114164
// Start receiving messages on stdin and sending messages on stdout
115165
const transport = new StdioServerTransport();
116166
await server.connect(transport);

0 commit comments

Comments
 (0)