fix(http): serialize nested objects in form-urlencoded body (#3124)

This commit is contained in:
Waleed
2026-02-03 10:58:01 -08:00
committed by GitHub
parent 710bf75bca
commit 4ca00810b2
2 changed files with 28 additions and 1 deletions

View File

@@ -286,6 +286,30 @@ describe('HTTP Request Tool', () => {
)
})
it('should handle nested objects and arrays in URL-encoded form data', async () => {
tester.setup({ result: 'success' })
const body = {
name: 'test',
data: { nested: 'value' },
items: [1, 2, 3],
}
await tester.execute({
url: 'https://api.example.com/submit',
method: 'POST',
body,
headers: [{ cells: { Key: 'Content-Type', Value: 'application/x-www-form-urlencoded' } }],
})
const fetchCall = (global.fetch as any).mock.calls[0]
const bodyStr = fetchCall[1].body
expect(bodyStr).toContain('name=test')
expect(bodyStr).toContain('data=%7B%22nested%22%3A%22value%22%7D')
expect(bodyStr).toContain('items=%5B1%2C2%2C3%5D')
})
it('should handle OAuth client credentials requests', async () => {
tester.setup({ access_token: 'token123', token_type: 'Bearer' })

View File

@@ -105,7 +105,10 @@ export const requestTool: ToolConfig<RequestParams, RequestResponse> = {
const urlencoded = new URLSearchParams()
Object.entries(params.body as Record<string, unknown>).forEach(([key, value]) => {
if (value !== undefined && value !== null) {
urlencoded.append(key, String(value))
urlencoded.append(
key,
typeof value === 'object' ? JSON.stringify(value) : String(value)
)
}
})
return urlencoded.toString()