@olaservo/mcp-server-everything-sep834 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* SEP-834 Demo Tool: Weather Forecast (Raw Array Output)
|
|
4
|
+
*
|
|
5
|
+
* This tool directly matches the example from SEP-834's Motivation section.
|
|
6
|
+
* It demonstrates returning a RAW ARRAY of hourly forecasts directly in
|
|
7
|
+
* structuredContent - the key capability enabled by SEP-834.
|
|
8
|
+
*
|
|
9
|
+
* Before SEP-834:
|
|
10
|
+
* - outputSchema MUST have type: "object" at root
|
|
11
|
+
* - structuredContent MUST be wrapped: { "forecasts": [...] }
|
|
12
|
+
* - Adds unnecessary nesting, conflicts with common REST API patterns
|
|
13
|
+
*
|
|
14
|
+
* After SEP-834:
|
|
15
|
+
* - outputSchema can be type: "array" at root
|
|
16
|
+
* - structuredContent can be the array directly: [...]
|
|
17
|
+
* - Matches natural API patterns (AccuWeather, OpenWeather, etc.)
|
|
18
|
+
*/
|
|
19
|
+
// Hourly forecast schema - matches SEP-834 example exactly
|
|
20
|
+
const HourlyForecastSchema = z.object({
|
|
21
|
+
hour: z.string().describe("Hour in HH:MM format"),
|
|
22
|
+
temp: z.number().describe("Temperature in Fahrenheit"),
|
|
23
|
+
conditions: z.string().describe("Weather conditions"),
|
|
24
|
+
});
|
|
25
|
+
// Mock forecast data - matches SEP-834 Motivation section example
|
|
26
|
+
const MOCK_FORECASTS = [
|
|
27
|
+
{ hour: "09:00", temp: 68, conditions: "sunny" },
|
|
28
|
+
{ hour: "10:00", temp: 72, conditions: "partly cloudy" },
|
|
29
|
+
{ hour: "11:00", temp: 75, conditions: "cloudy" },
|
|
30
|
+
{ hour: "12:00", temp: 78, conditions: "cloudy" },
|
|
31
|
+
{ hour: "13:00", temp: 80, conditions: "partly cloudy" },
|
|
32
|
+
{ hour: "14:00", temp: 82, conditions: "sunny" },
|
|
33
|
+
{ hour: "15:00", temp: 81, conditions: "sunny" },
|
|
34
|
+
{ hour: "16:00", temp: 79, conditions: "partly cloudy" },
|
|
35
|
+
];
|
|
36
|
+
// Tool input schema
|
|
37
|
+
const GetWeatherForecastInputSchema = {
|
|
38
|
+
hours: z
|
|
39
|
+
.number()
|
|
40
|
+
.min(1)
|
|
41
|
+
.max(24)
|
|
42
|
+
.optional()
|
|
43
|
+
.describe("Number of hourly forecasts to return (default: all available)"),
|
|
44
|
+
};
|
|
45
|
+
// SEP-834: Array schema at root level (not wrapped in object)
|
|
46
|
+
const GetWeatherForecastOutputSchema = z
|
|
47
|
+
.array(HourlyForecastSchema)
|
|
48
|
+
.describe("Array of hourly weather forecasts returned directly");
|
|
49
|
+
// Tool configuration
|
|
50
|
+
const name = "get-weather-forecast";
|
|
51
|
+
const config = {
|
|
52
|
+
title: "Get Weather Forecast (SEP-834)",
|
|
53
|
+
description: "Returns hourly weather forecasts as a RAW ARRAY. This matches the example from SEP-834's Motivation section, demonstrating why array outputs matter for real-world APIs.",
|
|
54
|
+
inputSchema: GetWeatherForecastInputSchema,
|
|
55
|
+
outputSchema: GetWeatherForecastOutputSchema,
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Registers the 'get-weather-forecast' tool.
|
|
59
|
+
*
|
|
60
|
+
* This tool demonstrates the primary use case from SEP-834:
|
|
61
|
+
* returning array data directly without artificial wrapper objects.
|
|
62
|
+
*
|
|
63
|
+
* Compare:
|
|
64
|
+
* Before SEP-834: { "forecasts": [{ "hour": "09:00", ... }] }
|
|
65
|
+
* After SEP-834: [{ "hour": "09:00", ... }]
|
|
66
|
+
*
|
|
67
|
+
* @param {McpServer} server - The McpServer instance where the tool will be registered.
|
|
68
|
+
*/
|
|
69
|
+
export const registerGetWeatherForecastTool = (server) => {
|
|
70
|
+
server.registerTool(name, config, async (args) => {
|
|
71
|
+
const hours = args.hours ?? MOCK_FORECASTS.length;
|
|
72
|
+
const forecasts = MOCK_FORECASTS.slice(0, hours);
|
|
73
|
+
const backwardCompatibleContentBlock = {
|
|
74
|
+
type: "text",
|
|
75
|
+
text: JSON.stringify(forecasts, null, 2),
|
|
76
|
+
};
|
|
77
|
+
// SEP-834: Return the array DIRECTLY, not wrapped in { forecasts: [...] }
|
|
78
|
+
return {
|
|
79
|
+
content: [backwardCompatibleContentBlock],
|
|
80
|
+
structuredContent: forecasts,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
};
|
package/dist/tools/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { registerTriggerElicitationRequestTool } from "./trigger-elicitation-req
|
|
|
14
14
|
import { registerTriggerLongRunningOperationTool } from "./trigger-long-running-operation.js";
|
|
15
15
|
import { registerTriggerSamplingRequestTool } from "./trigger-sampling-request.js";
|
|
16
16
|
// SEP-834: JSON Schema 2020-12 demo tools
|
|
17
|
-
import {
|
|
17
|
+
import { registerGetWeatherForecastTool } from "./get-weather-forecast.js";
|
|
18
18
|
import { registerFindByIdOrNameTool } from "./find-by-id-or-name.js";
|
|
19
19
|
import { registerGetCountTool } from "./get-count.js";
|
|
20
20
|
/**
|
|
@@ -35,7 +35,7 @@ export const registerTools = (server) => {
|
|
|
35
35
|
registerToggleSubscriberUpdatesTool(server);
|
|
36
36
|
registerTriggerLongRunningOperationTool(server);
|
|
37
37
|
// SEP-834: JSON Schema 2020-12 demo tools
|
|
38
|
-
|
|
38
|
+
registerGetWeatherForecastTool(server);
|
|
39
39
|
registerFindByIdOrNameTool(server);
|
|
40
40
|
registerGetCountTool(server);
|
|
41
41
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olaservo/mcp-server-everything-sep834",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "MCP server demonstrating SEP-834 JSON Schema 2020-12 support (arrays, primitives, compositions)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ola Hungerford (@olaservo)",
|