mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-18 15:54:09 +02:00
[WIP] Refactor everything server to be more modular and use recommended APIs.
* Added git-tiny-image.ts - registers a tool that returns a tiny MCP logo * In all other tools, updated function docs
This commit is contained in:
@@ -24,27 +24,33 @@ src/everything
|
|||||||
│ ├── logging.ts
|
│ ├── logging.ts
|
||||||
│ └── everything.ts
|
│ └── everything.ts
|
||||||
├── transports
|
├── transports
|
||||||
│ ├── stdio.ts
|
|
||||||
│ ├── sse.ts
|
│ ├── sse.ts
|
||||||
|
│ ├── stdio.ts
|
||||||
│ └── streamableHttp.ts
|
│ └── streamableHttp.ts
|
||||||
├── tools
|
├── tools
|
||||||
│ ├── index.ts
|
│ ├── index.ts
|
||||||
|
│ ├── add.ts
|
||||||
│ ├── echo.ts
|
│ ├── echo.ts
|
||||||
│ └── add.ts
|
│ ├── get-tiny-image.ts
|
||||||
|
│ ├── long-running-operation.ts
|
||||||
|
│ ├── print-env.ts
|
||||||
|
│ ├── sampling-request.ts
|
||||||
|
│ ├── toggle-logging.ts
|
||||||
|
│ └── toggle-subscriber-updates.ts
|
||||||
├── prompts
|
├── prompts
|
||||||
│ ├── index.ts
|
│ ├── index.ts
|
||||||
│ ├── simple.ts
|
|
||||||
│ ├── args.ts
|
│ ├── args.ts
|
||||||
│ ├── completions.ts
|
│ ├── completions.ts
|
||||||
|
│ ├── simple.ts
|
||||||
│ └── resource.ts
|
│ └── resource.ts
|
||||||
├── resources
|
├── resources
|
||||||
│ ├── index.ts
|
│ ├── index.ts
|
||||||
│ ├── templates.ts
|
|
||||||
│ ├── files.ts
|
│ ├── files.ts
|
||||||
│ └── subscriptions.ts
|
│ ├── subscriptions.ts
|
||||||
|
│ └── templates.ts
|
||||||
├── docs
|
├── docs
|
||||||
│ ├── server-instructions.md
|
│ ├── architecture.md
|
||||||
│ └── architecture.md
|
│ └── server-instructions.md
|
||||||
└── package.json
|
└── package.json
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -88,6 +94,8 @@ At `src/everything`:
|
|||||||
- Defines an `add` tool with a Zod input schema that sums two numbers `a` and `b` and returns the result.
|
- Defines an `add` tool with a Zod input schema that sums two numbers `a` and `b` and returns the result.
|
||||||
- echo.ts
|
- echo.ts
|
||||||
- Defines a minimal `echo` tool with a Zod input schema and returns `Echo: {message}`.
|
- Defines a minimal `echo` tool with a Zod input schema and returns `Echo: {message}`.
|
||||||
|
- get-tiny-image.ts
|
||||||
|
- Defines `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
|
- long-running-operation.ts
|
||||||
- Defines `long-running-operation`: simulates a long-running task over a specified `duration` (seconds) and number of `steps`; emits `notifications/progress` updates when the client supplies a `progressToken`.
|
- Defines `long-running-operation`: simulates a long-running task over a specified `duration` (seconds) and number of `steps`; emits `notifications/progress` updates when the client supplies a `progressToken`.
|
||||||
- print-env.ts
|
- print-env.ts
|
||||||
@@ -175,6 +183,7 @@ At `src/everything`:
|
|||||||
|
|
||||||
- `add` (tools/add.ts): Adds two numbers `a` and `b` and returns their sum. Uses Zod to validate inputs.
|
- `add` (tools/add.ts): Adds two numbers `a` and `b` and returns their sum. Uses Zod to validate inputs.
|
||||||
- `echo` (tools/echo.ts): Echoes the provided `message: string`. Uses Zod to validate inputs.
|
- `echo` (tools/echo.ts): Echoes the provided `message: string`. 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.
|
- `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.
|
||||||
- `print-env` (tools/print-env.ts): Returns all environment variables from the running process as pretty-printed JSON text.
|
- `print-env` (tools/print-env.ts): Returns all environment variables from the running process as pretty-printed JSON text.
|
||||||
- `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.
|
- `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.
|
||||||
|
|||||||
@@ -17,17 +17,17 @@ const config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a tool on the given server to handle addition operations.
|
* Registers the 'add' tool with the provided McpServer instance.
|
||||||
*
|
**
|
||||||
* @param {McpServer} server - The server instance where the addition tool will be registered.
|
|
||||||
*
|
|
||||||
* The registered tool processes input arguments, validates them using a predefined schema,
|
* The registered tool processes input arguments, validates them using a predefined schema,
|
||||||
* performs addition on two numeric values, and returns the result in a structured format.
|
* performs addition on two numeric values, and returns the result in a structured format.
|
||||||
*
|
*
|
||||||
* The tool expects input arguments to conform to a specific schema that includes two numeric properties, `a` and `b`.
|
* Expects input arguments to conform to a specific schema that includes two numeric properties, `a` and `b`.
|
||||||
* Validation is performed to ensure the input adheres to the expected structure before calculating the sum.
|
* Validation is performed to ensure the input adheres to the expected structure before calculating the sum.
|
||||||
*
|
*
|
||||||
* The result is returned as a Promise resolving to an object containing the computed sum in a text format.
|
* The result is returned as a Promise resolving to an object containing the computed sum in a text format.
|
||||||
|
*
|
||||||
|
* @param {McpServer} server - The server instance where the addition tool will be registered.
|
||||||
*/
|
*/
|
||||||
export const registerAddTool = (server: McpServer) => {
|
export const registerAddTool = (server: McpServer) => {
|
||||||
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
|
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ const config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the Echo Tool with the provided McpServer instance.
|
* Registers the 'echo' Tool with the provided McpServer instance.
|
||||||
*
|
*
|
||||||
* The Echo Tool validates input arguments using the EchoSchema and returns
|
* The registered tool validates input arguments using the EchoSchema and
|
||||||
* a response that echoes the message provided in the arguments.
|
* returns a response that echoes the message provided in the arguments.
|
||||||
*
|
*
|
||||||
* @param {McpServer} server - The server instance where the Echo Tool will be registered.
|
* @param {McpServer} server - The server instance where the Echo Tool will be registered.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
|
|||||||
47
src/everything/tools/get-tiny-image.ts
Normal file
47
src/everything/tools/get-tiny-image.ts
Normal file
File diff suppressed because one or more lines are too long
@@ -1,6 +1,7 @@
|
|||||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
import { registerAddTool } from "./add.js";
|
import { registerAddTool } from "./add.js";
|
||||||
import { registerEchoTool } from "./echo.js";
|
import { registerEchoTool } from "./echo.js";
|
||||||
|
import { registerGetTinyImageTool } from "./get-tiny-image.js";
|
||||||
import { registerLongRunningOperationTool } from "./long-running-operation.js";
|
import { registerLongRunningOperationTool } from "./long-running-operation.js";
|
||||||
import { registerPrintEnvTool } from "./print-env.js";
|
import { registerPrintEnvTool } from "./print-env.js";
|
||||||
import { registerSamplingRequestTool } from "./sampling-request.js";
|
import { registerSamplingRequestTool } from "./sampling-request.js";
|
||||||
@@ -14,6 +15,7 @@ import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates
|
|||||||
export const registerTools = (server: McpServer) => {
|
export const registerTools = (server: McpServer) => {
|
||||||
registerAddTool(server);
|
registerAddTool(server);
|
||||||
registerEchoTool(server);
|
registerEchoTool(server);
|
||||||
|
registerGetTinyImageTool(server);
|
||||||
registerLongRunningOperationTool(server);
|
registerLongRunningOperationTool(server);
|
||||||
registerPrintEnvTool(server);
|
registerPrintEnvTool(server);
|
||||||
registerSamplingRequestTool(server);
|
registerSamplingRequestTool(server);
|
||||||
|
|||||||
@@ -20,13 +20,14 @@ const config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a tool to demonstrate long-running operations on the server.
|
* Registers the 'long-running-operation' tool with the provided McpServer instance.
|
||||||
*
|
*
|
||||||
* This function defines and registers a tool with the provided server instance that performs a
|
* This function defines and registers a tool with the provided server instance that performs a
|
||||||
* long-running operation defined by a specific duration and number of steps. The progress
|
* long-running operation defined by a specific duration and number of steps. The progress
|
||||||
* of the operation is reported back to the client through notifications.
|
* of the operation is reported back to the client through notifications.
|
||||||
*
|
*
|
||||||
* The tool processes the operation in steps, with each step having equal duration.
|
* The registered tool processes the operation in steps, with each step having equal duration.
|
||||||
|
*
|
||||||
* Progress notifications are sent back to the client at each step, if a `progressToken`
|
* Progress notifications are sent back to the client at each step, if a `progressToken`
|
||||||
* is provided in the metadata. At the end of the operation, the tool returns a message
|
* is provided in the metadata. At the end of the operation, the tool returns a message
|
||||||
* indicating the completion of the operation, including the total duration and steps.
|
* indicating the completion of the operation, including the total duration and steps.
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ const config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the Echo Tool with the given MCP server. This tool, when invoked,
|
* Registers the 'print-env' tool with the given MCP server.
|
||||||
* retrieves and returns the environment variables of the current process
|
*
|
||||||
* as a JSON-formatted string encapsulated in a text response.
|
* The registered tool Retrieves and returns the environment variables
|
||||||
|
* of the current process as a JSON-formatted string encapsulated in a text response.
|
||||||
*
|
*
|
||||||
* @param {McpServer} server - The MCP server instance where the Echo Tool is to be registered.
|
* @param {McpServer} server - The MCP server instance where the Echo Tool is to be registered.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ const config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a sampling request tool within the given MCP server.
|
* Registers the 'sampling-request' tool within the provided McpServer instance.
|
||||||
*
|
*
|
||||||
* This tool allows the server to handle sampling requests by parsing input
|
* Allows the server to handle sampling requests by parsing input arguments,
|
||||||
* arguments, generating a sampling request for an LLM, and returning the
|
* generating a sampling request for an LLM, and returning the result to the client.
|
||||||
* result to the client.
|
|
||||||
*
|
*
|
||||||
* The registered tool performs the following operations:
|
* The registered tool performs the following operations:
|
||||||
* - Validates incoming arguments using `SampleLLMSchema`.
|
* - Validates incoming arguments using `SampleLLMSchema`.
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ const clients: Set<string | undefined> = new Set<string | undefined>();
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the `toggle-subscriber-updates` tool with the provided MCP server.
|
* Registers the `toggle-subscriber-updates` tool with the provided MCP server.
|
||||||
* This tool enables or disables sending of periodic, random-leveled logging
|
*
|
||||||
* messages the connected client.
|
* The registered tool enables or disables the sending of periodic, random-leveled
|
||||||
|
* logging messages the connected client.
|
||||||
*
|
*
|
||||||
* When invoked, it either starts or stops simulated logging based on the session's
|
* When invoked, it either starts or stops simulated logging based on the session's
|
||||||
* current state. If logging for the specified session is active, it will be stopped;
|
* current state. If logging for the specified session is active, it will be stopped;
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ const clients: Set<string | undefined> = new Set<string | undefined>();
|
|||||||
* This tool enables or disables simulated resource update notifications for a client.
|
* This tool enables or disables simulated resource update notifications for a client.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Toggles the state of the updates based on whether the session is already active.
|
* The registered tool toggles the state of the updates based on whether the session is already active.
|
||||||
* When enabled, the simulated resource updates are sent to the client at a regular interval.
|
* - When enabled, the simulated resource updates are sent to the client at a regular interval.
|
||||||
* When disabled, updates are stopped for the session.
|
* - When disabled, updates are stopped for the session.
|
||||||
*
|
*
|
||||||
* The response provides feedback indicating whether simulated updates were started or stopped,
|
* The response provides feedback indicating whether simulated updates were started or stopped,
|
||||||
* including the session ID.
|
* including the session ID.
|
||||||
|
|||||||
Reference in New Issue
Block a user