mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-20 12:55:36 +02:00
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
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
import { createServer } from "../server/index.js";
|
|
|
|
console.error("Starting default (STDIO) server...");
|
|
|
|
/**
|
|
* The main method
|
|
* - Initializes the StdioServerTransport, sets up the server,
|
|
* - Connects the transport to the server, invokes the `clientConnected` callback,
|
|
* - Handles cleanup on process exit.
|
|
*
|
|
* @return {Promise<void>} A promise that resolves when the main function has executed and the process exits.
|
|
*/
|
|
async function main(): Promise<void> {
|
|
const transport = new StdioServerTransport();
|
|
const { server, clientConnected, cleanup } = createServer();
|
|
|
|
// Connect transport to server and invoke clientConnected callback
|
|
await server.connect(transport);
|
|
clientConnected();
|
|
|
|
// Cleanup on exit
|
|
process.on("SIGINT", async () => {
|
|
await server.close();
|
|
cleanup();
|
|
process.exit(0);
|
|
});
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error("Server error:", error);
|
|
process.exit(1);
|
|
});
|