Skip to content

Commit 13af156

Browse files
authored
fix: Return structured content for empty search results in search-apify-docs and store_collection (#371)
* fix: return structured content for empty search results in search-apify-docs and store_collection
1 parent 35a103d commit 13af156

3 files changed

Lines changed: 32 additions & 16 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ Once configured, the server exposes tools that become available to the coding ag
9090
2. **Verify connection**: The client should connect and list available tools automatically
9191
3. **Tools are now available**: Once connected, all MCP tools are exposed and ready to use
9292

93-
#### 2. Coding agent testing workflow
93+
#### 2. Coding agent for MCP server testing
9494

95-
**Note**: Only execute this testing workflow when explicitly requested by the user.
95+
**Note**: Only execute the tests when explicitly requested by the user.
9696

97-
Once the server is configured, test the MCP tools by:
97+
Once the MCP server is configured, test the MCP tools by:
9898

9999
1. **Invoke each tool** through the MCP client (e.g., ask the AI agent to "search for actors" or "fetch actor details for apify/rag-web-browser")
100100
2. **Test with valid inputs** (happy path) – verify outputs match expected formats

src/tools/search-apify-docs.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,19 @@ USAGE EXAMPLES:
6767
const results = resultsRaw.slice(parsed.offset, parsed.offset + parsed.limit);
6868

6969
if (results.length === 0) {
70-
return buildMCPResponse({ texts: [`No results found for the query "${query}" with limit ${parsed.limit} and offset ${parsed.offset}.
71-
Please try a different query with different keywords, or adjust the limit and offset parameters.
72-
You can also try using more specific or alternative keywords related to your search topic.`] });
70+
const instructions = `No results found for the query "${query}" with limit ${parsed.limit} and offset ${parsed.offset}.
71+
Try a different query with different keywords, or adjust the limit and offset parameters.
72+
You can also try using more specific or alternative keywords related to your search topic.`;
73+
const structuredContent = {
74+
results: [],
75+
query,
76+
count: 0,
77+
instructions,
78+
};
79+
return buildMCPResponse({ texts: [instructions], structuredContent });
7380
}
7481

75-
const textContent = `You can use the Apify docs fetch tool to retrieve the full content of a document by its URL. The document fragment refers to the section of the content containing the relevant part for the search result item.
82+
const instructions = `You can use the Apify docs fetch tool to retrieve the full content of a document by its URL. The document fragment refers to the section of the content containing the relevant part for the search result item.
7683
Search results for "${query}":
7784
7885
${results.map((result) => `- Document URL: ${result.url}${result.fragment ? `\n Document fragment: ${result.fragment}` : ''}
@@ -84,8 +91,10 @@ ${results.map((result) => `- Document URL: ${result.url}${result.fragment ? `\n
8491
fragment: result.fragment,
8592
content: result.content,
8693
})),
87-
instructions: `You can use the Apify docs fetch tool to retrieve the full content of a document by its URL. The document fragment refers to the section of the content containing the relevant part for the search result item.`,
94+
query,
95+
count: results.length,
96+
instructions,
8897
};
89-
return buildMCPResponse({ texts: [textContent], structuredContent });
98+
return buildMCPResponse({ texts: [instructions], structuredContent });
9099
},
91100
} as const;

src/tools/store_collection.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,24 @@ Returns list of Actor cards with the following info:
145145
const actorCards = actors.length === 0 ? [] : actors.map(formatActorToActorCard);
146146

147147
if (actorCards.length === 0) {
148-
return buildMCPResponse({ texts: [`No Actors were found for the search query "${parsed.keywords}".
149-
Please try different keywords or simplify your query. Consider using more specific platform names (e.g., "Instagram", "Twitter") and data types (e.g., "posts", "products") rather than generic terms like "scraper" or "crawler".`] });
148+
const instructions = `No Actors were found for the search query "${parsed.keywords}".
149+
Try a different query with different keywords, or adjust the limit and offset parameters.
150+
You can also try using more specific or alternative keywords related to your search topic.`;
151+
const structuredContent = {
152+
actors: [],
153+
query: parsed.keywords,
154+
count: 0,
155+
instructions,
156+
};
157+
return buildMCPResponse({ texts: [instructions], structuredContent });
150158
}
151159

152160
const actorsText = actorCards.join('\n\n');
153161

154162
// Generate structured cards for the actors
155163
const structuredActorCards = actors.map(formatActorToStructuredCard);
156164

157-
const texts = [`
165+
const instructions = `
158166
# Search results:
159167
- **Search query:** ${parsed.keywords}
160168
- **Number of Actors found:** ${actorCards.length}
@@ -165,16 +173,15 @@ Returns list of Actor cards with the following info:
165173
166174
If you need more detailed information about any of these Actors, including their input schemas and usage instructions, please use the ${HelperTools.ACTOR_GET_DETAILS} tool with the specific Actor name.
167175
If the search did not return relevant results, consider refining your keywords, use broader terms or removing less important words from the keywords.
168-
`];
176+
`;
169177

170178
const structuredContent = {
171179
actors: structuredActorCards,
172180
query: parsed.keywords,
173181
count: actorCards.length,
174-
instructions: `If you need more detailed information about any of these Actors, including their input schemas and usage instructions, please use the ${HelperTools.ACTOR_GET_DETAILS} tool with the specific Actor name.
175-
If the search did not return relevant results, consider refining your keywords, use broader terms or removing less important words from the keywords.`,
182+
instructions,
176183
};
177184

178-
return buildMCPResponse({ texts, structuredContent });
185+
return buildMCPResponse({ texts: [instructions], structuredContent });
179186
},
180187
} as const;

0 commit comments

Comments
 (0)