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

* Updated architecture.md

* Refactor/renamed sampling-request.ts to get-sampling-request.ts

* In tools/index.ts
  - sorted presenation order
This commit is contained in:
cliffhall
2025-12-10 16:58:25 -05:00
parent 7acadf4ac9
commit 48bf94a728
4 changed files with 16 additions and 19 deletions

View File

@@ -7,7 +7,7 @@ import {
import { z } from "zod";
// Tool input schema
const SamplingRequestSchema = z.object({
const GetSamplingRequestSchema = z.object({
prompt: z.string().describe("The prompt to send to the LLM"),
maxTokens: z
.number()
@@ -16,34 +16,31 @@ const SamplingRequestSchema = z.object({
});
// Tool configuration
const name = "sampling-request";
const name = "get-sampling-request";
const config = {
title: "Sampling Request Tool",
description: "Sends the Client a Request for LLM Sampling",
inputSchema: SamplingRequestSchema,
title: "Get Sampling Request Tool",
description: "Server Sends the Client a Request for LLM Sampling",
inputSchema: GetSamplingRequestSchema,
};
/**
* Registers the 'sampling-request' tool within the provided McpServer instance.
*
* Allows the server to handle sampling requests by parsing input arguments,
* generating a sampling request for an LLM, and returning the result to the client.
* Registers the 'get-sampling-request' tool within the provided McpServer instance.
*
* The registered tool performs the following operations:
* - Validates incoming arguments using `SampleLLMSchema`.
* - Constructs a request object using provided prompt and maximum tokens.
* - Constructs a `sampling/createMessage` request object using provided prompt and maximum tokens.
* - Sends the request to the server for sampling.
* - Formats and returns the sampling result content to the client.
*
* @param {McpServer} server - The instance of the MCP server where the tool
* will be registered.
*/
export const registerSamplingRequestTool = (server: McpServer) => {
export const registerGetSamplingRequestTool = (server: McpServer) => {
server.registerTool(
name,
config,
async (args, extra): Promise<CallToolResult> => {
const validatedArgs = SamplingRequestSchema.parse(args);
const validatedArgs = GetSamplingRequestSchema.parse(args);
const { prompt, maxTokens } = validatedArgs;
// Create the sampling request

View File

@@ -12,7 +12,7 @@ const GetSumSchema = z.object({
const name = "get-sum";
const config = {
title: "Get Sum Tool",
description: "Gets the sum of two numbers",
description: "Returns the sum of two numbers",
inputSchema: GetSumSchema,
};

View File

@@ -4,11 +4,11 @@ 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";
import { registerLongRunningOperationTool } from "./long-running-operation.js";
import { registerSamplingRequestTool } from "./sampling-request.js";
import { registerToggleLoggingTool } from "./toggle-logging.js";
import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates.js";
@@ -22,11 +22,11 @@ export const registerTools = (server: McpServer) => {
registerGetEnvTool(server);
registerGetResourceLinksTool(server);
registerGetResourceReferenceTool(server);
registerGetSamplingRequestTool(server);
registerGetStructuredContentTool(server);
registerGetSumTool(server);
registerGetTinyImageTool(server);
registerLongRunningOperationTool(server);
registerSamplingRequestTool(server);
registerToggleLoggingTool(server);
registerToggleSubscriberUpdatesTool(server);
};