In src/everything:
* Refactor / move streamableHttp.ts, sse.ts, and stdio.ts to transports/
* Move everything.ts to server/ for reference
* Add server/index.js
- exports the createServer function
- import registerTools from tools/index.js
- in createServer()
- read instructions.md and include in ServerOptions for McpServer constructor
- construct McpServer instead of Server
- call registerTools, passing server
* Add tools/echo.ts
- define EchoSchema
- define tool config
- export addToolEcho function
- in addToolEcho()
- register handler for Echo tool
* Add tools/index.ts
- import addToolEcho
- export registerTools function
- in registerTools()
- call addToolEcho
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
import { registerTools } from "../tools/index.js";
|
|
import { dirname, join } from "path";
|
|
import { readFileSync } from "fs";
|
|
import { fileURLToPath } from "url";
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const instructions = readInstructions();
|
|
|
|
// Create the MCP resource server
|
|
export const createServer = () => {
|
|
const server = new McpServer(
|
|
{
|
|
name: "mcp-servers/everything",
|
|
title: "Everything Reference Server",
|
|
version: "2.0.0",
|
|
},
|
|
{
|
|
capabilities: {
|
|
tools: {},
|
|
logging: {},
|
|
prompts: {},
|
|
resources: {
|
|
subscribe: true,
|
|
}
|
|
},
|
|
instructions,
|
|
},
|
|
);
|
|
|
|
// Register the tools
|
|
registerTools(server);
|
|
|
|
return {
|
|
server,
|
|
cleanup: () => {},
|
|
startNotificationIntervals: (sessionId?: string) => {}
|
|
};
|
|
};
|
|
|
|
function readInstructions(): string {
|
|
let instructions;
|
|
|
|
try {
|
|
instructions = readFileSync(join(__dirname, "../instructions.md"), "utf-8");
|
|
} catch (e) {
|
|
instructions = "Server instructions not loaded: " + e;
|
|
}
|
|
return instructions;
|
|
}
|