mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-19 08:33:23 +02:00
* Adding dynamic resources
* Add server/index.js
- import registerResources from resources/index.js
- in createServer()
- call registerResources, passing server
* Add resources/dynamic.ts
- in addDynamicResources()
- define formatGmtTimestamp to create a time stamp to include in the resource text or encoded blob
- define parseIndex to ensure the index variable of the URI is a number
* Add resources/index.ts
- import addDynamicResources
- export registerResources function
- in registerResources()
- call addDynamicResources
* In package.json
- update the start commands to launch each of the transports properly
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
import { registerTools } from "../tools/index.js";
|
|
import { registerResources } from "../resources/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);
|
|
|
|
// Register the resources
|
|
registerResources(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;
|
|
}
|