mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-06-20 13:39:43 +02:00
b4a1c418bb
Add .oxfmtignore to skip generated bindings and wasm-pack output. Add npm format script, update DEVELOPMENT.md for Vite+ toolchain, and format all non-generated files with oxfmt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import { StreamableHTTPTransport } from "@hono/mcp";
|
|
import { serve } from "@hono/node-server";
|
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
import { Hono } from "hono";
|
|
import { registerFolderTools } from "./tools/folder.js";
|
|
import { registerHttpRequestTools } from "./tools/httpRequest.js";
|
|
import { registerToastTools } from "./tools/toast.js";
|
|
import { registerWindowTools } from "./tools/window.js";
|
|
import { registerWorkspaceTools } from "./tools/workspace.js";
|
|
import type { McpServerContext } from "./types.js";
|
|
|
|
export function createMcpServer(ctx: McpServerContext, port: number) {
|
|
console.log("Creating MCP server on port", port);
|
|
const mcpServer = new McpServer({
|
|
name: "yaak-mcp-server",
|
|
version: "0.1.0",
|
|
});
|
|
|
|
// Register all tools
|
|
registerToastTools(mcpServer, ctx);
|
|
registerHttpRequestTools(mcpServer, ctx);
|
|
registerFolderTools(mcpServer, ctx);
|
|
registerWindowTools(mcpServer, ctx);
|
|
registerWorkspaceTools(mcpServer, ctx);
|
|
|
|
const app = new Hono();
|
|
const transport = new StreamableHTTPTransport();
|
|
|
|
app.all("/mcp", async (c) => {
|
|
if (!mcpServer.isConnected()) {
|
|
// Connect the mcp with the transport
|
|
await mcpServer.connect(transport);
|
|
void ctx.yaak.toast.show({
|
|
message: `MCP Server connected`,
|
|
icon: "info",
|
|
color: "info",
|
|
timeout: 5000,
|
|
});
|
|
}
|
|
return transport.handleRequest(c);
|
|
});
|
|
|
|
const honoServer = serve(
|
|
{
|
|
port,
|
|
hostname: "127.0.0.1",
|
|
fetch: app.fetch,
|
|
},
|
|
(info) => {
|
|
console.log("Started MCP server on ", info.address);
|
|
void ctx.yaak.toast.show({
|
|
message: `MCP Server running on http://127.0.0.1:${info.port}`,
|
|
icon: "info",
|
|
color: "secondary",
|
|
timeout: 10000,
|
|
});
|
|
},
|
|
);
|
|
|
|
return {
|
|
server: mcpServer,
|
|
close: async () => {
|
|
await new Promise<void>((resolve, reject) => {
|
|
honoServer.close((err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
await mcpServer.close();
|
|
},
|
|
};
|
|
}
|