UNPKG

mcp-ts-template

Version:

A production-grade TypeScript template for building robust Model Context Protocol (MCP) servers, featuring built-in observability with OpenTelemetry, advanced error handling, comprehensive utilities, and a modular architecture.

47 lines 1.92 kB
/** * @fileoverview Defines the core logic, schemas, and types for the `echo` resource. * @module src/mcp-server/resources/echoResource/logic * @see {@link src/mcp-server/resources/echoResource/registration.ts} for the handler and registration logic. */ import { z } from "zod"; import { logger } from "../../../utils/index.js"; /** * Zod schema defining expected query parameters for the echo resource. */ export const EchoResourceQuerySchema = z.object({ message: z .string() .optional() .describe("Optional message to echo back in the response. If not provided, a default may be used or derived from the path."), }); /** * Processes the core logic for an echo resource request. * @param uri - The full URL object of the incoming resource request. * @param params - The validated query parameters for the request. * @param context - The request context, used for logging and tracing the operation. * @returns The data payload for the response. */ export async function echoResourceLogic(uri, params, context) { // The message can come from a query parameter or the path itself. // For a URI like `echo://my-message?param=1`, `hostname` is `my-message`. const messageFromPath = uri.hostname || uri.pathname.replace(/^\/+/g, ""); const messageToEcho = params.message || messageFromPath || "Default echo message"; logger.debug("Processing echo resource logic.", { ...context, resourceUri: uri.href, extractedMessage: messageToEcho, }); const responsePayload = { message: messageToEcho, timestamp: new Date().toISOString(), requestUri: uri.href, }; logger.debug("Echo resource processed successfully.", { ...context, responsePayloadSummary: { messageLength: responsePayload.message.length, }, }); return responsePayload; } //# sourceMappingURL=logic.js.map