formatting, more version rollbacks

This commit is contained in:
Basil Hosmer 2025-05-10 00:14:45 -04:00
commit 9686fc2ead
No known key found for this signature in database
3 changed files with 51 additions and 52 deletions

View file

@ -12,7 +12,7 @@ describe('McpServer outputSchema support', () => {
beforeEach(async () => {
server = new McpServer({ name: 'test', version: '1.0' });
client = new Client({ name: 'test-client', version: '1.0' });
[clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
});
@ -85,7 +85,7 @@ describe('McpServer outputSchema support', () => {
'structured-tool',
{ input: z.string() },
outputSchema,
() => ({
() => ({
structuredContent: { result: 'test', count: 42 }
})
);
@ -118,7 +118,7 @@ describe('McpServer outputSchema support', () => {
'structured-tool',
{ input: z.string() },
outputSchema,
() => ({
() => ({
structuredContent: { result: 'test' },
content: [{ type: 'text', text: 'Custom text' }]
})
@ -149,7 +149,7 @@ describe('McpServer outputSchema support', () => {
'broken-tool',
{ input: z.string() },
outputSchema,
() => ({
() => ({
content: [{ type: 'text', text: 'No structured content' }]
})
);
@ -169,7 +169,7 @@ describe('McpServer outputSchema support', () => {
server.tool(
'broken-tool',
{ input: z.string() },
() => ({
() => ({
structuredContent: { result: 'test' }
})
);

View file

@ -860,8 +860,8 @@ describe("tool()", () => {
expect(result.structuredContent).toBeDefined();
// For backward compatibility, content is auto-generated from structuredContent
expect(result.content).toBeDefined();
const structuredContent = result.structuredContent as {
const structuredContent = result.structuredContent as {
processedInput: string;
resultType: string;
timestamp: string;

View file

@ -121,12 +121,12 @@ export class McpServer {
: EMPTY_OBJECT_JSON_SCHEMA,
annotations: tool.annotations,
};
// Only include outputSchema if it's defined
if (tool.outputSchema) {
toolDefinition.outputSchema = tool.outputSchema;
}
return toolDefinition;
},
),
@ -205,7 +205,7 @@ export class McpServer {
`Tool ${request.params.name} has outputSchema but returned no structuredContent`,
);
}
// For backward compatibility, if structuredContent is provided but no content,
// automatically serialize the structured content to text
if (result.structuredContent && !result.content) {
@ -224,7 +224,7 @@ export class McpServer {
`Tool ${request.params.name} has no outputSchema but returned structuredContent`,
);
}
// Tool must have content if no outputSchema
if (!result.content && !result.isError) {
throw new McpError(
@ -774,11 +774,11 @@ export class McpServer {
// Check if the next arg is potentially annotations or outputSchema
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null) {
const nextArg = rest[0];
// Check if it's a JSON Schema (outputSchema)
if (typeof nextArg === "object" && "type" in nextArg) {
outputSchema = rest.shift() as Tool["outputSchema"];
// Check if there's still an annotations object
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !(isZodRawShape(rest[0]))) {
annotations = rest.shift() as ToolAnnotations;
@ -1011,7 +1011,7 @@ export class ResourceTemplate {
* Callback for a tool handler registered with Server.tool().
*
* Parameters will include tool arguments, if applicable, as well as other request handler context.
*
*
* The callback should return:
* - `structuredContent` if the tool has an outputSchema defined
* - `content` if the tool does not have an outputSchema