Skip to main content
Glama
ameeralns

DeepResearch MCP

by ameeralns

execute-research-step

Execute targeted research steps on DeepResearch MCP to perform web searches, data analysis, and generate detailed reports on specified topics, supporting iterative and intelligent research workflows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYes

Implementation Reference

  • Core implementation of the executeResearchStep function that performs web search, formats results, analyzes findings with OpenAI, and updates the research state.
    export async function executeResearchStep(sessionId: string): Promise<ResearchState> {
      const researchState = researchSessions.get(sessionId);
      if (!researchState) {
        throw new Error(`No research session found with ID: ${sessionId}`);
      }
    
      if (researchState.currentDepth >= researchState.depth) {
        // Max depth reached - research is complete
        return researchState;
      }
    
      try {
        // Determine search topic for this step
        const currentSearchTopic = researchState.nextSearchTopic || researchState.query;
        
        // Add current topic to the list of searched topics
        researchState.topics.push(currentSearchTopic);
    
        console.error(`[Research] Searching for: "${currentSearchTopic}"`);
    
        // Search for information on the current topic
        let searchResult;
        try {
          searchResult = await searchWeb(currentSearchTopic);
        } catch (searchError) {
          console.error(`[Research] Search error: ${searchError instanceof Error ? searchError.message : String(searchError)}`);
          // Create a fallback search result to indicate the error
          searchResult = {
            query: currentSearchTopic,
            results: [{
              title: 'Search Error',
              url: 'https://error.example.com',
              content: `An error occurred while searching: ${searchError instanceof Error ? searchError.message : String(searchError)}. The search will continue with the next topic.`,
              score: 0
            }]
          };
        }
        
        // Format search results into a detailed finding
        const finding = formatSearchResults(searchResult);
        researchState.findings.push(finding);
        
        // Always analyze findings to determine next steps, regardless of current shouldContinue value
        const analysis = await analyzeResearch(
          researchState.query,
          researchState.findings,
          researchState.topics
        );
        
        // Update research state with next topic and continue flag
        researchState.nextSearchTopic = analysis.nextSearchTopic;
        researchState.shouldContinue = analysis.shouldContinue;
        
        // Always increment the depth counter
        researchState.currentDepth++;
        
        // Update the session
        researchSessions.set(sessionId, researchState);
        
        return researchState;
      } catch (error) {
        console.error('Error executing research step:', error);
        
        // Update the research state to continue despite errors
        if (researchState) {
          // Increment depth to make progress even with errors
          researchState.currentDepth++;
          
          // If we don't have a next search topic, set shouldContinue to false to end the process
          if (!researchState.nextSearchTopic) {
            researchState.shouldContinue = false;
          }
          
          // Update the session
          researchSessions.set(sessionId, researchState);
        }
        
        throw new Error(`Failed to execute research step: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • src/index.ts:97-158 (registration)
    MCP server.tool registration for 'execute-research-step', including input schema { sessionId: z.string() } and wrapper handler function that calls the core executeResearchStep and formats the response.
    server.tool(
      'execute-research-step',
      {
        sessionId: z.string(),
      },
      async ({ sessionId }) => {
        try {
          const updatedState = await executeResearchStep(sessionId);
          
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                message: 'Research step executed',
                currentDepth: updatedState.currentDepth,
                maxDepth: updatedState.depth,
                lastTopic: updatedState.topics[updatedState.topics.length - 1],
                nextTopic: updatedState.nextSearchTopic,
                shouldContinue: updatedState.shouldContinue,
                state: updatedState
              }, null, 2)
            }]
          };
        } catch (error) {
          console.error('Error executing research step:', error);
          
          // Get the current state, even if there was an error
          const currentState = getResearchState(sessionId);
          
          // If we have a valid state, return a properly formatted JSON response with the error
          if (currentState) {
            return {
              content: [{
                type: 'text',
                text: JSON.stringify({
                  message: `Error: ${error instanceof Error ? error.message : String(error)}`,
                  currentDepth: currentState.currentDepth,
                  maxDepth: currentState.depth,
                  lastTopic: currentState.topics.length > 0 ? currentState.topics[currentState.topics.length - 1] : currentState.query,
                  nextTopic: currentState.nextSearchTopic,
                  shouldContinue: false, // Stop research on error
                  state: currentState,
                  error: true
                }, null, 2)
              }]
            };
          }
          
          // Fallback if we can't get the current state
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                message: `Error executing research step: ${error instanceof Error ? error.message : String(error)}`,
                error: true
              }, null, 2)
            }],
            isError: true
          };
        }
      }
    );
  • Zod input schema for the execute-research-step tool: requires a sessionId string.
      sessionId: z.string(),
    },
  • Helper function formatSearchResults used within executeResearchStep to format web search results into a markdown finding for analysis.
    function formatSearchResults(searchResult: SearchResult): string {
      let formattedResult = `# Search Results for: ${searchResult.query}\n\n`;
      
      searchResult.results.forEach((result, index) => {
        const resultNumber = index + 1;
        formattedResult += `## Source [${resultNumber}]: ${result.title}\n`;
        formattedResult += `URL: ${result.url}\n`;
        formattedResult += `Citation: [${resultNumber}] ${result.url}\n\n`;
        formattedResult += `### Content from Source [${resultNumber}]:\n${result.content}\n\n`;
      });
      
      // Add a clear and standardized source section for easy citation
      formattedResult += `# Source URLs for Citation\n\n`;
      searchResult.results.forEach((result, index) => {
        formattedResult += `[${index + 1}] ${result.url} - ${result.title}\n`;
      });
      
      return formattedResult;
    } 
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ameeralns/DeepResearchMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server