Skip to content

add support for upload #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2025
Merged
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
32 changes: 28 additions & 4 deletions packages/openapi-mcp-server/src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export type Configuration = {
authorization?: Authorization;
};

const arrayRepeatUrls = ['serverless.twilio.com'];

/**
* Get the authorization header
* @param authorization
Expand Down Expand Up @@ -145,7 +147,14 @@ export default class Http {
// eslint-disable-next-line no-underscore-dangle
options.body = request.body.__formData;
} else if (['POST', 'PUT'].includes(request.method) && request.body) {
options.body = Http.getBody(request.body, request.headers);
const arrayRepeated = arrayRepeatUrls.some((x) =>
request.url.includes(x),
);
options.body = Http.getBody(
request.body,
request.headers,
arrayRepeated,
);
}

logger.debug(
Expand Down Expand Up @@ -293,13 +302,28 @@ export default class Http {
private static getBody(
body: Record<string, unknown>,
headers?: Record<string, string>,
arrayRepeat?: boolean,
): string {
const contentType = headers?.['Content-Type'] as string;
if (contentType === 'application/x-www-form-urlencoded') {
return qs.stringify(body, {
arrayFormat: 'repeat',
indices: false,
if (arrayRepeat) {
return qs.stringify(body, {
arrayFormat: 'repeat',
indices: false,
});
}

const processedBody: Record<string, unknown> = {};
Object.keys(body).forEach((key) => {
const value = body[key];
if (value !== null && typeof value === 'object') {
processedBody[key] = JSON.stringify(value);
} else {
processedBody[key] = value;
}
});

return qs.stringify(processedBody);
}

return JSON.stringify(body);
Expand Down