File tree 1 file changed +15
-3
lines changed
src/fetch/src/mcp_server_fetch
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -233,9 +233,21 @@ async def call_tool(name, arguments: dict) -> list[TextContent]:
233
233
content , prefix = await fetch_url (
234
234
url , user_agent_autonomous , force_raw = args .raw
235
235
)
236
- if len (content ) > args .max_length :
237
- content = content [args .start_index : args .start_index + args .max_length ]
238
- content += f"\n \n <error>Content truncated. Call the fetch tool with a start_index of { args .start_index + args .max_length } to get more content.</error>"
236
+ original_length = len (content )
237
+ if args .start_index >= original_length :
238
+ content = "<error>No more content available.</error>"
239
+ else :
240
+ truncated_content = content [args .start_index : args .start_index + args .max_length ]
241
+ if not truncated_content :
242
+ content = "<error>No more content available.</error>"
243
+ else :
244
+ content = truncated_content
245
+ actual_content_length = len (truncated_content )
246
+ remaining_content = original_length - (args .start_index + actual_content_length )
247
+ # Only add the prompt to continue fetching if there is still remaining content
248
+ if actual_content_length == args .max_length and remaining_content > 0 :
249
+ next_start = args .start_index + actual_content_length
250
+ content += f"\n \n <error>Content truncated. Call the fetch tool with a start_index of { next_start } to get more content.</error>"
239
251
return [TextContent (type = "text" , text = f"{ prefix } Contents of { url } :\n { content } " )]
240
252
241
253
@server .get_prompt ()
You can’t perform that action at this time.
0 commit comments