Skip to content

Commit 7e18a7c

Browse files
committed
formatting, more version rollbacks
1 parent 8530e94 commit 7e18a7c

File tree

8 files changed

+51
-52
lines changed

8 files changed

+51
-52
lines changed

src/client/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ export class Client<
442442
try {
443443
// Validate the structured content (which is already an object) against the schema
444444
const validationResult = outputSchema.safeParse(result.structuredContent);
445-
445+
446446
if (!validationResult.success) {
447447
throw new McpError(
448448
ErrorCode.InvalidParams,
@@ -485,10 +485,10 @@ export class Client<
485485
// Cache the tools and their output schemas for future validation
486486
this._cachedTools.clear();
487487
this._cachedToolOutputSchemas.clear();
488-
488+
489489
for (const tool of result.tools) {
490490
this._cachedTools.set(tool.name, tool);
491-
491+
492492
// If the tool has an outputSchema, create and cache the Zod schema
493493
if (tool.outputSchema) {
494494
try {

src/examples/server/mcpServerOutputSchema.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ server.tool(
3434
},
3535
required: ["celsius", "fahrenheit"]
3636
},
37-
conditions: {
37+
conditions: {
3838
type: "string",
3939
enum: ["sunny", "cloudy", "rainy", "stormy", "snowy"]
4040
},
@@ -57,7 +57,7 @@ server.tool(
5757
// Simulate weather API call
5858
const temp_c = Math.round((Math.random() * 35 - 5) * 10) / 10;
5959
const conditions = ["sunny", "cloudy", "rainy", "stormy", "snowy"][Math.floor(Math.random() * 5)];
60-
60+
6161
return {
6262
structuredContent: {
6363
temperature: {
@@ -118,15 +118,15 @@ server.tool(
118118
const lines = csv_data.trim().split('\n');
119119
const headers = lines[0].split(delimiter).map(h => h.trim());
120120
const data = lines.slice(1).map(line => line.split(delimiter).map(cell => cell.trim()));
121-
121+
122122
// Infer data types
123123
const dataTypes: { [key: string]: string } = {};
124124
const summary: { [key: string]: unknown } = {};
125-
125+
126126
headers.forEach((header, idx) => {
127127
const values = data.map(row => row[idx]);
128128
const numericValues = values.filter(v => !isNaN(Number(v)) && v !== '');
129-
129+
130130
if (numericValues.length === values.length) {
131131
dataTypes[header] = "number";
132132
const numbers = numericValues.map(Number);
@@ -140,7 +140,7 @@ server.tool(
140140
dataTypes[header] = "string";
141141
}
142142
});
143-
143+
144144
return {
145145
structuredContent: {
146146
row_count: data.length,
@@ -174,7 +174,7 @@ server.tool(
174174

175175
// Tool that can return both structured and unstructured content
176176
server.tool(
177-
"hybrid_tool",
177+
"hybrid_tool",
178178
"Tool that returns both structured and readable content",
179179
{
180180
data: z.array(z.number()).describe("Array of numbers to analyze")
@@ -196,12 +196,12 @@ server.tool(
196196
async ({ data }) => {
197197
const mean = data.reduce((a, b) => a + b, 0) / data.length;
198198
const sorted = [...data].sort((a, b) => a - b);
199-
const median = sorted.length % 2 === 0
199+
const median = sorted.length % 2 === 0
200200
? (sorted[sorted.length / 2 - 1] + sorted[sorted.length / 2]) / 2
201201
: sorted[Math.floor(sorted.length / 2)];
202202
const variance = data.reduce((acc, val) => acc + Math.pow(val - mean, 2), 0) / data.length;
203203
const std_dev = Math.sqrt(variance);
204-
204+
205205
return {
206206
structuredContent: {
207207
stats: {

src/examples/server/outputSchema.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
3838
type: "object",
3939
properties: {
4040
bmi: { type: "number", description: "Body Mass Index" },
41-
category: {
42-
type: "string",
41+
category: {
42+
type: "string",
4343
enum: ["underweight", "normal", "overweight", "obese"],
4444
description: "BMI category"
4545
},
@@ -102,22 +102,22 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
102102
switch (request.params.name) {
103103
case "calculate_bmi": {
104104
const { height_cm, weight_kg } = request.params.arguments as { height_cm: number; weight_kg: number };
105-
105+
106106
const height_m = height_cm / 100;
107107
const bmi = weight_kg / (height_m * height_m);
108-
108+
109109
let category: string;
110110
if (bmi < 18.5) category = "underweight";
111111
else if (bmi < 25) category = "normal";
112112
else if (bmi < 30) category = "overweight";
113113
else category = "obese";
114-
114+
115115
// Calculate healthy weight range for normal BMI (18.5-24.9)
116116
const min_healthy_bmi = 18.5;
117117
const max_healthy_bmi = 24.9;
118118
const min_healthy_weight = min_healthy_bmi * height_m * height_m;
119119
const max_healthy_weight = max_healthy_bmi * height_m * height_m;
120-
120+
121121
// Return structured content matching the outputSchema
122122
return {
123123
structuredContent: {
@@ -130,39 +130,39 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
130130
}
131131
};
132132
}
133-
133+
134134
case "analyze_text": {
135135
const { text } = request.params.arguments as { text: string };
136-
136+
137137
// Simple text analysis
138138
const words = text.trim().split(/\s+/);
139139
const sentences = text.split(/[.!?]+/).filter(s => s.trim().length > 0);
140140
const wordsPerMinute = 200; // Average reading speed
141-
141+
142142
// Very simple sentiment analysis (for demo purposes)
143143
const positiveWords = ["good", "great", "excellent", "happy", "positive", "amazing"];
144144
const negativeWords = ["bad", "poor", "terrible", "sad", "negative", "awful"];
145-
145+
146146
let positiveCount = 0;
147147
let negativeCount = 0;
148148
words.forEach(word => {
149149
if (positiveWords.includes(word.toLowerCase())) positiveCount++;
150150
if (negativeWords.includes(word.toLowerCase())) negativeCount++;
151151
});
152-
152+
153153
let sentiment: string;
154154
if (positiveCount > negativeCount) sentiment = "positive";
155155
else if (negativeCount > positiveCount) sentiment = "negative";
156156
else sentiment = "neutral";
157-
157+
158158
// Extract key phrases (simple approach - just common bigrams)
159159
const keyPhrases: string[] = [];
160160
for (let i = 0; i < words.length - 1; i++) {
161161
if (words[i].length > 3 && words[i + 1].length > 3) {
162162
keyPhrases.push(`${words[i]} ${words[i + 1]}`);
163163
}
164164
}
165-
165+
166166
return {
167167
structuredContent: {
168168
word_count: words.length,
@@ -174,21 +174,21 @@ server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest)
174174
}
175175
};
176176
}
177-
177+
178178
case "traditional_tool": {
179179
const { message } = request.params.arguments as { message: string };
180-
180+
181181
// Traditional tool returns content array
182182
return {
183183
content: [
184-
{
185-
type: "text",
186-
text: `Processed message: ${message.toUpperCase()}`
184+
{
185+
type: "text",
186+
text: `Processed message: ${message.toUpperCase()}`
187187
}
188188
]
189189
};
190190
}
191-
191+
192192
default:
193193
throw new McpError(
194194
ErrorCode.MethodNotFound,

src/server/mcp-outputschema.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('McpServer outputSchema support', () => {
1212
beforeEach(async () => {
1313
server = new McpServer({ name: 'test', version: '1.0' });
1414
client = new Client({ name: 'test-client', version: '1.0' });
15-
15+
1616
[clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
1717
});
1818

@@ -85,7 +85,7 @@ describe('McpServer outputSchema support', () => {
8585
'structured-tool',
8686
{ input: z.string() },
8787
outputSchema,
88-
() => ({
88+
() => ({
8989
structuredContent: { result: 'test', count: 42 }
9090
})
9191
);
@@ -118,7 +118,7 @@ describe('McpServer outputSchema support', () => {
118118
'structured-tool',
119119
{ input: z.string() },
120120
outputSchema,
121-
() => ({
121+
() => ({
122122
structuredContent: { result: 'test' },
123123
content: [{ type: 'text', text: 'Custom text' }]
124124
})
@@ -149,7 +149,7 @@ describe('McpServer outputSchema support', () => {
149149
'broken-tool',
150150
{ input: z.string() },
151151
outputSchema,
152-
() => ({
152+
() => ({
153153
content: [{ type: 'text', text: 'No structured content' }]
154154
})
155155
);
@@ -169,7 +169,7 @@ describe('McpServer outputSchema support', () => {
169169
server.tool(
170170
'broken-tool',
171171
{ input: z.string() },
172-
() => ({
172+
() => ({
173173
structuredContent: { result: 'test' }
174174
})
175175
);

src/server/mcp.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@ describe("tool()", () => {
860860
expect(result.structuredContent).toBeDefined();
861861
// For backward compatibility, content is auto-generated from structuredContent
862862
expect(result.content).toBeDefined();
863-
864-
const structuredContent = result.structuredContent as {
863+
864+
const structuredContent = result.structuredContent as {
865865
processedInput: string;
866866
resultType: string;
867867
timestamp: string;

src/server/mcp.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ export class McpServer {
121121
: EMPTY_OBJECT_JSON_SCHEMA,
122122
annotations: tool.annotations,
123123
};
124-
124+
125125
// Only include outputSchema if it's defined
126126
if (tool.outputSchema) {
127127
toolDefinition.outputSchema = tool.outputSchema;
128128
}
129-
129+
130130
return toolDefinition;
131131
},
132132
),
@@ -205,7 +205,7 @@ export class McpServer {
205205
`Tool ${request.params.name} has outputSchema but returned no structuredContent`,
206206
);
207207
}
208-
208+
209209
// For backward compatibility, if structuredContent is provided but no content,
210210
// automatically serialize the structured content to text
211211
if (result.structuredContent && !result.content) {
@@ -224,7 +224,7 @@ export class McpServer {
224224
`Tool ${request.params.name} has no outputSchema but returned structuredContent`,
225225
);
226226
}
227-
227+
228228
// Tool must have content if no outputSchema
229229
if (!result.content && !result.isError) {
230230
throw new McpError(
@@ -774,11 +774,11 @@ export class McpServer {
774774
// Check if the next arg is potentially annotations or outputSchema
775775
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null) {
776776
const nextArg = rest[0];
777-
777+
778778
// Check if it's a JSON Schema (outputSchema)
779779
if (typeof nextArg === "object" && "type" in nextArg) {
780780
outputSchema = rest.shift() as Tool["outputSchema"];
781-
781+
782782
// Check if there's still an annotations object
783783
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !(isZodRawShape(rest[0]))) {
784784
annotations = rest.shift() as ToolAnnotations;
@@ -1011,7 +1011,7 @@ export class ResourceTemplate {
10111011
* Callback for a tool handler registered with Server.tool().
10121012
*
10131013
* Parameters will include tool arguments, if applicable, as well as other request handler context.
1014-
*
1014+
*
10151015
* The callback should return:
10161016
* - `structuredContent` if the tool has an outputSchema defined
10171017
* - `content` if the tool does not have an outputSchema

src/types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ describe("Types", () => {
44

55
test("should have correct latest protocol version", () => {
66
expect(LATEST_PROTOCOL_VERSION).toBeDefined();
7-
expect(LATEST_PROTOCOL_VERSION).toBe("DRAFT-2025-v2");
7+
expect(LATEST_PROTOCOL_VERSION).toBe("2025-03-26");
88
});
99
test("should have correct supported protocol versions", () => {
1010
expect(SUPPORTED_PROTOCOL_VERSIONS).toBeDefined();

src/types.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { z, ZodTypeAny } from "zod";
22

3-
export const LATEST_PROTOCOL_VERSION = "DRAFT-2025-v2";
3+
export const LATEST_PROTOCOL_VERSION = "2025-03-26";
44
export const SUPPORTED_PROTOCOL_VERSIONS = [
55
LATEST_PROTOCOL_VERSION,
6-
"2025-03-26",
76
"2024-11-05",
87
"2024-10-07",
98
];
@@ -889,12 +888,12 @@ export const CallToolUnstructuredResultSchema = ResultSchema.extend({
889888
* If the Tool does not define an outputSchema, this field MUST be present in the result.
890889
*/
891890
content: ContentListSchema,
892-
891+
893892
/**
894893
* Structured output must not be provided in an unstructured tool result.
895894
*/
896895
structuredContent: z.never().optional(),
897-
896+
898897
/**
899898
* Whether the tool call ended in an error.
900899
*
@@ -910,7 +909,7 @@ export const CallToolStructuredResultSchema = ResultSchema.extend({
910909
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
911910
*/
912911
structuredContent: z.object({}).passthrough(),
913-
912+
914913
/**
915914
* A list of content objects that represent the result of the tool call.
916915
*
@@ -919,7 +918,7 @@ export const CallToolStructuredResultSchema = ResultSchema.extend({
919918
* Clients that support structured content should ignore this field.
920919
*/
921920
content: z.optional(ContentListSchema),
922-
921+
923922
/**
924923
* Whether the tool call ended in an error.
925924
*

0 commit comments

Comments
 (0)