-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.ts
More file actions
69 lines (58 loc) · 1.99 KB
/
Copy pathmain.ts
File metadata and controls
69 lines (58 loc) · 1.99 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { cleanupRepository, initializeRepository } from "./repository.ts";
import { registerTools } from "./tools.ts";
import { registerResources } from "./resources.ts";
import denoConfig from "./deno.json" with { type: "json" };
/**
* FEP MCP Server
*
* An MCP server that provides access to Fediverse Enhancement Proposals (FEPs).
* On startup, it prepares a shared local cache of the FEP repository and
* exposes tools and resources for reading and searching FEP documents.
*/
const SERVER_NAME = "fep-mcp";
const SERVER_VERSION = denoConfig.version;
/**
* Main entry point for the FEP MCP server.
*/
async function main(): Promise<void> {
// Initialize the FEP repository
console.error(`${SERVER_NAME} v${SERVER_VERSION} starting...`);
try {
const repoPath = await initializeRepository();
console.error(`FEP repository cache ready at: ${repoPath}`);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.error(`Failed to initialize FEP repository: ${message}`);
Deno.exit(1);
}
// Create MCP server
const server = new McpServer({
name: SERVER_NAME,
version: SERVER_VERSION,
});
// Register tools and resources
registerTools(server);
registerResources(server);
// Set up stdio transport
const transport = new StdioServerTransport();
// Handle graceful shutdown
const shutdown = async () => {
console.error("Shutting down...");
await cleanupRepository();
Deno.exit(0);
};
Deno.addSignalListener("SIGINT", shutdown);
if (Deno.build.os !== "windows") {
Deno.addSignalListener("SIGTERM", shutdown);
}
// Connect and start serving
console.error("MCP server ready, waiting for connections...");
await server.connect(transport);
}
// Run the server
main().catch((error) => {
console.error("Fatal error:", error);
Deno.exit(1);
});