mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-02-19 11:54:58 -05:00
[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:
@@ -52,7 +52,7 @@ src/everything
|
||||
│ ├── get-structured-content.ts
|
||||
│ ├── get-sum.ts
|
||||
│ ├── long-running-operation.ts
|
||||
│ ├── sampling-request.ts
|
||||
│ ├── get-sampling-request.ts
|
||||
│ ├── toggle-logging.ts
|
||||
│ └── toggle-subscriber-updates.ts
|
||||
└── package.json
|
||||
@@ -104,6 +104,8 @@ At `src/everything`:
|
||||
- Registers a `get-resource-links` tool that returns an intro `text` block followed by multiple `resource_link` items.
|
||||
- get-resource-reference.ts
|
||||
- Registers a `get-resource-reference` tool that returns a reference for a selected dynamic resource.
|
||||
- get-sampling-request.ts
|
||||
- Registers a `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
|
||||
@@ -112,8 +114,6 @@ At `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`.
|
||||
- sampling-request.ts
|
||||
- Registers a `sampling-request` tool that sends a `sampling/createMessage` request to the client/LLM and returns the sampling result.
|
||||
- toggle-logging.ts
|
||||
- Registers a `toggle-logging` tool, which starts or stops simulated logging for the invoking session.
|
||||
- toggle-subscriber-updates.ts
|
||||
@@ -198,11 +198,11 @@ At `src/everything`:
|
||||
- `get-env` (tools/get-env.ts): Returns all environment variables from the running process as pretty-printed JSON text.
|
||||
- `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`.
|
||||
- `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.
|
||||
- `sampling-request` (tools/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.
|
||||
- `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.
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user