Skip to content
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
50 changes: 29 additions & 21 deletions src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,30 +210,12 @@ Call ${handleDialog.name} to handle it before continuing.`);

response.push('## Network requests');
if (requests.length) {
const paginationResult = paginate(
const data = this.#dataWithPagination(
requests,
this.#networkRequestsOptions.pagination,
);
if (paginationResult.invalidPage) {
response.push('Invalid page number provided. Showing first page.');
}

const {startIndex, endIndex, currentPage, totalPages} =
paginationResult;
response.push(
`Showing ${startIndex + 1}-${endIndex} of ${requests.length} (Page ${currentPage + 1} of ${totalPages}).`,
);

if (this.#networkRequestsOptions.pagination) {
if (paginationResult.hasNextPage) {
response.push(`Next page: ${currentPage + 1}`);
}
if (paginationResult.hasPreviousPage) {
response.push(`Previous page: ${currentPage - 1}`);
}
}

for (const request of paginationResult.items) {
response.push(...data.info);
for (const request of data.items) {
response.push(getShortDescriptionForRequest(request));
}
} else {
Expand Down Expand Up @@ -264,6 +246,32 @@ Call ${handleDialog.name} to handle it before continuing.`);
return [text, ...images];
}

#dataWithPagination<T>(data: T[], pagination?: PaginationOptions) {
const response = [];
const paginationResult = paginate<T>(data, pagination);
if (paginationResult.invalidPage) {
response.push('Invalid page number provided. Showing first page.');
}

const {startIndex, endIndex, currentPage, totalPages} = paginationResult;
response.push(
`Showing ${startIndex + 1}-${endIndex} of ${data.length} (Page ${currentPage + 1} of ${totalPages}).`,
);
if (pagination) {
if (paginationResult.hasNextPage) {
response.push(`Next page: ${currentPage + 1}`);
}
if (paginationResult.hasPreviousPage) {
response.push(`Previous page: ${currentPage - 1}`);
}
}

return {
info: response,
items: paginationResult.items,
};
}

#getIncludeNetworkRequestsData(context: McpContext): string[] {
const response: string[] = [];
const url = this.#attachedNetworkRequestUrl;
Expand Down