-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp.ts
More file actions
42 lines (37 loc) · 1.21 KB
/
mcp.ts
File metadata and controls
42 lines (37 loc) · 1.21 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
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { fileURLToPath } from "bun";
import { execa } from "execa";
import { z } from "zod";
const rootDir = fileURLToPath(new URL("..", import.meta.url));
const $ = execa({ cwd: rootDir });
/**
* Model Context Protocol (MCP) server.
*
* @see https://modelcontextprotocol.org
* @see https://code.visualstudio.com/docs/copilot/chat/mcp-servers
*/
const server = new McpServer({
name: "React Starter Kit",
version: "0.0.0",
});
// This is just an example of a custom command that can be executed
// from the MCP client (e.g., VS Code, GitHub Copilot, etc.).
server.tool(
"eslint",
"Lint JavaScript and TypeScript files with ESLint",
{
filename: z.string(),
},
async function lint({ filename }) {
const cmd = await $`bun run eslint ${filename}`;
return {
content: [{ type: "text", text: cmd.stdout }],
};
},
);
// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
await server.connect(transport);