Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions src/openapi-mcp-server/mcp/__tests__/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ describe('MCPProxy', () => {
content: [
{
type: 'text',
text: JSON.stringify({ message: 'success' }),
text: JSON.stringify({
status: 'success',
statusCode: 200,
data: { message: 'success' },
}),
},
],
})
Expand Down Expand Up @@ -170,11 +174,61 @@ describe('MCPProxy', () => {
content: [
{
type: 'text',
text: JSON.stringify({ message: 'success' })
text: JSON.stringify({
status: 'success',
statusCode: 200,
data: { message: 'success' },
})
}
]
})
})

it('should include HTTP status information in success responses', async () => {
// Mock HttpClient response with different status code
const mockResponse = {
data: { id: 123, name: 'Test Resource' },
status: 201,
headers: new Headers({
'content-type': 'application/json',
}),
}
;(HttpClient.prototype.executeOperation as ReturnType<typeof vi.fn>).mockResolvedValue(mockResponse)

// Set up the openApiLookup with our test operation
;(proxy as any).openApiLookup = {
'API-createTest': {
operationId: 'createTest',
responses: { '201': { description: 'Created' } },
method: 'post',
path: '/test',
},
}

const server = (proxy as any).server
const handlers = server.setRequestHandler.mock.calls.flatMap((x: unknown[]) => x).filter((x: unknown) => typeof x === 'function')
const callToolHandler = handlers[1]

const result = await callToolHandler({
params: {
name: 'API-createTest',
arguments: { name: 'New Resource' },
},
})

expect(result).toEqual({
content: [
{
type: 'text',
text: JSON.stringify({
status: 'success',
statusCode: 201,
data: { id: 123, name: 'Test Resource' },
}),
},
],
})
})
})

describe('getContentType', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/openapi-mcp-server/mcp/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ export class MCPProxy {
content: [
{
type: 'text', // currently this is the only type that seems to be used by mcp server
text: JSON.stringify(response.data), // TODO: pass through the http status code text?
text: JSON.stringify({
status: 'success',
statusCode: response.status,
data: response.data,
}),
},
],
}
Expand Down