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.
* 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
|
||||
│ └── everything.ts
|
||||
├── transports
|
||||
│ ├── stdio.ts
|
||||
│ ├── sse.ts
|
||||
│ ├── stdio.ts
|
||||
│ └── streamableHttp.ts
|
||||
├── tools
|
||||
│ ├── index.ts
|
||||
│ ├── add.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
|
||||
│ ├── index.ts
|
||||
│ ├── simple.ts
|
||||
│ ├── args.ts
|
||||
│ ├── completions.ts
|
||||
│ ├── simple.ts
|
||||
│ └── resource.ts
|
||||
├── resources
|
||||
│ ├── index.ts
|
||||
│ ├── templates.ts
|
||||
│ ├── files.ts
|
||||
│ └── subscriptions.ts
|
||||
│ ├── subscriptions.ts
|
||||
│ └── templates.ts
|
||||
├── docs
|
||||
│ ├── server-instructions.md
|
||||
│ └── architecture.md
|
||||
│ ├── architecture.md
|
||||
│ └── server-instructions.md
|
||||
└── 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.
|
||||
- echo.ts
|
||||
- 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
|
||||
- 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
|
||||
@@ -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.
|
||||
- `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.
|
||||
- `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.
|
||||
|
||||
@@ -17,17 +17,17 @@ const config = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers a tool on the given server to handle addition operations.
|
||||
*
|
||||
* @param {McpServer} server - The server instance where the addition tool will be registered.
|
||||
*
|
||||
* Registers the 'add' tool with the provided McpServer instance.
|
||||
**
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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) => {
|
||||
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
|
||||
* a response that echoes the message provided in the arguments.
|
||||
* The registered tool validates input arguments using the EchoSchema and
|
||||
* returns a response that echoes the message provided in the arguments.
|
||||
*
|
||||
* @param {McpServer} server - The server instance where the Echo Tool will be registered.
|
||||
* @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 { registerAddTool } from "./add.js";
|
||||
import { registerEchoTool } from "./echo.js";
|
||||
import { registerGetTinyImageTool } from "./get-tiny-image.js";
|
||||
import { registerLongRunningOperationTool } from "./long-running-operation.js";
|
||||
import { registerPrintEnvTool } from "./print-env.js";
|
||||
import { registerSamplingRequestTool } from "./sampling-request.js";
|
||||
@@ -14,6 +15,7 @@ import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates
|
||||
export const registerTools = (server: McpServer) => {
|
||||
registerAddTool(server);
|
||||
registerEchoTool(server);
|
||||
registerGetTinyImageTool(server);
|
||||
registerLongRunningOperationTool(server);
|
||||
registerPrintEnvTool(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
|
||||
* 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.
|
||||
*
|
||||
* 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`
|
||||
* 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.
|
||||
|
||||
@@ -11,9 +11,10 @@ const config = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers the Echo Tool with the given MCP server. This tool, when invoked,
|
||||
* retrieves and returns the environment variables of the current process
|
||||
* as a JSON-formatted string encapsulated in a text response.
|
||||
* Registers the 'print-env' tool with the given MCP server.
|
||||
*
|
||||
* 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.
|
||||
* @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
|
||||
* arguments, generating a sampling request for an LLM, and returning the
|
||||
* result to the client.
|
||||
* 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.
|
||||
*
|
||||
* The registered tool performs the following operations:
|
||||
* - 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.
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* 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 disabled, updates are stopped for the session.
|
||||
* 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 disabled, updates are stopped for the session.
|
||||
*
|
||||
* The response provides feedback indicating whether simulated updates were started or stopped,
|
||||
* including the session ID.
|
||||
|
||||
Reference in New Issue
Block a user