mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-19 08:43:28 +02:00
[WIP] Refactor everything server to be more modular and use recommended APIs.
Finalized Roots list changed handling and initial request. Final fit and finish work.
* Updated architecture.md
- Added links to other docs
- Refactor/extracted sections into extension.md, features.md, how-it-works.md, startup.md, and structure.md
* Removed everything.ts
- all features are ported
* In roots.ts
- refactor/renaned setRootsListChangedHandler to syncRoots
- refactor handler logic to requestRoots function
- Calls for roots list directly to get initial list
* In server/index.ts
- import setRootsListChangedHandler
- in clientConnected callback
- call setRootsListChangedHandler passing server and sessionId
* In sse.ts, stdio.ts, and streamableHttp.ts
- update inline and function docs
* In index.ts,
- updated usage output
* In server/index.ts
- refactor/extracted readInstructions to resources/index.ts
- defined ServerFactoryResponse response type
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { registerResourceTemplates } from "./templates.js";
|
||||
import { registerFileResources } from "./files.js";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname, join } from "path";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
/**
|
||||
* Register the resources with the MCP server.
|
||||
@@ -10,3 +13,24 @@ export const registerResources = (server: McpServer) => {
|
||||
registerResourceTemplates(server);
|
||||
registerFileResources(server);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads the server instructions from the corresponding markdown file.
|
||||
* Attempts to load the content of the file located in the `docs` directory.
|
||||
* If the file cannot be loaded, an error message is returned instead.
|
||||
*
|
||||
* @return {string} The content of the server instructions file, or an error message if reading fails.
|
||||
*/
|
||||
export function readInstructions(): string {
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const filePath = join(__dirname, "..", "docs", "instructions.md");
|
||||
let instructions;
|
||||
|
||||
try {
|
||||
instructions = readFileSync(filePath, "utf-8");
|
||||
} catch (e) {
|
||||
instructions = "Server instructions not loaded: " + e;
|
||||
}
|
||||
return instructions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user