[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
This commit is contained in:
cliffhall
2025-12-11 17:39:25 -05:00
parent 2afc618ccd
commit 339e056ea0
3 changed files with 15 additions and 15 deletions

View File

@@ -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` (110), 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/<name>` 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 LLMs response payload.
- `get-structured-content` (tools/get-structured-content.ts): Demonstrates structured responses. Accepts `location` input and returns both backwardcompatible `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, 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.
- Prompts

View File

@@ -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);
};

View File

@@ -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<CallToolResult> => {
const validatedArgs = GetSamplingRequestSchema.parse(args);
const validatedArgs = TriggerSamplingRequestSchema.parse(args);
const { prompt, maxTokens } = validatedArgs;
// Create the sampling request