[WIP] Refactor everything server to be more modular and use recommended APIs.
Refactor/rename `print-env` tool to `get-env` * Updated architecture.md * Refactor rename print-env.ts to get-env.ts * In tools/index.ts - reorder tools alphabetically
This commit is contained in:
parent
8530747606
commit
03d3da0d55
3 changed files with 12 additions and 11 deletions
|
|
@ -34,7 +34,7 @@ src/everything
|
||||||
│ ├── echo.ts
|
│ ├── echo.ts
|
||||||
│ ├── get-tiny-image.ts
|
│ ├── get-tiny-image.ts
|
||||||
│ ├── long-running-operation.ts
|
│ ├── long-running-operation.ts
|
||||||
│ ├── print-env.ts
|
│ ├── get-env.ts
|
||||||
│ ├── sampling-request.ts
|
│ ├── sampling-request.ts
|
||||||
│ ├── toggle-logging.ts
|
│ ├── toggle-logging.ts
|
||||||
│ └── toggle-subscriber-updates.ts
|
│ └── toggle-subscriber-updates.ts
|
||||||
|
|
@ -97,12 +97,13 @@ At `src/everything`:
|
||||||
- Registers an `annotated-message` tool which demonstrates annotated content items by emitting a primary `text` message with `annotations` that vary by `messageType` (`"error" | "success" | "debug"`), and optionally includes an annotated `image` (tiny PNG) when `includeImage` is true.
|
- Registers an `annotated-message` tool which demonstrates annotated content items by emitting a primary `text` message with `annotations` that vary by `messageType` (`"error" | "success" | "debug"`), and optionally includes an annotated `image` (tiny PNG) when `includeImage` is true.
|
||||||
- echo.ts
|
- echo.ts
|
||||||
- Registers an `echo` tool that takes a message and returns `Echo: {message}`.
|
- Registers an `echo` tool that takes a message and returns `Echo: {message}`.
|
||||||
|
- get-env.ts
|
||||||
|
- Registers a `get-env` tool that returns the current process environment variables as formatted JSON text; useful for debugging configuration.
|
||||||
|
|
||||||
- get-tiny-image.ts
|
- get-tiny-image.ts
|
||||||
- Registers a `get-tiny-image` tool, which returns a tiny PNG MCP logo as an `image` content item, along with surrounding descriptive `text` items.
|
- 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
|
- 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`.
|
- 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`.
|
||||||
- print-env.ts
|
|
||||||
- Registers a `print-env` tool that returns the current process environment variables as formatted JSON text; useful for debugging configuration.
|
|
||||||
- sampling-request.ts
|
- sampling-request.ts
|
||||||
- Registers a `sampling-request` tool that sends a `sampling/createMessage` request to the client/LLM and returns the sampling result.
|
- Registers a `sampling-request` tool that sends a `sampling/createMessage` request to the client/LLM and returns the sampling result.
|
||||||
- toggle-logging.ts
|
- toggle-logging.ts
|
||||||
|
|
@ -189,7 +190,7 @@ At `src/everything`:
|
||||||
- `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.
|
- `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.
|
- `get-env` (tools/get-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.
|
||||||
- `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-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.
|
- `toggle-subscriber-updates` (tools/toggle-subscriber-updates.ts): Starts or stops simulated resource update notifications for URIs the invoking session has subscribed to.
|
||||||
|
|
|
||||||
33
src/everything/tools/get-env.ts
Normal file
33
src/everything/tools/get-env.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
|
||||||
|
// Tool configuration
|
||||||
|
const name = "get-env";
|
||||||
|
const config = {
|
||||||
|
title: "Print Environment Tool",
|
||||||
|
description:
|
||||||
|
"Prints all environment variables, helpful for debugging MCP server configuration",
|
||||||
|
inputSchema: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the 'get-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}
|
||||||
|
*/
|
||||||
|
export const registerGetEnvTool = (server: McpServer) => {
|
||||||
|
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
|
||||||
|
return {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: JSON.stringify(process.env, null, 2),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -2,11 +2,11 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
import { registerAddTool } from "./add.js";
|
import { registerAddTool } from "./add.js";
|
||||||
import { registerAnnotatedMessageTool } from "./annotated-message.js";
|
import { registerAnnotatedMessageTool } from "./annotated-message.js";
|
||||||
import { registerEchoTool } from "./echo.js";
|
import { registerEchoTool } from "./echo.js";
|
||||||
import { registerGetTinyImageTool } from "./get-tiny-image.js";
|
import { registerGetEnvTool } from "./get-env.js";
|
||||||
import { registerGetResourceLinksTool } from "./get-resource-links.js";
|
import { registerGetResourceLinksTool } from "./get-resource-links.js";
|
||||||
import { registerGetResourceReferenceTool } from "./get-resource-reference.js";
|
import { registerGetResourceReferenceTool } from "./get-resource-reference.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 { registerSamplingRequestTool } from "./sampling-request.js";
|
import { registerSamplingRequestTool } from "./sampling-request.js";
|
||||||
import { registerToggleLoggingTool } from "./toggle-logging.js";
|
import { registerToggleLoggingTool } from "./toggle-logging.js";
|
||||||
import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates.js";
|
import { registerToggleSubscriberUpdatesTool } from "./toggle-subscriber-updates.js";
|
||||||
|
|
@ -19,11 +19,11 @@ export const registerTools = (server: McpServer) => {
|
||||||
registerAddTool(server);
|
registerAddTool(server);
|
||||||
registerAnnotatedMessageTool(server);
|
registerAnnotatedMessageTool(server);
|
||||||
registerEchoTool(server);
|
registerEchoTool(server);
|
||||||
registerGetTinyImageTool(server);
|
registerGetEnvTool(server);
|
||||||
registerGetResourceLinksTool(server);
|
registerGetResourceLinksTool(server);
|
||||||
registerGetResourceReferenceTool(server);
|
registerGetResourceReferenceTool(server);
|
||||||
|
registerGetTinyImageTool(server);
|
||||||
registerLongRunningOperationTool(server);
|
registerLongRunningOperationTool(server);
|
||||||
registerPrintEnvTool(server);
|
|
||||||
registerSamplingRequestTool(server);
|
registerSamplingRequestTool(server);
|
||||||
registerToggleLoggingTool(server);
|
registerToggleLoggingTool(server);
|
||||||
registerToggleSubscriberUpdatesTool(server);
|
registerToggleSubscriberUpdatesTool(server);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue