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.
Adding get-structured-content tool
* Updated architecture.md
* added get-structured-content.ts
- Registers the 'get-structured-content' tool with the provided McpServer instance.
- The registered tool processes incoming arguments using a predefined input schema,
generates structured content with weather information including temperature,
conditions, and humidity, and returns both backward-compatible content blocks
and structured content in the response.
This commit is contained in:
@@ -19,25 +19,9 @@ This document summarizes the current layout and runtime architecture of the `src
|
||||
```
|
||||
src/everything
|
||||
├── index.ts
|
||||
├── server
|
||||
│ ├── index.ts
|
||||
│ ├── logging.ts
|
||||
│ └── everything.ts
|
||||
├── transports
|
||||
│ ├── sse.ts
|
||||
│ ├── stdio.ts
|
||||
│ └── streamableHttp.ts
|
||||
├── tools
|
||||
│ ├── index.ts
|
||||
│ ├── annotated-message.ts
|
||||
│ ├── add.ts
|
||||
│ ├── echo.ts
|
||||
│ ├── get-tiny-image.ts
|
||||
│ ├── long-running-operation.ts
|
||||
│ ├── get-env.ts
|
||||
│ ├── sampling-request.ts
|
||||
│ ├── toggle-logging.ts
|
||||
│ └── toggle-subscriber-updates.ts
|
||||
├── docs
|
||||
│ ├── architecture.md
|
||||
│ └── server-instructions.md
|
||||
├── prompts
|
||||
│ ├── index.ts
|
||||
│ ├── args.ts
|
||||
@@ -49,9 +33,28 @@ src/everything
|
||||
│ ├── files.ts
|
||||
│ ├── subscriptions.ts
|
||||
│ └── templates.ts
|
||||
├── docs
|
||||
│ ├── architecture.md
|
||||
│ └── server-instructions.md
|
||||
├── server
|
||||
│ ├── index.ts
|
||||
│ ├── logging.ts
|
||||
│ └── everything.ts
|
||||
├── transports
|
||||
│ ├── sse.ts
|
||||
│ ├── stdio.ts
|
||||
│ └── streamableHttp.ts
|
||||
├── tools
|
||||
│ ├── index.ts
|
||||
│ ├── add.ts
|
||||
│ ├── annotated-message.ts
|
||||
│ ├── echo.ts
|
||||
│ ├── get-env.ts
|
||||
│ ├── get-tiny-image.ts
|
||||
│ ├── get-resource-links.ts
|
||||
│ ├── get-resource-reference.ts
|
||||
│ ├── get-structured-content.ts
|
||||
│ ├── long-running-operation.ts
|
||||
│ ├── sampling-request.ts
|
||||
│ ├── toggle-logging.ts
|
||||
│ └── toggle-subscriber-updates.ts
|
||||
└── package.json
|
||||
```
|
||||
|
||||
@@ -99,9 +102,7 @@ At `src/everything`:
|
||||
- echo.ts
|
||||
- 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
|
||||
- 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
|
||||
@@ -190,9 +191,12 @@ At `src/everything`:
|
||||
- `add` (tools/add.ts): Adds two numbers `a` and `b` and returns their sum. Uses Zod to validate inputs.
|
||||
- `annotated-message` (tools/annotated-message.ts): Returns a `text` message annotated with `priority` and `audience` based on `messageType` (`error`, `success`, or `debug`); can optionally include an annotated `image`.
|
||||
- `echo` (tools/echo.ts): Echoes the provided `message: string`. Uses Zod to validate inputs.
|
||||
- `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-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-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.
|
||||
- `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.
|
||||
- `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.
|
||||
|
||||
87
src/everything/tools/get-structured-content.ts
Normal file
87
src/everything/tools/get-structured-content.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { z } from "zod";
|
||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import {
|
||||
CallToolResult,
|
||||
ContentBlock,
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
// Tool input schema
|
||||
const GetStructuredContentInputSchema = {
|
||||
location: z
|
||||
.enum(["New York", "Chicago", "Los Angeles"])
|
||||
.describe("Choose city"),
|
||||
};
|
||||
|
||||
// Tool output schema
|
||||
const GetStructuredContentOutputSchema = z.object({
|
||||
temperature: z.number().describe("Temperature in celsius"),
|
||||
conditions: z.string().describe("Weather conditions description"),
|
||||
humidity: z.number().describe("Humidity percentage"),
|
||||
});
|
||||
|
||||
// Tool configuration
|
||||
const name = "get-structured-content";
|
||||
const config = {
|
||||
title: "Get Structured Content Tool",
|
||||
description:
|
||||
"Returns structured content along with an output schema for client data validation",
|
||||
inputSchema: GetStructuredContentInputSchema,
|
||||
outputSchema: GetStructuredContentOutputSchema,
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers the 'get-structured-content' tool with the provided McpServer instance.
|
||||
*
|
||||
* The registered tool processes incoming arguments using a predefined input schema,
|
||||
* generates structured content with weather information including temperature,
|
||||
* conditions, and humidity, and returns both backward-compatible content blocks
|
||||
* and structured content in the response.
|
||||
*
|
||||
* The response contains:
|
||||
* - `content`: An array of content blocks, presented as JSON stringified objects.
|
||||
* - `structuredContent`: A JSON structured representation of the weather data.
|
||||
*
|
||||
* @param {McpServer} server - The server instance to which the tool will be registered.
|
||||
*/
|
||||
export const registerGetStructuredContentTool = (server: McpServer) => {
|
||||
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
|
||||
// Get simulated weather for the chosen city
|
||||
let weather;
|
||||
console.log();
|
||||
switch (args.location) {
|
||||
case "New York":
|
||||
weather = {
|
||||
temperature: 33,
|
||||
conditions: "Cloudy",
|
||||
humidity: 82,
|
||||
};
|
||||
break;
|
||||
|
||||
case "Chicago":
|
||||
weather = {
|
||||
temperature: 36,
|
||||
conditions: "Light rain / drizzle",
|
||||
humidity: 82,
|
||||
};
|
||||
break;
|
||||
|
||||
case "Los Angeles":
|
||||
weather = {
|
||||
temperature: 73,
|
||||
conditions: "Sunny / Clear",
|
||||
humidity: 48,
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
const backwardCompatibleContentBlock: ContentBlock = {
|
||||
type: "text",
|
||||
text: JSON.stringify(weather),
|
||||
};
|
||||
|
||||
return {
|
||||
content: [backwardCompatibleContentBlock],
|
||||
structuredContent: weather,
|
||||
};
|
||||
});
|
||||
};
|
||||
@@ -10,6 +10,7 @@ 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";
|
||||
import { registerGetStructuredContentTool } from "./get-structured-content.js";
|
||||
|
||||
/**
|
||||
* Register the tools with the MCP server.
|
||||
@@ -22,6 +23,7 @@ export const registerTools = (server: McpServer) => {
|
||||
registerGetEnvTool(server);
|
||||
registerGetResourceLinksTool(server);
|
||||
registerGetResourceReferenceTool(server);
|
||||
registerGetStructuredContentTool(server);
|
||||
registerGetTinyImageTool(server);
|
||||
registerLongRunningOperationTool(server);
|
||||
registerSamplingRequestTool(server);
|
||||
|
||||
Reference in New Issue
Block a user