From 339e056ea0cbe864a712da73a183384229854bc9 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Thu, 11 Dec 2025 17:39:25 -0500 Subject: [PATCH] [WIP] Refactor everything server to be more modular and use recommended APIs. * Updated architecture.md * Refactor/renamed get-sampling-request.ts to trigger-sampling-request.ts - use trigger instead of get throughout * In tools/index.ts - sorted display order --- src/everything/docs/architecture.md | 10 +++++----- src/everything/tools/index.ts | 4 ++-- ...ng-request.ts => trigger-sampling-request.ts} | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) rename src/everything/tools/{get-sampling-request.ts => trigger-sampling-request.ts} (80%) diff --git a/src/everything/docs/architecture.md b/src/everything/docs/architecture.md index b2e5fb71..525909d4 100644 --- a/src/everything/docs/architecture.md +++ b/src/everything/docs/architecture.md @@ -54,9 +54,9 @@ src/everything │ ├── get-sum.ts │ ├── gzip-file-as-resource.ts │ ├── long-running-operation.ts -│ ├── get-sampling-request.ts │ ├── toggle-logging.ts -│ └── toggle-subscriber-updates.ts +│ ├── toggle-subscriber-updates.ts +│ └── trigger-sampling-request.ts └── package.json ``` @@ -115,8 +115,8 @@ At `src/everything`: - `GZIP_MAX_FETCH_SIZE` (bytes, default 10 MiB) - `GZIP_MAX_FETCH_TIME_MILLIS` (ms, default 30000) - `GZIP_ALLOWED_DOMAINS` (comma-separated allowlist; empty means all domains allowed) - - get-sampling-request.ts - - Registers a `sampling-request` tool that sends a `sampling/createMessage` request to the client/LLM and returns the sampling result. + - trigger-sampling-request.ts + - Registers a `trigger-sampling-request` tool that sends a `sampling/createMessage` request to the client/LLM and returns the sampling result. - get-structured-content.ts - Registers a `get-structured-content` tool that demonstrates structuredContent block responses. - get-sum.ts @@ -210,13 +210,13 @@ At `src/everything`: - `get-resource-links` (tools/get-resource-links.ts): Returns an intro `text` block followed by multiple `resource_link` items. For a requested `count` (1–10), alternates between dynamic Text and Blob resources using URIs from `resources/templates.ts`. - `get-resource-reference` (tools/get-resource-reference.ts): Accepts `resourceType` (`text` or `blob`) and `resourceId` (positive integer). Returns a concrete `resource` content block (with its `uri`, `mimeType`, and data) with surrounding explanatory `text`. - `gzip-file-as-resource` (tools/gzip-file-as-resource.ts): Accepts a `name` and `data` (URL or data URI), fetches the data subject to size/time/domain constraints, compresses it, registers it as a session resource at `demo://resource/session/` with `mimeType: application/gzip`, and returns either a `resource_link` (default) or an inline `resource` depending on `outputType`. - - `get-sampling-request` (tools/get-sampling-request.ts): Issues a `sampling/createMessage` request to the client/LLM using provided `prompt` and optional generation controls; returns the LLM’s response payload. - `get-structured-content` (tools/get-structured-content.ts): Demonstrates structured responses. Accepts `location` input and returns both backward‑compatible `content` (a `text` block containing JSON) and `structuredContent` validated by an `outputSchema` (temperature, conditions, humidity). - `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, random‑leveled logging for the invoking session. Respects the client’s 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 LLM’s response payload. - Prompts diff --git a/src/everything/tools/index.ts b/src/everything/tools/index.ts index 7ad57eb1..1cbedb9d 100644 --- a/src/everything/tools/index.ts +++ b/src/everything/tools/index.ts @@ -4,7 +4,6 @@ import { registerEchoTool } from "./echo.js"; import { registerGetEnvTool } from "./get-env.js"; import { registerGetResourceLinksTool } from "./get-resource-links.js"; import { registerGetResourceReferenceTool } from "./get-resource-reference.js"; -import { registerGetSamplingRequestTool } from "./get-sampling-request.js"; import { registerGetStructuredContentTool } from "./get-structured-content.js"; import { registerGetSumTool } from "./get-sum.js"; import { registerGetTinyImageTool } from "./get-tiny-image.js"; @@ -12,6 +11,7 @@ import { registerGZipFileAsResourceTool } from "./gzip-file-as-resource.js"; import { registerLongRunningOperationTool } from "./long-running-operation.js"; import { registerToggleLoggingTool } from "./toggle-logging.js"; import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates.js"; +import { registerTriggerSamplingRequestTool } from "./trigger-sampling-request.js"; /** * Register the tools with the MCP server. @@ -23,7 +23,6 @@ export const registerTools = (server: McpServer) => { registerGetEnvTool(server); registerGetResourceLinksTool(server); registerGetResourceReferenceTool(server); - registerGetSamplingRequestTool(server); registerGetStructuredContentTool(server); registerGetSumTool(server); registerGetTinyImageTool(server); @@ -31,4 +30,5 @@ export const registerTools = (server: McpServer) => { registerLongRunningOperationTool(server); registerToggleLoggingTool(server); registerToggleSubscriberUpdatesTool(server); + registerTriggerSamplingRequestTool(server); }; diff --git a/src/everything/tools/get-sampling-request.ts b/src/everything/tools/trigger-sampling-request.ts similarity index 80% rename from src/everything/tools/get-sampling-request.ts rename to src/everything/tools/trigger-sampling-request.ts index 7c4a2295..fb8ee33e 100644 --- a/src/everything/tools/get-sampling-request.ts +++ b/src/everything/tools/trigger-sampling-request.ts @@ -7,7 +7,7 @@ import { import { z } from "zod"; // Tool input schema -const GetSamplingRequestSchema = z.object({ +const TriggerSamplingRequestSchema = z.object({ prompt: z.string().describe("The prompt to send to the LLM"), maxTokens: z .number() @@ -16,15 +16,15 @@ const GetSamplingRequestSchema = z.object({ }); // Tool configuration -const name = "get-sampling-request"; +const name = "trigger-sampling-request"; const config = { - title: "Get Sampling Request Tool", - description: "Server Sends the Client a Request for LLM Sampling", - inputSchema: GetSamplingRequestSchema, + title: "Trigger Sampling Request Tool", + description: "Trigger a Request from the Server for LLM Sampling", + inputSchema: TriggerSamplingRequestSchema, }; /** - * Registers the 'get-sampling-request' tool within the provided McpServer instance. + * Registers the 'trigger-sampling-request' tool within the provided McpServer instance. * * The registered tool performs the following operations: * - Validates incoming arguments using `SampleLLMSchema`. @@ -35,12 +35,12 @@ const config = { * @param {McpServer} server - The instance of the MCP server where the tool * will be registered. */ -export const registerGetSamplingRequestTool = (server: McpServer) => { +export const registerTriggerSamplingRequestTool = (server: McpServer) => { server.registerTool( name, config, async (args, extra): Promise => { - const validatedArgs = GetSamplingRequestSchema.parse(args); + const validatedArgs = TriggerSamplingRequestSchema.parse(args); const { prompt, maxTokens } = validatedArgs; // Create the sampling request