[WIP] Refactor everything server to be more modular and use recommended APIs.

* Updated docs

* Refactor/renamed toggle-logging.ts to toggle-simulated-logging.ts
  - refactor/renamed registerToggleLoggingTool to registerToggleSimulatedLoggingTool
This commit is contained in:
cliffhall
2025-12-13 10:59:35 -05:00
parent 19e588bdcb
commit f561f70002
5 changed files with 15 additions and 18 deletions

View File

@@ -19,7 +19,7 @@
- `get-sum` (tools/get-sum.ts): For two numbers `a` and `b` calculates and returns their sum. Uses Zod to validate inputs.
- `get-tiny-image` (tools/get-tiny-image.ts): Returns a tiny PNG MCP logo as an `image` content item with brief descriptive text before and after.
- `long-running-operation` (tools/long-running-operation.ts): Simulates a multi-step operation over a given `duration` and number of `steps`; reports progress via `notifications/progress` when a `progressToken` is provided by the client.
- `toggle-logging` (tools/toggle-logging.ts): Starts or stops simulated, randomleveled logging for the invoking session. Respects the clients selected minimum logging level.
- `toggle-simulated-logging` (tools/toggle-simulated-logging.ts): Starts or stops simulated, randomleveled logging for the invoking session. Respects the clients selected minimum logging level.
- `toggle-subscriber-updates` (tools/toggle-subscriber-updates.ts): Starts or stops simulated resource update notifications for URIs the invoking session has subscribed to.
- `trigger-sampling-request` (tools/trigger-sampling-request.ts): Issues a `sampling/createMessage` request to the client/LLM using provided `prompt` and optional generation controls; returns the LLMs response payload.
@@ -47,5 +47,5 @@
## Simulated Logging
- Simulated logging is available but off by default.
- Use the `toggle-logging` tool to start/stop periodic log messages of varying levels (debug, info, notice, warning, error, critical, alert, emergency) per session.
- Use the `toggle-simulated-logging` tool to start/stop periodic log messages of varying levels (debug, info, notice, warning, error, critical, alert, emergency) per session.
- Clients can control the minimum level they receive via the standard MCP `logging/setLevel` request.

View File

@@ -30,5 +30,5 @@ Each client manages its own resource subscriptions and receives notifications on
### Module: `server/logging.ts`
- Periodically sends randomized log messages at different levels. Messages can include the session ID for clarity during demos.
- Started/stopped on demand via the `toggle-logging` tool, which calls `beginSimulatedLogging(server, sessionId?)` and `stopSimulatedLogging(sessionId?)`. Note that transport disconnect triggers `cleanup()` which also stops any active intervals.
- Started/stopped on demand via the `toggle-simulated-logging` tool, which calls `beginSimulatedLogging(server, sessionId?)` and `stopSimulatedLogging(sessionId?)`. Note that transport disconnect triggers `cleanup()` which also stops any active intervals.
- Uses `server.sendLoggingMessage({ level, data }, sessionId?)` so that the clients configured minimum logging level is respected by the SDK.

View File

@@ -29,8 +29,7 @@ src/everything
├── server
│ ├── index.ts
│ ├── logging.ts
── roots.ts
│ └── everything.ts
── roots.ts
├── tools
│ ├── index.ts
│ ├── echo.ts
@@ -44,7 +43,7 @@ src/everything
│ ├── get-tiny-image.ts
│ ├── gzip-file-as-resource.ts
│ ├── long-running-operation.ts
│ ├── toggle-logging.ts
│ ├── toggle-simulated-logging.ts
│ ├── toggle-subscriber-updates.ts
│ ├── trigger-elicitation-request.ts
│ └── trigger-sampling-request.ts
@@ -113,11 +112,9 @@ src/everything
- `index.ts`
- Server factory that creates an `McpServer` with declared capabilities, loads server instructions, and registers tools, prompts, and resources.
- Sets resource subscription handlers via `setSubscriptionHandlers(server)`.
- Exposes `{ server, cleanup }` to the chosen transport. Cleanup stops any running intervals in the server when the transport disconencts.
- Exposes `{ server, cleanup }` to the chosen transport. Cleanup stops any running intervals in the server when the transport disconnects.
- `logging.ts`
- Implements simulated logging. Periodically sends randomized log messages at various levels to the connected client session. Started/stopped on demand via a dedicated tool.
- `everything.ts`
- A full “reference/monolith” implementation demonstrating most MCP features. Not the default path used by the transports in this package.
### `tools/`
@@ -156,8 +153,8 @@ src/everything
- Registers a `get-tiny-image` tool, which returns a tiny PNG MCP logo as an `image` content item, along with surrounding descriptive `text` items.
- `long-running-operation.ts`
- Registers a `long-running-operation` tool that simulates a long-running task over a specified `duration` (seconds) and number of `steps`; emits `notifications/progress` updates when the client supplies a `progressToken`.
- `toggle-logging.ts`
- Registers a `toggle-logging` tool, which starts or stops simulated logging for the invoking session.
- `toggle-simulated-logging.ts`
- Registers a `toggle-simulated-logging` tool, which starts or stops simulated logging for the invoking session.
- `toggle-subscriber-updates.ts`
- Registers a `toggle-subscriber-updates` tool, which starts or stops simulated resource subscription update checks for the invoking session.

View File

@@ -10,7 +10,7 @@ import { registerGetSumTool } from "./get-sum.js";
import { registerGetTinyImageTool } from "./get-tiny-image.js";
import { registerGZipFileAsResourceTool } from "./gzip-file-as-resource.js";
import { registerLongRunningOperationTool } from "./long-running-operation.js";
import { registerToggleLoggingTool } from "./toggle-logging.js";
import { registerToggleSimulatedLoggingTool } from "./toggle-simulated-logging.js";
import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates.js";
import { registerTriggerElicitationRequestTool } from "./trigger-elicitation-request.js";
import { registerTriggerSamplingRequestTool } from "./trigger-sampling-request.js";
@@ -31,7 +31,7 @@ export const registerTools = (server: McpServer) => {
registerGetTinyImageTool(server);
registerGZipFileAsResourceTool(server);
registerLongRunningOperationTool(server);
registerToggleLoggingTool(server);
registerToggleSimulatedLoggingTool(server);
registerToggleSubscriberUpdatesTool(server);
registerTriggerElicitationRequestTool(server);
registerTriggerSamplingRequestTool(server);

View File

@@ -6,10 +6,10 @@ import {
} from "../server/logging.js";
// Tool configuration
const name = "toggle-logging";
const name = "toggle-simulated-logging";
const config = {
title: "Toggle Logging",
description: "Toggles simulated logging on or off.",
title: "Toggle Simulated Logging",
description: "Toggles simulated, random-leveled logging on or off.",
inputSchema: {},
};
@@ -17,7 +17,7 @@ const config = {
const clients: Set<string | undefined> = new Set<string | undefined>();
/**
* Registers the `toggle-subscriber-updates` tool with the provided MCP server.
* Registers the `toggle-simulated-logging` tool with the provided MCP server.
*
* The registered tool enables or disables the sending of periodic, random-leveled
* logging messages the connected client.
@@ -28,7 +28,7 @@ const clients: Set<string | undefined> = new Set<string | undefined>();
*
* @param {McpServer} server - The server instance to which the tool is registered.
*/
export const registerToggleLoggingTool = (server: McpServer) => {
export const registerToggleSimulatedLoggingTool = (server: McpServer) => {
server.registerTool(
name,
config,